Skip to content

Commit b975e77

Browse files
committed
Switch to PyTest WIP
1 parent ea98d9f commit b975e77

2 files changed

Lines changed: 62 additions & 44 deletions

File tree

pyproject.toml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,29 @@ classifiers = [
5151
requires-python = ">=3.10"
5252
dependencies = []
5353

54-
optional-dependencies = {
55-
dev = [
56-
"flake8",
57-
"black",
58-
"pylint",
59-
"pytest",
60-
"pytest-cov",
61-
"pytest-mock",
62-
"pytest-xdist",
63-
"testplan",
64-
"coverage",
65-
"mypy",
66-
],
67-
docs = [
68-
"sphinx",
69-
"sphinx-rtd-theme",
70-
"sphinx-autodoc-typehints",
71-
],
72-
}
73-
54+
[project.optional-dependencies]
55+
tests = [
56+
"pytest",
57+
"testplan",
58+
"coverage"
59+
]
60+
dev = [
61+
"flake8",
62+
"black",
63+
"pylint",
64+
"pytest",
65+
"pytest-cov",
66+
"pytest-mock",
67+
"pytest-xdist",
68+
"testplan",
69+
"coverage",
70+
"mypy"
71+
]
72+
docs = [
73+
"sphinx",
74+
"sphinx-rtd-theme",
75+
"sphinx-autodoc-typehints"
76+
]
7477

7578
[project.urls]
7679
Homepage = "https://github.com/JerilynFranz/python-gen-tries"

test_plan.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
#!/usr/bin/env python3
2-
"""Testplan for testing the gentri module."""
2+
"""Pytest launcher for gentrie tests.
33
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)
97
10-
from tests.gentrie import test_gentri
8+
Environment (optional):
9+
GENTRIE_FAIL_FAST=1 # enable fail-fast (-x)
10+
"""
1111

12-
# pylint: disable=missing-function-docstring
12+
from __future__ import annotations
1313

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)
2744

2845

2946
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

Comments
 (0)