Skip to content

Commit

Permalink
Added coverage checks (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
trag1c authored May 18, 2024
1 parent f68e65c commit 27bdad6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uv venv
uv pip install . -r dev-requirements.txt
- name: Run tests
run: uv run python -m pytest
run: uv run python -m pytest --cov crossandra --cov-report term-missing
- name: Lint code
if: always()
run: |
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mypy ~= 1.10.0
pytest ~= 8.2.0
pytest-cov ~= 5.0.0
ruff ~= 0.4.2
5 changes: 2 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ install:
uv pip install . -r dev-requirements.txt

check:
python -m pytest
mypy --strict crossandra
mypy --strict tests
python -m pytest --cov crossandra --cov-report term-missing
mypy --strict crossandra tests
ruff check
ruff format --check
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ archs = ["auto", "aarch64"]
[tool.cibuildwheel.macos]
archs = ["x86_64", "universal2"]

[tool.coverage.report]
exclude_also = [
"if TYPE_CHECKING:",
"if sys.version_info.*:",
"if __name__ == \"__main__\":",
]

[tool.ruff]
target-version = "py38"

Expand Down
66 changes: 66 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
RuleGroup,
common,
)
from crossandra.lib import invert_enum
from crossandra.rule import IGNORED, NOT_APPLIED

if TYPE_CHECKING:
Expand Down Expand Up @@ -198,3 +199,68 @@ def test_rule_group() -> None:
p, r = RuleGroup((a, b))

assert (a, b) == (x, y) == (p, r)


def test_rule_properties() -> None:
a = Rule[str]("a")
b = Rule[str]("a")

assert a == b
assert a != 1
assert isinstance(a | a | b, RuleGroup)
assert isinstance(a | (a | b), RuleGroup)


@pytest.mark.parametrize(
"rule_or_rulegroup",
[
Rule[str]("a"),
RuleGroup((Rule[str]("a"), Rule[str]("b"))),
],
)
def test_rule_group_creation_fail(rule_or_rulegroup: Rule[Any] | RuleGroup) -> None:
with pytest.raises(TypeError):
rule_or_rulegroup | 1


def test_invert_enum_with_aliases() -> None:
class Test(Enum):
FOO = "1"
BAR = ("2", "3")

assert invert_enum(Test) == {"1": Test.FOO, "2": Test.BAR, "3": Test.BAR}


def test_tokenize_lines() -> None:
assert Crossandra(rules=[common.WORD], ignore_whitespace=True).tokenize_lines(
"a b\nc\rde"
) == [["a", "b"], ["c"], ["de"]]


def test_break_path() -> None:
class Test(Enum):
X = "ABC"
Y = "A"
Z = "B"

assert Crossandra(Test).tokenize("ABABAABABC") == [
Test.Y,
Test.Z,
Test.Y,
Test.Z,
Test.Y,
Test.Y,
Test.Z,
Test.X,
]


def test_tokenize_fast_with_ignored() -> None:
class Test(Enum):
FOO = "x"
BAR = "y"

assert Crossandra(Test, ignored_characters="z").tokenize("xzy") == [
Test.FOO,
Test.BAR,
]

0 comments on commit 27bdad6

Please sign in to comment.