@@ -64,28 +64,35 @@ def _check_functional_tests_structure(
64
64
files : set [Path ] = set ()
65
65
dirs : set [Path ] = set ()
66
66
67
+ def _get_files_from_dir (
68
+ path : Path , violations : list [tuple [Path , int ]]
69
+ ) -> list [Path ]:
70
+ """Return directories and files from a directory and handles violations."""
71
+ files_without_leading_underscore = list (
72
+ p for p in path .iterdir () if not p .stem .startswith ("_" )
73
+ )
74
+ if len (files_without_leading_underscore ) > max_file_per_directory :
75
+ violations .append ((path , len (files_without_leading_underscore )))
76
+ return files_without_leading_underscore
77
+
67
78
def walk (path : Path ) -> Iterator [Path ]:
68
79
violations : list [tuple [Path , int ]] = []
69
80
violations_msgs : set [str ] = set ()
70
- parent_dir_files = list (path .iterdir ())
71
- if len (parent_dir_files ) > max_file_per_directory :
72
- violations .append ((path , len (parent_dir_files )))
81
+ parent_dir_files = _get_files_from_dir (path , violations )
73
82
error_msg = (
74
83
"The following directory contains too many functional tests files:\n "
75
84
)
76
85
for _file_or_dir in parent_dir_files :
77
86
if _file_or_dir .is_dir ():
78
- _files = list (_file_or_dir .iterdir ())
79
- if len (_files ) > max_file_per_directory :
80
- violations .append ((_file_or_dir , len (_files )))
87
+ _files = _get_files_from_dir (_file_or_dir , violations )
81
88
yield _file_or_dir .resolve ()
82
89
try :
83
90
yield from walk (_file_or_dir )
84
91
except AssertionError as e :
85
92
violations_msgs .add (str (e ).replace (error_msg , "" ))
86
93
else :
87
94
yield _file_or_dir .resolve ()
88
- if violations :
95
+ if violations or violations_msgs :
89
96
_msg = error_msg
90
97
for offending_file , number in violations :
91
98
_msg += f"- { offending_file } : { number } when the max is { max_file_per_directory } \n "
@@ -95,8 +102,6 @@ def walk(path: Path) -> Iterator[Path]:
95
102
96
103
# Collect all sub-directories and files in directory
97
104
for file_or_dir in walk (directory ):
98
- if file_or_dir .stem .startswith ("_" ):
99
- continue
100
105
if file_or_dir .is_dir ():
101
106
dirs .add (file_or_dir )
102
107
elif file_or_dir .suffix == ".py" :
@@ -116,6 +121,7 @@ def walk(path: Path) -> Iterator[Path]:
116
121
):
117
122
if not file .stem .startswith (file .parent .stem ):
118
123
misplaced_file .append (file )
124
+
119
125
if directory_does_not_exists or misplaced_file :
120
126
msg = "The following functional tests are disorganized:\n "
121
127
for file , possible_dir in directory_does_not_exists :
0 commit comments