7
7
import statistics
8
8
import subprocess
9
9
import sys
10
- from typing import TextIO , Callable
10
+ from typing import TextIO , Callable , Any
11
11
12
12
from e3 .fs import mkdir , rm
13
13
from e3 .testsuite import Testsuite , logger , TestsuiteCore
@@ -32,22 +32,44 @@ class StandardTestFinder(YAMLTestFinder):
32
32
we want to be able to write baseline/performance hybrid tests.
33
33
"""
34
34
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
+
35
57
def probe (self ,
36
58
testsuite : TestsuiteCore ,
37
59
dirpath : str ,
38
60
dirnames : list [str ],
39
- filenames : list [str ]) -> TestFinderResult :
61
+ filenames : list [str ]) -> TestFinderResult | None :
40
62
# Probe testcases as usual
41
63
result = super ().probe (testsuite , dirpath , dirnames , filenames )
42
64
43
65
# Reject all tests which have 'tests/perf' in their directory name
44
66
if result is None or P .join ("tests" , "perf" ) in result .test_dir :
45
67
return None
46
68
47
- return result
69
+ return self . verify_then_return ( result )
48
70
49
71
50
- class PerfTestFinder (YAMLTestFinder ):
72
+ class PerfTestFinder (StandardTestFinder ):
51
73
"""
52
74
Testcase finder to use in perf mode.
53
75
@@ -77,7 +99,7 @@ def probe(self,
77
99
" performance measuring"
78
100
)
79
101
80
- return result
102
+ return self . verify_then_return ( result )
81
103
82
104
83
105
class LKQLTestsuite (Testsuite ):
@@ -138,12 +160,24 @@ def add_options(self, parser: ArgumentParser) -> None:
138
160
' to get feedback quickly during development.'
139
161
)
140
162
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
+
141
170
@property
142
171
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
+
143
177
return [
144
- PerfTestFinder ()
178
+ PerfTestFinder (env_constraints )
145
179
if self .env .perf_mode else
146
- StandardTestFinder ()
180
+ StandardTestFinder (env_constraints )
147
181
]
148
182
149
183
def set_up (self ) -> None :
0 commit comments