Skip to content

Commit 46646b7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5e4fe2c commit 46646b7

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#!/usr/bin/env python3
2+
from __future__ import annotations
23

34
import subprocess
45
import sys
56
from pathlib import Path
67

7-
FORBIDDEN = {"a", "an", "the"}
8+
FORBIDDEN = {'a', 'an', 'the'}
89

910

1011
def git_ls_python_files():
1112
result = subprocess.run(
12-
["git", "ls-files", "*.py"],
13+
['git', 'ls-files', '*.py'],
1314
capture_output=True,
1415
text=True,
1516
check=True,
@@ -20,14 +21,14 @@ def git_ls_python_files():
2021
def is_test_file(path: Path) -> bool:
2122
name = path.name
2223
return (
23-
name.startswith("test_")
24-
or name.startswith("tests_")
25-
or name.endswith("_test.py")
24+
name.startswith('test_') or
25+
name.startswith('tests_') or
26+
name.endswith('_test.py')
2627
)
2728

2829

2930
def has_forbidden_article(path: Path) -> bool:
30-
parts = path.stem.split("_")
31+
parts = path.stem.split('_')
3132
return any(part in FORBIDDEN for part in parts)
3233

3334

@@ -37,12 +38,12 @@ def main() -> int:
3738
continue
3839

3940
if has_forbidden_article(path):
40-
print("ERROR: Forbidden article in test filename:")
41+
print('ERROR: Forbidden article in test filename:')
4142
print(path)
4243
return 1
4344

4445
return 0
4546

4647

47-
if __name__ == "__main__":
48+
if __name__ == '__main__':
4849
sys.exit(main())

pre_commit_hooks/tests_should_end_in_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from __future__ import annotations
2+
23
import argparse
34
import os.path
45
import re
56
from collections.abc import Sequence
7+
8+
69
def main(argv: Sequence[str] | None = None) -> int:
710
parser = argparse.ArgumentParser()
811
parser.add_argument('filenames', nargs='*')
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
import sys
35
from pathlib import Path
46

57

6-
HOOK = Path(__file__).parents[1] / "pre_commit_hooks" / "forbid_articles_in_test_filenames.py"
8+
HOOK = Path(__file__).parents[1] / 'pre_commit_hooks' / 'forbid_articles_in_test_filenames.py'
79

810

911
def run_hook(repo_path: Path):
@@ -18,39 +20,39 @@ def run_hook(repo_path: Path):
1820

1921

2022
def init_git_repo(tmp_path: Path):
21-
subprocess.run(["git", "init"], cwd=tmp_path, check=True)
22-
subprocess.run(["git", "config", "user.email", "[email protected]"], cwd=tmp_path, check=True)
23-
subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, check=True)
23+
subprocess.run(['git', 'init'], cwd=tmp_path, check=True)
24+
subprocess.run(['git', 'config', 'user.email', '[email protected]'], cwd=tmp_path, check=True)
25+
subprocess.run(['git', 'config', 'user.name', 'Test User'], cwd=tmp_path, check=True)
2426

2527

2628
def git_add_all(tmp_path: Path):
27-
subprocess.run(["git", "add", "."], cwd=tmp_path, check=True)
29+
subprocess.run(['git', 'add', '.'], cwd=tmp_path, check=True)
2830

2931

3032
def test_fails_on_forbidden_article_in_test_filename(tmp_path: Path):
3133
init_git_repo(tmp_path)
3234

33-
bad_test = tmp_path / "tests_create_an_address.py"
34-
bad_test.write_text("def test_something(): pass\n")
35+
bad_test = tmp_path / 'tests_create_an_address.py'
36+
bad_test.write_text('def test_something(): pass\n')
3537

3638
git_add_all(tmp_path)
3739

3840
code, output = run_hook(tmp_path)
3941

4042
assert code == 1
41-
assert "ERROR: Forbidden article in test filename:" in output
42-
assert "tests_create_an_address.py" in output
43+
assert 'ERROR: Forbidden article in test filename:' in output
44+
assert 'tests_create_an_address.py' in output
4345

4446

4547
def test_passes_on_valid_test_filename(tmp_path: Path):
4648
init_git_repo(tmp_path)
4749

48-
good_test = tmp_path / "tests_create_address.py"
49-
good_test.write_text("def test_something(): pass\n")
50+
good_test = tmp_path / 'tests_create_address.py'
51+
good_test.write_text('def test_something(): pass\n')
5052

5153
git_add_all(tmp_path)
5254

5355
code, output = run_hook(tmp_path)
5456

5557
assert code == 0
56-
assert output == ""
58+
assert output == ''

0 commit comments

Comments
 (0)