Skip to content

Commit

Permalink
Merge pull request #7 from MIERUNE/pytest
Browse files Browse the repository at this point in the history
python3.9, pytest
  • Loading branch information
Kanahiro authored Apr 30, 2024
2 parents 827af96 + 4f6c890 commit fbe486a
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 110 deletions.
42 changes: 24 additions & 18 deletions .github/workflows/test.yml
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
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.15
3.9.15
232 changes: 193 additions & 39 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ readme = "README.md"
packages = [{include = "gtfs_parser"}]

[tool.poetry.dependencies]
python = ">=3.7.1"
python = ">=3.9"
pandas = ">=1.3.3"


[tool.poetry.group.dev.dependencies]
pytest = "^8.2.0"
pytest-cov = "^5.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
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)
42 changes: 17 additions & 25 deletions tests/test_aggregator.py
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())
17 changes: 7 additions & 10 deletions tests/test_gtfs.py
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())
36 changes: 20 additions & 16 deletions tests/test_parser.py
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)

0 comments on commit fbe486a

Please sign in to comment.