Skip to content

Commit ecbff1d

Browse files
committed
TST: Add tests for function used by entry-point.
1 parent 6068996 commit ecbff1d

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/check_python_h_first/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
)
2020

2121

22-
def main():
22+
def main(argv: list[str] = None):
2323
"""Run the checker on the files passed on the command line."""
24-
args = PARSER.parse_args()
24+
args = PARSER.parse_args(argv)
2525

2626
files = args.files
2727
if len(files) == 1 and os.path.isdir(files[0]):
2828
files = find_c_cpp_files(files[0])
2929

3030
# See which of the headers include Python.h and add them to the list
3131
n_out_of_order = process_files(files)
32-
sys.exit(n_out_of_order)
32+
return n_out_of_order
3333

3434

3535
if __name__ == "__main__":
36-
main()
36+
sys.exit(main())

tests/test_main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Test the function used by the installed script."""
2+
3+
import os.path
4+
5+
import pytest
6+
7+
from check_python_h_first.__main__ import main
8+
9+
THIS_DIR = os.path.dirname(__file__)
10+
11+
12+
@pytest.mark.parametrize("to_pass", [None, []])
13+
def test_call_empty(to_pass):
14+
"""Test that calling without arguments fails."""
15+
with pytest.raises(SystemExit):
16+
assert main(to_pass) != 0
17+
18+
19+
def test_call_single():
20+
"""Test that calling with a single directory finds files."""
21+
assert main([THIS_DIR]) > 0

tests/test_wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def test_process_files():
4242
"""
4343
result = process_files(HEADER_LIST + SOURCE_LIST)
4444
assert result == sum(
45-
os.path.basename(name).startswith("system") or os.path.basename(name).startswith("bad")
45+
os.path.basename(name).startswith("system")
46+
or os.path.basename(name).startswith("bad")
4647
for name in HEADER_LIST + SOURCE_LIST
4748
)
4849

0 commit comments

Comments
 (0)