Skip to content

Commit d7e3c08

Browse files
committed
test: refactor all
1 parent f15ef36 commit d7e3c08

File tree

90 files changed

+90
-2315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+90
-2315
lines changed

tests/_test_version.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/check.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

tests/common.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import importlib
44
from itertools import chain
5+
from os import walk
56
from pathlib import Path
67
from types import ModuleType
78

@@ -12,17 +13,17 @@
1213
def assert_pass(check: Check, examples: tuple[str, ...]) -> None:
1314
"""Assert that the `check` does not produce results against `examples`."""
1415
for example in examples:
15-
assert (
16-
check.check_with_flags(example) == []
17-
), f"False positive against {check.path}: '{example}'"
16+
assert check.check_with_flags(example) == [], (
17+
f"False positive against {check.path}: '{example}'"
18+
)
1819

1920

2021
def assert_fail(check: Check, examples: tuple[str, ...]) -> None:
2122
"""Assert that the `check` produces results against `examples`."""
2223
for example in examples:
23-
assert (
24-
check.check_with_flags(example) != []
25-
), f"False negative against {check.path}: '{example}'"
24+
assert check.check_with_flags(example) != [], (
25+
f"False negative against {check.path}: '{example}'"
26+
)
2627

2728

2829
def is_check(path: Path) -> bool:
@@ -34,8 +35,8 @@ def get_check_paths() -> list[Path]:
3435
"""Traverse through subdirectories and select check paths."""
3536
return [
3637
file
37-
for root, _, files in (proselint_path / "checks").walk()
38-
for file in map(root.__truediv__, files)
38+
for root, _, files in walk(proselint_path / "checks")
39+
for file in map(Path(root).__truediv__, files)
3940
if is_check(file) and (file.parent / "__init__.py").exists()
4041
]
4142

tests/test_annotations.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_archaism.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_butterick_symbols.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/test_check_examples.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def test_check_examples(
4545
result = chain.from_iterable(
4646
map(Check.check_with_flags, checks, repeat(example))
4747
)
48-
assert (
49-
result != []
50-
), f"False negative against {module_name}: '{example}'"
48+
assert result != [], (
49+
f"False negative against {module_name}: '{example}'"
50+
)
5151
for check in checks:
5252
assert_pass(check, should_pass)

tests/test_check_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_consistency_smoke(
4545
term_pair: tuple[str, str], path: str, noise: str
4646
) -> None:
4747
"""Return no matches when no elements are present."""
48-
assume(term_pair[0] not in noise and term_pair[1] not in noise)
48+
assume(all(term not in noise.lower() for term in term_pair))
4949
check_type = types.Consistency(term_pairs=(term_pair,))
5050
check = Check(check_type=check_type, path=path, message="{} || {}")
5151
assert check.check(noise) == []

tests/test_cli.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Verify that the CLI behaves correctly."""
2+
3+
from pathlib import Path
4+
5+
from click.testing import CliRunner
6+
from pytest import fixture
7+
8+
from proselint.command_line import proselint
9+
from proselint.version import __version__
10+
11+
CHAR_FILE = Path(__file__, "../invalid-chars.txt").resolve()
12+
13+
14+
@fixture
15+
def _runner() -> CliRunner: # pyright: ignore[reportUnusedFunction]
16+
return CliRunner()
17+
18+
19+
def test_exit_code_demo(_runner: CliRunner) -> None:
20+
"""Ensure that linting the demo returns an exit code of 1."""
21+
output = _runner.invoke(proselint, "--demo")
22+
assert output.exit_code == 1
23+
24+
25+
def test_exit_code_version(_runner: CliRunner) -> None:
26+
"""Ensure that getting the version returns an exit code of 0."""
27+
output = _runner.invoke(proselint, "--version")
28+
assert output.exit_code == 0
29+
30+
31+
def test_invalid_characters(_runner: CliRunner) -> None:
32+
"""Ensure that invalid characters do not break proselint."""
33+
runner = CliRunner()
34+
35+
output = runner.invoke(proselint, CHAR_FILE.as_posix())
36+
37+
assert "UnicodeDecodeError" not in output.stdout
38+
assert "FileNotFoundError" not in output.stdout
39+
40+
41+
def test_version(_runner: CliRunner) -> None:
42+
"""Ensure that the version number is correct."""
43+
runner = CliRunner()
44+
45+
output = runner.invoke(proselint, "--version")
46+
assert __version__ in output.stdout

tests/test_cliches.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)