11from __future__ import annotations
2-
32import argparse
43import os .path
54import re
65from collections .abc import Sequence
7-
8-
96def main (argv : Sequence [str ] | None = None ) -> int :
107 parser = argparse .ArgumentParser ()
118 parser .add_argument ('filenames' , nargs = '*' )
@@ -14,27 +11,23 @@ def main(argv: Sequence[str] | None = None) -> int:
1411 '--pytest' ,
1512 dest = 'pattern' ,
1613 action = 'store_const' ,
17- const = r'^tests\/(?:[a-zA-Z0-9_]+\/)*tests [a-zA-Z0-9_]*\.py$' ,
18- default = r'^tests\/(?:[a-zA-Z0-9_]+\/)*tests [a-zA-Z0-9_]*\.py$' ,
14+ const = r'^tests\/(?:[a-zA-Z0-9_]+\/)*tests_ [a-zA-Z0-9_]*\.py$' ,
15+ default = r'^tests\/(?:[a-zA-Z0-9_]+\/)*tests_ [a-zA-Z0-9_]*\.py$' ,
1916 help = '(the default) ensure tests match %(const)s' ,
2017 )
2118 args = parser .parse_args (argv )
22-
2319 retcode = 0
2420 reg = re .compile (args .pattern )
2521 for filename in args .filenames :
2622 base = os .path .basename (filename )
2723 print (base )
28- if (
29- not reg .fullmatch (base ) and
30- not base == '.*/__init__.py' and
31- not base == '.*/conftest.py' and
32- not base == '.*/models.py'
33-
34- ):
24+ # Check for files that should be ignored
25+ if base in ('__init__.py' , 'conftest.py' , 'models.py' ):
26+ continue
27+ # Raise an exception if filename doesn't start with 'tests_' and doesn't match the pattern
28+ if not reg .fullmatch (filename ):
3529 retcode = 1
3630 print (f'{ filename } does not match pattern "{ args .pattern } "' )
37-
3831 return retcode
3932
4033
0 commit comments