-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MIERUNE/pytest
python3.9, pytest
- Loading branch information
Showing
8 changed files
with
279 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
name: test | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
unittest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
unittest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.7 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry install | ||
- name: unittest | ||
run: poetry run python -m unittest discover . | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry install | ||
- name: Run pytest | ||
run: poetry run pytest -v --cov --cov-report xml --cov-report term | ||
|
||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: MIERUNE/gtfs-parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.7.15 | ||
3.9.15 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from gtfs_parser.gtfs import GTFS | ||
|
||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixture") | ||
|
||
|
||
@pytest.fixture | ||
def gtfs(): | ||
return GTFS(FIXTURE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
import os | ||
import unittest | ||
|
||
from gtfs_parser.gtfs import GTFS | ||
from gtfs_parser.aggregate import Aggregator | ||
|
||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixture") | ||
|
||
|
||
class TestAggregator(unittest.TestCase): | ||
gtfs = GTFS(FIXTURE_DIR) | ||
def test_read_interpolated_stops(gtfs): | ||
aggregator = Aggregator(gtfs) | ||
interpolated_stops_features = aggregator.read_interpolated_stops() | ||
|
||
def test_read_interpolated_stops(self): | ||
aggregator = Aggregator(self.gtfs) | ||
interpolated_stops_features = aggregator.read_interpolated_stops() | ||
# as_unify means near and similar named stops move into same lat-lon(centroid of them) | ||
assert 518 == len(interpolated_stops_features) | ||
|
||
# as_unify means near and similar named stops move into same lat-lon(centroid of them) | ||
self.assertEqual(518, len(interpolated_stops_features)) | ||
# read_interpolated_stops unify stops having same lat-lon into one featrure. | ||
# there are no stops having same lat-lon in fixture | ||
aggregator_nounify = Aggregator(gtfs, no_unify_stops=True) | ||
nounify_features = aggregator_nounify.read_interpolated_stops() | ||
assert 899 == len(nounify_features) | ||
|
||
# read_interpolated_stops unify stops having same lat-lon into one featrure. | ||
# there are no stops having same lat-lon in fixture | ||
aggregator_nounify = Aggregator(self.gtfs, no_unify_stops=True) | ||
nounify_features = aggregator_nounify.read_interpolated_stops() | ||
self.assertEqual(899, len(nounify_features)) | ||
|
||
def test_read_route_frequency(self): | ||
# unify some 'similar' stops into same position, this decrease num of route_frequency features | ||
aggregator = Aggregator(self.gtfs) | ||
self.assertEqual(918, len(aggregator.read_route_frequency())) | ||
def test_read_route_frequency(gtfs): | ||
# unify some 'similar' stops into same position, this decrease num of route_frequency features | ||
aggregator = Aggregator(gtfs) | ||
assert 918 == len(aggregator.read_route_frequency()) | ||
|
||
# each route_frequency feature is drawn between 2 stops | ||
aggregator_nounify = Aggregator(self.gtfs, no_unify_stops=True) | ||
self.assertEqual(956, len(aggregator_nounify.read_route_frequency())) | ||
# each route_frequency feature is drawn between 2 stops | ||
aggregator_nounify = Aggregator(gtfs, no_unify_stops=True) | ||
assert 956 == len(aggregator_nounify.read_route_frequency()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import os | ||
import unittest | ||
import glob | ||
|
||
from gtfs_parser.gtfs import GTFS | ||
|
||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixture") | ||
from gtfs_parser.gtfs import GTFS | ||
|
||
|
||
class TestGtfs(unittest.TestCase): | ||
def test_gtfs(): | ||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixture") | ||
gtfs = GTFS(FIXTURE_DIR) | ||
|
||
def test_gtfs(self): | ||
# 13 txt files are in ./fixture | ||
self.assertEqual(13, len(glob.glob(os.path.join(FIXTURE_DIR, "*.txt")))) | ||
# read tables in constants.py | ||
self.assertEqual(13, len(self.gtfs.keys())) | ||
# 13 txt files are in ./fixture | ||
assert 13 == len(glob.glob(os.path.join(FIXTURE_DIR, "*.txt"))) | ||
# read tables in constants.py | ||
assert 13 == len(gtfs.keys()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import os | ||
import unittest | ||
|
||
import pytest | ||
|
||
from gtfs_parser.gtfs import GTFS | ||
from gtfs_parser.parse import read_routes, read_stops | ||
|
||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), "fixture") | ||
|
||
|
||
class TestParser(unittest.TestCase): | ||
gtfs = GTFS(FIXTURE_DIR) | ||
@pytest.fixture | ||
def gtfs(): | ||
return GTFS(FIXTURE_DIR) | ||
|
||
|
||
def test_read_stops(gtfs): | ||
stops_features = read_stops(gtfs) | ||
# list of geojson-feature | ||
assert 899 == len(stops_features) | ||
|
||
def test_read_stops(self): | ||
stops_features = read_stops(self.gtfs) | ||
# list of geojson-feature | ||
self.assertEqual(899, len(stops_features)) | ||
# remove no-route stops | ||
stops_features_no_noroute = read_stops(gtfs, ignore_no_route=True) | ||
assert 896 == len(stops_features_no_noroute) | ||
|
||
# remove no-route stops | ||
stops_features_no_noroute = read_stops(self.gtfs, ignore_no_route=True) | ||
self.assertEqual(896, len(stops_features_no_noroute)) | ||
|
||
def test_read_routes(self): | ||
routes_features = read_routes(self.gtfs) | ||
self.assertEqual(32, len(routes_features)) | ||
def test_read_routes(gtfs): | ||
routes_features = read_routes(gtfs) | ||
assert 32 == len(routes_features) | ||
|
||
# num of features in routes.geojson depends on not shapes.txt but routes.txt | ||
routes_features_noshapes = read_routes(self.gtfs, ignore_shapes=True) | ||
self.assertEqual(32, len(routes_features_noshapes)) | ||
# num of features in routes.geojson depends on not shapes.txt but routes.txt | ||
routes_features_noshapes = read_routes(gtfs, ignore_shapes=True) | ||
assert 32 == len(routes_features_noshapes) |