Skip to content

Commit fa17a2f

Browse files
[CI] Updates file hygiene in tests (autoflake)
1 parent b217291 commit fa17a2f

8 files changed

Lines changed: 324 additions & 182 deletions

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'''Testing module for locstat'''
1+
"""Testing module for locstat"""

tests/constants.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Final
22

3-
__all__ = ("UNIX_NEWLINE",
4-
"WIN_NEWLINE")
3+
__all__ = ("UNIX_NEWLINE", "WIN_NEWLINE")
54

65
UNIX_NEWLINE: Final[str] = "\n"
7-
WIN_NEWLINE: Final[str] = "\r\n"
6+
WIN_NEWLINE: Final[str] = "\r\n"

tests/fixtures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from locstat.data_structures.verbosity import Verbosity
66
from locstat.data_structures.parse_modes import ParseMode
77

8+
89
@dataclass
910
class MockConfig:
1011
verbosity: Verbosity = field(default=Verbosity.BARE)
@@ -14,14 +15,17 @@ class MockConfig:
1415

1516
@property
1617
def configurable(self) -> frozenset[str]:
17-
return frozenset(["verbosity", "minimum_characters",
18-
"max_depth", "parsing_mode"])
18+
return frozenset(
19+
["verbosity", "minimum_characters", "max_depth", "parsing_mode"]
20+
)
21+
1922

2023
@pytest.fixture
2124
def mock_config() -> MockConfig:
2225
return MockConfig()
2326

27+
2428
@pytest.fixture
2529
def mock_dir(tmp_path_factory):
2630
path = tmp_path_factory.mktemp("_temp_dir")
27-
return path
31+
return path

tests/integrity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'''Integrity tests'''
1+
"""Integrity tests"""

tests/integrity/test_parsing_modes_consistency.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from locstat.utilities.core import derive_file_parser
99
from locstat.data_structures.parse_modes import ParseMode
1010

11+
1112
def _populate_directory(directory: Path) -> None:
1213
directory.mkdir(parents=True, exist_ok=True)
1314

@@ -19,9 +20,7 @@ def _populate_directory(directory: Path) -> None:
1920
for d in (src, utils, tests, data):
2021
d.mkdir(parents=True, exist_ok=True)
2122

22-
(src / "main.py").write_text(
23-
textwrap.dedent(
24-
"""
23+
(src / "main.py").write_text(textwrap.dedent("""
2524
\"\"\"
2625
Entry point for the application.
2726
\"\"\"
@@ -38,14 +37,9 @@ def main():
3837
3938
if __name__ == "__main__":
4039
main()
41-
"""
42-
).strip()
43-
+ "\n"
44-
)
40+
""").strip() + "\n")
4541

46-
(utils / "math_utils.py").write_text(
47-
textwrap.dedent(
48-
"""
42+
(utils / "math_utils.py").write_text(textwrap.dedent("""
4943
\"\"\"
5044
Utility functions for math operations.
5145
\"\"\"
@@ -63,14 +57,9 @@ def add(a: int, b: int) -> int:
6357
The sum of a and b
6458
\"\"\"
6559
return a + b
66-
"""
67-
).strip()
68-
+ "\n"
69-
)
60+
""").strip() + "\n")
7061

71-
(tests / "test_math_utils.py").write_text(
72-
textwrap.dedent(
73-
"""
62+
(tests / "test_math_utils.py").write_text(textwrap.dedent("""
7463
import pytest
7564
7665
from src.utils.math_utils import add
@@ -83,14 +72,9 @@ def test_add_basic():
8372
8473
def test_add_negative_numbers():
8574
assert add(-1, -2) == -3
86-
"""
87-
).strip()
88-
+ "\n"
89-
)
75+
""").strip() + "\n")
9076

91-
(directory / "README.md").write_text(
92-
textwrap.dedent(
93-
"""
77+
(directory / "README.md").write_text(textwrap.dedent("""
9478
# Mock Project
9579
9680
This is a fake project structure used for testing filesystem behavior.
@@ -99,10 +83,7 @@ def test_add_negative_numbers():
9983
- Python code
10084
- Nested directories
10185
- Symlinks
102-
"""
103-
).strip()
104-
+ "\n"
105-
)
86+
""").strip() + "\n")
10687

10788
(data / "sample.txt").write_text(
10889
"This is a sample data file.\n\nIt has multiple lines.\n"
@@ -116,23 +97,31 @@ def test_add_negative_numbers():
11697
except (OSError, NotImplementedError):
11798
pass
11899

100+
119101
def test_parse_mode_consistency(mock_dir, mock_config):
120102
_populate_directory(mock_dir)
121103

122-
object.__setattr__(mock_config, "symbol_mapping", {"py" : (b"#", None, None)})
104+
object.__setattr__(mock_config, "symbol_mapping", {"py": (b"#", None, None)})
123105

124106
outputs: dict[ParseMode, array.array] = {}
125107
for parse_mode in ParseMode:
126-
result: array.array = array.array("L", (0,0))
108+
result: array.array = array.array("L", (0, 0))
127109
mock_config.parsing_mode = parse_mode
128-
parse_directory(os.scandir(mock_dir),
129-
mock_config,
130-
result,
131-
-1,
132-
derive_file_parser(parse_mode))
110+
parse_directory(
111+
os.scandir(mock_dir),
112+
mock_config,
113+
result,
114+
-1,
115+
derive_file_parser(parse_mode),
116+
)
133117
outputs[parse_mode] = result
134118

135-
assert len(set(tuple(o) for o in outputs.values())) == 1, \
136-
" ".join(("Parsing modes produce different outputs",
137-
"\n".join(f"{mode}: Total={total}, LOC={loc}"
138-
for mode, (total, loc) in outputs.items())))
119+
assert len(set(tuple(o) for o in outputs.values())) == 1, " ".join(
120+
(
121+
"Parsing modes produce different outputs",
122+
"\n".join(
123+
f"{mode}: Total={total}, LOC={loc}"
124+
for mode, (total, loc) in outputs.items()
125+
),
126+
)
127+
)

tests/unit/test_argument_parser.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
'''Unit tests for CLI argument parser'''
1+
"""Unit tests for CLI argument parser"""
2+
23
import argparse
34

45
from locstat.argparser import initialize_parser, parse_arguments
56

67
from tests.fixtures import mock_config, mock_dir
78

9+
810
def test_exclusive_groups(mock_config, mock_dir) -> None:
911
parser: argparse.ArgumentParser = initialize_parser(mock_config)
1012

1113
illegal_combinations: tuple[str, ...] = (
1214
"-it py -xt js",
1315
"-if foo.py -xf bar.py",
14-
"-id foo -xd bar"
16+
"-id foo -xd bar",
1517
)
1618

1719
base_args: str = f"-d {mock_dir}"
@@ -20,11 +22,13 @@ def test_exclusive_groups(mock_config, mock_dir) -> None:
2022
failed: bool = False
2123
try:
2224
parse_arguments(" ".join((base_args, combination)).split(), parser)
23-
except SystemExit as se:
25+
except SystemExit:
2426
failed = True
2527
finally:
26-
assert failed, \
27-
f"Illegal argument combination '{combination}' accepted by argument parser"
28+
assert (
29+
failed
30+
), f"Illegal argument combination '{combination}' accepted by argument parser"
31+
2832

2933
def test_allowed_combinations(mock_config, mock_dir):
3034
parser: argparse.ArgumentParser = initialize_parser(mock_config)
@@ -35,7 +39,7 @@ def test_allowed_combinations(mock_config, mock_dir):
3539
"-if foo.py bar.py",
3640
"-xf foo.py bar.py",
3741
"-id foo bar",
38-
"-xd foo bar"
42+
"-xd foo bar",
3943
)
4044

4145
base_args: str = f"-d {mock_dir}"
@@ -46,32 +50,37 @@ def test_allowed_combinations(mock_config, mock_dir):
4650
except SystemExit as e:
4751
e.add_note(f"Original argument: {base_args + arg}")
4852
raise e
49-
53+
54+
5055
def test_target_existence(mock_config, mock_dir):
5156
parser: argparse.ArgumentParser = initialize_parser(mock_config)
5257

5358
mock_subdir = mock_dir / "_temp_subdir"
5459
mock_file = mock_subdir / "_temp_file.py"
5560

56-
arg_mapping: dict[str, type[BaseException]] = {f"-f {mock_file}" : SystemExit,
57-
f"-d {mock_subdir}" : SystemExit}
61+
arg_mapping: dict[str, type[BaseException]] = {
62+
f"-f {mock_file}": SystemExit,
63+
f"-d {mock_subdir}": SystemExit,
64+
}
5865

5966
for arg, expected_exception in arg_mapping.items():
6067
failed: bool = False
6168
arg_sequence: list[str] = arg.split()
6269
try:
6370
parse_arguments(arg_sequence, parser)
6471
except SystemExit as e:
65-
assert isinstance(e, expected_exception), \
66-
" ".join((f"Non-existing target {arg_sequence[-1]} rejected with unexpected error",
67-
f"Expected: {expected_exception}",
68-
f"Raised: {e}"))
72+
assert isinstance(e, expected_exception), " ".join(
73+
(
74+
f"Non-existing target {arg_sequence[-1]} rejected with unexpected error",
75+
f"Expected: {expected_exception}",
76+
f"Raised: {e}",
77+
)
78+
)
6979
failed = True
70-
assert failed, \
71-
f"Non-existing target {arg_sequence[-1]} accepted"
80+
assert failed, f"Non-existing target {arg_sequence[-1]} accepted"
7281

7382
mock_subdir.mkdir()
7483
mock_file.touch()
7584

7685
for arg in arg_mapping:
77-
parse_arguments(arg.split(), parser)
86+
parse_arguments(arg.split(), parser)

0 commit comments

Comments
 (0)