|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Testplan for testing the gentri module.""" |
| 2 | +"""Pytest launcher for gentrie tests. |
3 | 3 |
|
4 | | -# pylint: disable=import-error |
5 | | -import sys |
6 | | - |
7 | | -from testplan import test_plan # type: ignore |
8 | | -from testplan.testing import pyunit # type: ignore |
| 4 | +Usage: |
| 5 | + ./test_plan.py # run all tests under tests/gentrie |
| 6 | + ./test_plan.py KeyToken # pattern filter (class or test name substring / -k expression) |
9 | 7 |
|
10 | | -from tests.gentrie import test_gentri |
| 8 | +Environment (optional): |
| 9 | + GENTRIE_FAIL_FAST=1 # enable fail-fast (-x) |
| 10 | +""" |
11 | 11 |
|
12 | | -# pylint: disable=missing-function-docstring |
| 12 | +from __future__ import annotations |
13 | 13 |
|
14 | | - |
15 | | -@test_plan(name='PyUnitGentri', description='PyUnit gentri tests') |
16 | | -def main(plan): # type: ignore |
17 | | - plan.add( # type: ignore |
18 | | - pyunit.PyUnit( |
19 | | - name="gen-trie tests", |
20 | | - description="PyUnit testcases for the gentri module", |
21 | | - testcases=[test_gentri.TestTrieKeyToken, |
22 | | - test_gentri.TestTrieId, |
23 | | - test_gentri.TestGeneralizedKey, |
24 | | - test_gentri.TestGeneralizedTrie], |
25 | | - ) |
26 | | - ) |
| 14 | +import os |
| 15 | +import sys |
| 16 | +import pytest |
| 17 | + |
| 18 | + |
| 19 | +def build_pytest_args(pattern: str | None) -> list[str]: |
| 20 | + args: list[str] = [] |
| 21 | + # Fail fast |
| 22 | + if os.environ.get("GENTRIE_FAIL_FAST") == "1": |
| 23 | + args.append("-x") |
| 24 | + # Quiet by default; adjust as needed |
| 25 | + args.extend(["-q", "--disable-warnings"]) |
| 26 | + # Add test path |
| 27 | + args.append("tests/gentrie") |
| 28 | + # Pattern handling: allow either simple substring or full -k expression |
| 29 | + if pattern: |
| 30 | + # If user already passed pytest expression operators, trust it |
| 31 | + if any(op in pattern for op in (" and ", " or ", " not ", "(", ")")): |
| 32 | + args.extend(["-k", pattern]) |
| 33 | + else: |
| 34 | + # Simple substring: wrap to match anywhere in node id |
| 35 | + expr = pattern |
| 36 | + args.extend(["-k", expr]) |
| 37 | + return args |
| 38 | + |
| 39 | + |
| 40 | +def main() -> int: |
| 41 | + pattern = sys.argv[1] if len(sys.argv) > 1 else None |
| 42 | + args = build_pytest_args(pattern) |
| 43 | + return pytest.main(args) |
27 | 44 |
|
28 | 45 |
|
29 | 46 | if __name__ == "__main__": |
30 | | - # pylint: disable=invalid-name, no-value-for-parameter |
31 | | - res = main() # type: ignore |
32 | | - sys.exit(res.exit_code) # type: ignore |
| 47 | + sys.exit(main()) |
0 commit comments