From ae1bbfbdbd291c038b8ed9f84accde0d362e1a25 Mon Sep 17 00:00:00 2001 From: Paraita Wohler Date: Tue, 24 Jan 2017 20:48:40 +0100 Subject: [PATCH] Add python 3 support (#1) * Add python 3.4 3.5 and 3.6 support * Ignore my python 3 virtualenv folder * Fix the test for python 3 support while maintaining python 2 support --- .gitignore | 1 + .travis.yml | 3 +++ requirements.txt | 1 - sophiabus230/__init__.py | 5 ++++- sophiabus230/tests/test_get_next_buses.py | 6 +++--- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6fe7387..ceb58ce 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,7 @@ celerybeat-schedule # virtualenv venv/ ENV/ +ENV3/ # Spyder project settings .spyderproject diff --git a/.travis.yml b/.travis.yml index 24c7696..3782890 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: python python: - "2.6" - "2.7" + - "3.4" + - "3.5" + - "3.6" install: - pip install . - pip install coverage diff --git a/requirements.txt b/requirements.txt index 4a7f3ff..13f8775 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,3 @@ pbr==1.10.0 python-dateutil==2.6.0 requests==2.12.4 six==1.10.0 -sophiabus230==0.1 diff --git a/sophiabus230/__init__.py b/sophiabus230/__init__.py index a779f6a..b154d48 100644 --- a/sophiabus230/__init__.py +++ b/sophiabus230/__init__.py @@ -75,7 +75,7 @@ def _parse_entry(entry): bus_time.replace(tzinfo=tz_paris) idx_start_direction = 3 dest = ' '.join(split_entry[idx_start_direction:idx_end_direction]) - dest = dest.encode('utf-8') + dest = dest return {'bus_time': bus_time, 'dest': dest, 'is_real_time': is_real_time} @@ -104,3 +104,6 @@ def get_next_buses(debug=False): logging.info('found {0}'.format(sane_entry.encode('utf-8'))) tt.append(_parse_entry(sane_entry)) return tt + + +get_next_buses() \ No newline at end of file diff --git a/sophiabus230/tests/test_get_next_buses.py b/sophiabus230/tests/test_get_next_buses.py index fbe7216..b3b7d19 100644 --- a/sophiabus230/tests/test_get_next_buses.py +++ b/sophiabus230/tests/test_get_next_buses.py @@ -15,7 +15,7 @@ class TestSophiabus230(TestCase): @patch('sophiabus230._get_html_from_cg06') def test_get_next_buses(self, mock_content): parent_path = os.path.dirname(os.path.abspath(__file__)) - with open(parent_path + os.sep + "example_content.html", 'r') as fd: + with open(parent_path + os.sep + "example_content.html", 'rb') as fd: mock_content.return_value = fd.read() tz_paris = gettz('Europe/Paris') result_list = sophiabus230.get_next_buses(debug=True) @@ -24,9 +24,9 @@ def test_get_next_buses(self, mock_content): actual_dest = result_list[0]['dest'] actual_is_real_time = result_list[0]['is_real_time'] actual_bus_time = result_list[0]['bus_time'] - expected_dest = 'Cathédrale-Vieille Ville' + expected_dest = u'Cathédrale-Vieille Ville' expected_is_real_time = True - assert actual_dest == expected_dest + self.assertEqual(actual_dest, expected_dest) assert actual_is_real_time == expected_is_real_time assert actual_bus_time.year == expected_bus_time.year assert actual_bus_time.month == expected_bus_time.month