-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test that only tests changes with 'master'
- Loading branch information
Showing
8 changed files
with
137 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: pybikes (changes) | ||
run-name: Check changes between branch and master | ||
|
||
env: | ||
PYBIKES_CYCLOCITY: ${{ secrets.PYBIKES_CYCLOCITY }} | ||
PYBIKES_BYSYKKEL: ${{ secrets.PYBIKES_BYSYKKEL }} | ||
PYBIKES_WEELO_CLIENT_ID: ${{ secrets.PYBIKES_WEELO_CLIENT_ID }} | ||
PYBIKES_WEELO_CLIENT_SECRET: ${{ secrets.PYBIKES_WEELO_CLIENT_SECRET }} | ||
PYBIKES_DEUTSCHEBAHN_CLIENT_ID: ${{ secrets.PYBIKES_DEUTSCHEBAHN_CLIENT_ID }} | ||
PYBIKES_DEUTSCHEBAHN_CLIENT_SECRET: ${{ secrets.PYBIKES_DEUTSCHEBAHN_CLIENT_SECRET }} | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: make install | ||
- name: Test instance changes on this branch | ||
run: make test-changes T_FLAGS+='-n 10 --json-report --json-report-file=report/report.json' | ||
# Only run summary once | ||
- name: summary | ||
if: (success() || failure()) && matrix.python-version == '3.8' | ||
run: | | ||
make github-summary >> $GITHUB_STEP_SUMMARY |
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
pytest | ||
pytest-xdist | ||
mock; python_version < '3.3' | ||
gitpython | ||
|
||
# Lint | ||
flake8 | ||
|
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,78 @@ | ||
""" Very hacky script that runs tests on bike share systems that have | ||
changed on a specific branch. Checks for changes on data files and | ||
classes containing bike share systems. | ||
This is meant for red explicit fails on changes in CI | ||
""" | ||
|
||
import re | ||
import os | ||
import git | ||
import inspect | ||
|
||
from pytest import mark | ||
from warnings import warn | ||
|
||
from pybikes import BikeShareSystem | ||
from pybikes.data import get_instances | ||
from pybikes.compat import resources | ||
|
||
from tests.test_instances import get_test_cls | ||
|
||
|
||
def is_system(obj): | ||
if not inspect.isclass(obj): | ||
return False | ||
|
||
if not issubclass(obj, BikeShareSystem): | ||
return False | ||
|
||
if obj == BikeShareSystem: | ||
return False | ||
|
||
return True | ||
|
||
|
||
def generate_tests_from_changes(): | ||
from importlib.util import spec_from_file_location, module_from_spec | ||
|
||
|
||
g = git.cmd.Git(os.getcwd()) | ||
changed_files = g.diff('--name-only', 'origin/master').splitlines() | ||
clss = set() | ||
|
||
|
||
for file in changed_files: | ||
if re.match(r'pybikes/data/.*\.json', file): | ||
# Extract classes from json file | ||
match = re.search(r'pybikes/data/(.*)\.json', file) | ||
if not match: | ||
continue | ||
schema = match.group(1) | ||
[clss.add(cls) for cls, _ in get_instances(schema)] | ||
elif re.match(r'pybikes/.*\.py', file): | ||
# Extract bike share classes from file | ||
spec = spec_from_file_location('some.mod', file) | ||
mod = module_from_spec(spec) | ||
spec.loader.exec_module(mod) | ||
systems = filter(lambda m: is_system(m[1]), inspect.getmembers(mod)) | ||
[clss.add(cls) for cls, _ in systems] | ||
|
||
|
||
for cls in sorted(clss): | ||
test_cls = get_test_cls(cls) | ||
test_cls = mark.changes(test_cls) | ||
# decorate with pytest mark | ||
globals()[test_cls.__name__] = test_cls | ||
|
||
|
||
# non-optimal not-required | ||
try: | ||
generate_tests_from_changes() | ||
except Exception as e: | ||
warn("Failed generating tests from branch changes: " + str(e)) | ||
|
||
# Force pytest to succeed when no tests are marked with 'changes' | ||
@mark.changes | ||
def test_dummy(): | ||
assert True |
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