77import statistics
88import subprocess
99import sys
10- from typing import TextIO , Callable
10+ from typing import TextIO , Callable , Any
1111
1212from e3 .fs import mkdir , rm
1313from e3 .testsuite import Testsuite , logger , TestsuiteCore
@@ -32,22 +32,44 @@ class StandardTestFinder(YAMLTestFinder):
3232 we want to be able to write baseline/performance hybrid tests.
3333 """
3434
35+ def __init__ (
36+ self ,
37+ env_constraints : dict [str , Callable [[Any ], bool ]] | None = None
38+ ):
39+ """
40+ Create a new standard test finder, with a given list of constraints to
41+ check on the test environment.
42+ """
43+ super ().__init__ ()
44+ self .env_constraints = env_constraints
45+
46+ def verify_then_return (self , test : TestFinderResult ) -> TestFinderResult | None :
47+ """
48+ Check that the provided test environment is validating all constraints
49+ attached to this test finder.
50+ """
51+ if self .env_constraints :
52+ for field , predicate in self .env_constraints .items ():
53+ if not predicate (test .test_env .get (field , None )):
54+ return None
55+ return test
56+
3557 def probe (self ,
3658 testsuite : TestsuiteCore ,
3759 dirpath : str ,
3860 dirnames : list [str ],
39- filenames : list [str ]) -> TestFinderResult :
61+ filenames : list [str ]) -> TestFinderResult | None :
4062 # Probe testcases as usual
4163 result = super ().probe (testsuite , dirpath , dirnames , filenames )
4264
4365 # Reject all tests which have 'tests/perf' in their directory name
4466 if result is None or P .join ("tests" , "perf" ) in result .test_dir :
4567 return None
4668
47- return result
69+ return self . verify_then_return ( result )
4870
4971
50- class PerfTestFinder (YAMLTestFinder ):
72+ class PerfTestFinder (StandardTestFinder ):
5173 """
5274 Testcase finder to use in perf mode.
5375
@@ -77,7 +99,7 @@ def probe(self,
7799 " performance measuring"
78100 )
79101
80- return result
102+ return self . verify_then_return ( result )
81103
82104
83105class LKQLTestsuite (Testsuite ):
@@ -138,12 +160,24 @@ def add_options(self, parser: ArgumentParser) -> None:
138160 ' to get feedback quickly during development.'
139161 )
140162
163+ parser .add_argument (
164+ '--only-with-auto-fix' ,
165+ action = 'store_true' ,
166+ help = 'Run only tests that uses the LKQL rewriting API through'
167+ ' checkers auto-fixing function.'
168+ )
169+
141170 @property
142171 def test_finders (self ) -> list [TestFinder ]:
172+ # Create the test environment constraint list
173+ env_constraints = dict ()
174+ if self .env .options .only_with_auto_fix :
175+ env_constraints ["auto_fix" ] = lambda v : v == True
176+
143177 return [
144- PerfTestFinder ()
178+ PerfTestFinder (env_constraints )
145179 if self .env .perf_mode else
146- StandardTestFinder ()
180+ StandardTestFinder (env_constraints )
147181 ]
148182
149183 def set_up (self ) -> None :
0 commit comments