Skip to content

Commit ca33cf1

Browse files
committed
TST: Add test for the multi-file adapter.
1 parent 1d630a0 commit ca33cf1

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/check_python_h_first/get_submodule_paths.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ def get_submodule_paths():
1313
Get paths to submodules so that we can exclude them from things like
1414
check_test_name.py, check_unicode.py, etc.
1515
"""
16-
root_directory = os.path.dirname(os.path.dirname(__file__))
16+
# Find the git repo root
17+
root_directory = os.getcwd()
18+
git_dir = os.path.join(root_directory, ".git")
19+
while not os.path.exists(git_dir):
20+
next_root = os.path.abspath(os.path.join(root_directory, ".."))
21+
if next_root == root_directory:
22+
break
23+
else:
24+
root_directory = next_root
25+
git_dir = os.path.join(root_directory, ".git")
26+
27+
# Check for submodules
1728
gitmodule_file = os.path.join(root_directory, ".gitmodules")
29+
if not os.path.exists(gitmodule_file):
30+
return []
1831
with open(gitmodule_file) as gitmodules:
1932
data = gitmodules.read().split("\n")
2033
submodule_paths = [

src/check_python_h_first/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import subprocess
1313
import sys
1414

15-
from . import get_submodule_paths
15+
from .get_submodule_paths import get_submodule_paths
1616
from .single_file import check_python_h_included_first
1717

1818
C_CPP_EXTENSIONS = (".c", ".h", ".cpp", ".hpp", ".cc", ".hh", ".cxx", ".hxx")

tests/test_wrapper.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import glob
44
import os.path
55

6-
from check_python_h_first.wrapper import find_c_cpp_files, sort_order
6+
from check_python_h_first.wrapper import find_c_cpp_files, process_files, sort_order
77

88
THIS_DIR = os.path.dirname(__file__)
99

@@ -21,3 +21,15 @@ def test_find_c_cpp_files():
2121
"""Test that the function can find all the files."""
2222
result = find_c_cpp_files(THIS_DIR)
2323
assert set(result) == set(HEADER_LIST + SOURCE_LIST)
24+
25+
26+
def test_process_files():
27+
"""Test that process files detects the number of failures.
28+
29+
Will break down if one file has multiple failures.
30+
"""
31+
result = process_files(HEADER_LIST + SOURCE_LIST)
32+
assert result == sum(
33+
os.path.basename(name).startswith("system")
34+
for name in HEADER_LIST + SOURCE_LIST
35+
)

0 commit comments

Comments
 (0)