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
2020 benchmarks_driver , refactor_driver
2121)
2222
23- class PerfTestFinder (YAMLTestFinder ):
23+
24+ class StandardTestFinder (YAMLTestFinder ):
2425 """
25- Testcase finder to use in perf mode.
26+ Testcase finder to use in stadard mode.
2627
27- This finder automatically discard tests that do not have performance
28- measuring instructions. This is preferable to creating these tests but
29- skipping them (SKIP status) as most tests do not support performance
30- measurements: less noise in the testsuite report.
28+ This finder exclude test cases from the 'tests/perf/' directory to avoid
29+ running them in standard mode. This allow performance exclusive test
30+ cases.
31+ This finder doesn't exclude all performance compatible tests because
32+ we want to be able to write baseline/performance hybrid tests.
3133 """
3234
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+
3357 def probe (self ,
3458 testsuite : TestsuiteCore ,
3559 dirpath : str ,
3660 dirnames : list [str ],
37- filenames : list [str ]) -> TestFinderResult :
61+ filenames : list [str ]) -> TestFinderResult | None :
3862 # Probe testcases as usual
3963 result = super ().probe (testsuite , dirpath , dirnames , filenames )
4064
41- # Reject testcases which do not contain performance measuring
42- # instructions.
43- if result is None or P .join ("tests" , "perf" ) not in result .test_dir :
65+ # Reject all tests which have 'tests/perf' in their directory name
66+ if result is None or P .join ("tests" , "perf" ) in result .test_dir :
4467 return None
4568
46- # Make sure that the driver supports performance measuring
47- if not result .driver_cls .perf_supported :
48- raise ProbingError (
49- f"The '{ result .driver_cls .__name__ } ' driver does not support"
50- " performance measuring"
51- )
69+ return self .verify_then_return (result )
5270
53- return result
5471
55-
56- class StandardTestFinder (YAMLTestFinder ):
72+ class PerfTestFinder (StandardTestFinder ):
5773 """
58- Testcase finder to use in stadard mode.
74+ Testcase finder to use in perf mode.
5975
60- This finder exclude test cases from the 'tests/perf/' directory to avoid
61- running them in standard mode. This allow performance exclusive test
62- cases.
63- This finder doesn't exclude all performance compatible tests because
64- we want to be able to write baseline/performance hybrid tests.
76+ This finder automatically discard tests that do not have performance
77+ measuring instructions. This is preferable to creating these tests but
78+ skipping them (SKIP status) as most tests do not support performance
79+ measurements: less noise in the testsuite report.
6580 """
6681
6782 def probe (self ,
@@ -72,11 +87,19 @@ def probe(self,
7287 # Probe testcases as usual
7388 result = super ().probe (testsuite , dirpath , dirnames , filenames )
7489
75- # Reject all tests which have 'tests/perf' in their directory name
76- if result is None or P .join ("tests" , "perf" ) in result .test_dir :
90+ # Reject testcases which do not contain performance measuring
91+ # instructions.
92+ if result is None or P .join ("tests" , "perf" ) not in result .test_dir :
7793 return None
7894
79- return result
95+ # Make sure that the driver supports performance measuring
96+ if not result .driver_cls .perf_supported :
97+ raise ProbingError (
98+ f"The '{ result .driver_cls .__name__ } ' driver does not support"
99+ " performance measuring"
100+ )
101+
102+ return self .verify_then_return (result )
80103
81104
82105class LKQLTestsuite (Testsuite ):
@@ -137,12 +160,24 @@ def add_options(self, parser: ArgumentParser) -> None:
137160 ' to get feedback quickly during development.'
138161 )
139162
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+
140170 @property
141171 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+
142177 return [
143- PerfTestFinder ()
178+ PerfTestFinder (env_constraints )
144179 if self .env .perf_mode else
145- StandardTestFinder ()
180+ StandardTestFinder (env_constraints )
146181 ]
147182
148183 def set_up (self ) -> None :
0 commit comments