From b8afc1fb10ee20bbadd0188e8de8f89cf97c7d23 Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Thu, 21 Dec 2023 19:11:46 +0800 Subject: [PATCH] Test on Python 2.7 --- .github/workflows/ci.yml | 8 ++++++++ test_train_arrival.py | 11 +++++++++-- train_arrival.py | 6 ++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1fa719..de875ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,19 @@ name: ci on: [push, pull_request, workflow_dispatch] jobs: test-and-coverage: + strategy: + matrix: + python-version: ['2.7', '3.12'] runs-on: ubuntu-latest steps: - name: checkout repo content uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install Python requirements run: | pip install --upgrade pip diff --git a/test_train_arrival.py b/test_train_arrival.py index 56e799b..23d8a57 100644 --- a/test_train_arrival.py +++ b/test_train_arrival.py @@ -30,11 +30,18 @@ def test_get_all_station_names(): def test_get_train_arrival_time_by_id(): - test_cases = (("Raffles Place", "EW14,NS26"), ("Farrer Road", "CC20")) + test_cases = ( + ("Raffles Place", "EW14,NS26"), + ("Farrer Road", "CC20"), + ("Not A Real Station", ""), + ) for test_case in test_cases: expected_station_name, expected_station_code = test_case[0], test_case[1] res = get_train_arrival_time_by_id(expected_station_name) - arrival_time_response = json.loads(res) + arrival_time_response = json.loads(res) # type: dict + if expected_station_name == "Not A Real Station": + assert arrival_time_response.get("results", None) == [] + continue _verify_arrival_time_response( arrival_time_response, expected_station_name, expected_station_code ) diff --git a/train_arrival.py b/train_arrival.py index 53b2e87..98b448a 100644 --- a/train_arrival.py +++ b/train_arrival.py @@ -34,10 +34,8 @@ def _is_str_or_unicode(s): """ if isinstance(s, str): return True - is_python3 = sys.version_info[0] == 3 - if is_python3: - return False - return type(s).__name__ == "unicode" + is_python2 = sys.version_info[0] == 2 + return is_python2 and type(s).__name__ == "unicode" def _get(url, params=None):