-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
establish auto-discovery and auto-testing of match report files in te…
…sts/mocks_data/match_reports
- Loading branch information
Showing
17 changed files
with
411 additions
and
271 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
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,24 @@ | ||
name: Publish to PyPI | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
pypi_release: | ||
name: Poetry Build & Publish (PyPI) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Init python/poetry environment | ||
uses: ./.github/actions/setup-poetry-env | ||
with: | ||
cached-venv: false | ||
|
||
- run: poetry run pytest | ||
|
||
- run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}" | ||
|
||
- name: "TODO: Publish to PyPI" | ||
run: echo TODO && exit 1 | ||
shell: bash |
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
Empty file.
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 @@ | ||
# Mock match reports for tests | ||
|
||
The following pattern(s) *must* be followed for automatic discovery and testing. See `./__init__.py` for details. | ||
|
||
## Add a match report for testing | ||
|
||
1. Add the report text file to `tests/mock_data/match_reports` (ex: `report_foo.txt`) | ||
- The stem of the filename must conform to python source file naming requirements (rule of thumb: `^[a-z][_a-z0-9]*\.txt$`) | ||
- Sanitize competitor names | ||
2. Add a corresponding python source file of the same name (ex: `report_foo.py`) that exports a function named `assert_match_report` | ||
- the exported function just be of type `Callable[[ParsedMatchReport], None]` | ||
- it should assert the expected state of the corresponding match report |
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,16 @@ | ||
import importlib | ||
from pathlib import Path | ||
from typing import Callable, Dict | ||
|
||
from hitfactorpy.parsers.match_report.models import ParsedMatchReport | ||
|
||
AssertMatchReportCallable = Callable[[ParsedMatchReport], None] | ||
|
||
DIRECTORY = Path(__file__).resolve().parent | ||
REPORT_FILES = list(DIRECTORY.glob("*.txt")) | ||
BY_FILENAME = {str(f).split("tests/mock_data/")[-1]: f.read_text() for f in REPORT_FILES} | ||
VALIDATORS: Dict[str, AssertMatchReportCallable] = { | ||
fname: importlib.import_module(f".{Path(fname).stem}", package="tests.mock_data.match_reports").assert_match_report | ||
# fname: __import__(f".{Path(fname).stem}", globals(), locals(), [], 1).assert_match_report | ||
for fname in BY_FILENAME.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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import datetime | ||
|
||
from pytest import approx | ||
|
||
from hitfactorpy.enums import Classification, Division, PowerFactor, Scoring | ||
from hitfactorpy.parsers.match_report.models import ParsedMatchReport | ||
|
||
|
||
def assert_pcsl_match_report_1gun_20231129(report: ParsedMatchReport): | ||
"""Assert the expected state of the 1-gun 20231129 report""" | ||
assert report | ||
assert report.name == "matchName" | ||
assert report.match_level == 1 | ||
assert report.platform == "IOS" | ||
assert report.ps_product == "PractiScore (iOS)" | ||
assert report.ps_version == "1.682" | ||
assert report.club_name == "clubName" | ||
assert report.club_code == "clubCode" | ||
assert report.region == "USPSA" | ||
assert report.raw_date == "11/29/2023" | ||
assert report.date == datetime.datetime(2023, 11, 29, 0, 0) | ||
assert report.stages | ||
assert len(report.stages) == 3 | ||
assert report.competitors | ||
assert len(report.competitors) == 5 | ||
assert report.stage_scores | ||
assert len(report.stage_scores) == 13 | ||
|
||
# Verify a stage | ||
assert report.stages[0].name == "Surefire" | ||
assert report.stages[0].min_rounds == 30 | ||
assert report.stages[0].max_points == 150 | ||
assert report.stages[0].classifier is False | ||
assert report.stages[0].classifier_number in ["nan", "", None] | ||
assert report.stages[0].internal_id == 1 | ||
assert report.stages[0].scoring_type == Scoring.COMSTOCK | ||
assert report.stages[0].number == 1 | ||
assert report.stages[0].gun_type == "Pistol" | ||
|
||
# Verify a competitor | ||
assert report.competitors[0].internal_id == 1 | ||
assert report.competitors[0].first_name == "Person" | ||
assert report.competitors[0].last_name == "A" | ||
assert report.competitors[0].classification == Classification.UNKNOWN | ||
assert report.competitors[0].division == Division.UNKNOWN | ||
assert report.competitors[0].member_number == "NUMBER1" | ||
assert report.competitors[0].power_factor == PowerFactor.MINOR | ||
assert report.competitors[0].dq is False | ||
assert report.competitors[0].reentry is False | ||
|
||
# Verify DQ'ed competitor | ||
assert report.competitors[4].dq is True | ||
|
||
# Verify a stage score with a DQ | ||
assert report.stage_scores[-1].stage_id == 3 | ||
assert report.stage_scores[-1].competitor_id == 4 | ||
assert report.stage_scores[-1].a == 9 | ||
assert report.stage_scores[-1].b == 0 | ||
assert report.stage_scores[-1].c == 5 | ||
assert report.stage_scores[-1].d == 0 | ||
assert report.stage_scores[-1].m == 0 | ||
assert report.stage_scores[-1].ns == 0 | ||
assert report.stage_scores[-1].npm == 0 | ||
assert report.stage_scores[-1].procedural == 0 | ||
assert report.stage_scores[-1].late_shot == 0 | ||
assert report.stage_scores[-1].extra_shot == 0 | ||
assert report.stage_scores[-1].extra_hit == 0 | ||
assert report.stage_scores[-1].other_penalty == 0 | ||
assert report.stage_scores[-1].t1 == approx(9.43) | ||
assert report.stage_scores[-1].t2 == approx(0) | ||
assert report.stage_scores[-1].t3 == approx(0) | ||
assert report.stage_scores[-1].t4 == approx(0) | ||
assert report.stage_scores[-1].t5 == approx(0) | ||
assert report.stage_scores[-1].time == approx(9.43) | ||
assert report.stage_scores[-1].raw_points == approx(60) | ||
assert report.stage_scores[-1].penalty_points == approx(0) | ||
assert report.stage_scores[-1].total_points == approx(60) | ||
assert report.stage_scores[-1].hit_factor == approx(0) | ||
assert report.stage_scores[-1].stage_points == approx(0) | ||
assert report.stage_scores[-1].stage_place == 4 | ||
assert report.stage_scores[-1].dq is True | ||
assert report.stage_scores[-1].dnf is False | ||
assert report.stage_scores[-1].stage_power_factor is None | ||
|
||
# Verify DQ'ed competitor exists in competitors list, and was DQ'ed | ||
dqed_competitor = next((c for c in report.competitors if c.internal_id == 4), None) | ||
assert dqed_competitor | ||
assert dqed_competitor.dq is True | ||
|
||
|
||
assert_match_report = assert_pcsl_match_report_1gun_20231129 |
File renamed without changes.
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,86 @@ | ||
import datetime | ||
|
||
from pytest import approx | ||
|
||
from hitfactorpy.enums import Classification, Division, PowerFactor, Scoring | ||
from hitfactorpy.parsers.match_report.models import ParsedMatchReport | ||
|
||
|
||
def assert_pcsl_match_report_2gun_20231129(report: ParsedMatchReport): | ||
"""Assert the expected state of the 2-gun 20231129 report""" | ||
assert report | ||
assert report.name == "matchName" | ||
assert report.match_level == 1 | ||
assert report.platform == "IOS" | ||
assert report.ps_product == "PractiScore (iOS)" | ||
assert report.ps_version == "1.682" | ||
assert report.club_name == "clubName" | ||
assert report.club_code == "clubCode" | ||
assert report.region == "USPSA" | ||
assert report.raw_date == "11/29/2023" | ||
assert report.date == datetime.datetime(2023, 11, 29, 0, 0) | ||
assert report.stages | ||
assert len(report.stages) == 3 | ||
assert report.competitors | ||
assert len(report.competitors) == 3 | ||
assert report.stage_scores | ||
assert len(report.stage_scores) == 8 | ||
|
||
# Verify a stage | ||
assert report.stages[0].name == "Surefire" | ||
assert report.stages[0].min_rounds == 54 | ||
assert report.stages[0].max_points == 270 | ||
assert report.stages[0].classifier is False | ||
assert report.stages[0].classifier_number in ["nan", "", None] | ||
assert report.stages[0].internal_id == 1 | ||
assert report.stages[0].scoring_type == Scoring.COMSTOCK | ||
assert report.stages[0].number == 1 | ||
assert report.stages[0].gun_type == "Pistol" | ||
|
||
# Verify a competitor | ||
assert report.competitors[1].internal_id == 2 | ||
assert report.competitors[1].first_name == "Person" | ||
assert report.competitors[1].last_name == "B" | ||
assert report.competitors[1].classification == Classification.UNKNOWN | ||
assert report.competitors[1].division == Division.UNKNOWN | ||
assert report.competitors[1].member_number == "NUMBER2" | ||
assert report.competitors[1].power_factor == PowerFactor.MINOR | ||
assert report.competitors[1].dq is False | ||
assert report.competitors[1].reentry is False | ||
|
||
# Verify no DQ'ed competitors exist in this report | ||
assert report.competitors[-1].dq is True | ||
|
||
# Verify a stage score | ||
assert report.stage_scores[1].stage_id == 1 | ||
assert report.stage_scores[1].competitor_id == 2 | ||
assert report.stage_scores[1].a == 45 | ||
assert report.stage_scores[1].b == 0 | ||
assert report.stage_scores[1].c == 9 | ||
assert report.stage_scores[1].d == 0 | ||
assert report.stage_scores[1].m == 0 | ||
assert report.stage_scores[1].ns == 0 | ||
assert report.stage_scores[1].npm == 0 | ||
assert report.stage_scores[1].procedural == 0 | ||
assert report.stage_scores[1].late_shot == 0 | ||
assert report.stage_scores[1].extra_shot == 0 | ||
assert report.stage_scores[1].extra_hit == 0 | ||
assert report.stage_scores[1].other_penalty == 0 | ||
assert report.stage_scores[1].t1 == approx(49.21) | ||
assert report.stage_scores[1].t2 == approx(0) | ||
assert report.stage_scores[1].t3 == approx(0) | ||
assert report.stage_scores[1].t4 == approx(0) | ||
assert report.stage_scores[1].t5 == approx(0) | ||
assert report.stage_scores[1].time == approx(49.21) | ||
assert report.stage_scores[1].raw_points == approx(252) | ||
assert report.stage_scores[1].penalty_points == approx(0) | ||
assert report.stage_scores[1].total_points == approx(252) | ||
assert report.stage_scores[1].hit_factor == approx(5.1209) | ||
assert report.stage_scores[1].stage_points == approx(248.82) | ||
assert report.stage_scores[1].stage_place == 2 | ||
assert report.stage_scores[1].dq is False | ||
assert report.stage_scores[1].dnf is False | ||
assert report.stage_scores[1].stage_power_factor is None | ||
|
||
|
||
assert_match_report = assert_pcsl_match_report_2gun_20231129 |
File renamed without changes.
Oops, something went wrong.