Skip to content

Commit

Permalink
Test on Python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwutingfeng committed Dec 21, 2023
1 parent 20cee0a commit b8afc1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions test_train_arrival.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
6 changes: 2 additions & 4 deletions train_arrival.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b8afc1f

Please sign in to comment.