@@ -42,12 +42,10 @@ def make_validation_test(rule, test_name, regen=REGEN_TEST_FIXTURES):
42
42
43
43
def closure_test_function (* args , ** kwargs ):
44
44
check_special_rule_cannot_be_detected (rule )
45
-
46
45
else :
47
46
48
47
def closure_test_function (* args , ** kwargs ):
49
48
check_rule_or_license_can_be_self_detected_exactly (rule )
50
- check_ignorable_clues (rule , regen = regen )
51
49
52
50
closure_test_function .__name__ = test_name
53
51
closure_test_function .funcname = test_name
@@ -107,6 +105,25 @@ def check_rule_or_license_can_be_self_detected_exactly(rule):
107
105
assert '\n ' .join (failure_trace ) == '\n ' .join (expected )
108
106
109
107
108
+ def make_ignorable_clues_test (rule , test_name , regen = REGEN_TEST_FIXTURES ):
109
+ """
110
+ Build and return a test function closing on tests arguments.
111
+ """
112
+ if isinstance (test_name , bytes ):
113
+ test_name = test_name .decode ('utf-8' )
114
+
115
+ if rule .is_false_positive :
116
+ return
117
+
118
+ def closure_test_function (* args , ** kwargs ):
119
+ check_ignorable_clues (rule , regen = regen )
120
+
121
+ closure_test_function .__name__ = test_name
122
+ closure_test_function .funcname = test_name
123
+
124
+ return closure_test_function
125
+
126
+
110
127
def check_ignorable_clues (licensish , regen = REGEN_TEST_FIXTURES , verbose = False ):
111
128
"""
112
129
Validate that all expected ignorable clues declared in a `licensish` License
@@ -152,7 +169,13 @@ def check_ignorable_clues(licensish, regen=REGEN_TEST_FIXTURES, verbose=False):
152
169
assert saneyaml .dump (result ) == saneyaml .dump (expected )
153
170
154
171
155
- def build_validation_tests (rules , test_classes , regen = REGEN_TEST_FIXTURES ):
172
+ def build_validation_tests (
173
+ rules ,
174
+ test_classes ,
175
+ test_func_creator = make_validation_test ,
176
+ test_name_prefix = "test_validate_detect_" ,
177
+ regen = REGEN_TEST_FIXTURES ,
178
+ ):
156
179
"""
157
180
Dynamically build an individual test method for each rule texts in a
158
181
``rules`` iterable of Rule objects then attach the test methods to the
@@ -178,16 +201,14 @@ def build_validation_tests(rules, test_classes, regen=REGEN_TEST_FIXTURES):
178
201
# as they are not included in the standard indexing
179
202
if rule .language != 'en' :
180
203
continue
181
- test_name = (
182
- 'test_validate_detect_' +
183
- text .python_safe_name (rule .identifier )
184
- )
185
- test_method = make_validation_test (
204
+ test_name = f"{ test_name_prefix } { text .python_safe_name (rule .identifier )} "
205
+ test_method = test_func_creator (
186
206
rule = rule ,
187
207
test_name = test_name ,
188
208
regen = regen ,
189
209
)
190
- setattr (cls , test_name , test_method )
210
+ if test_method :
211
+ setattr (cls , test_name , test_method )
191
212
192
213
193
214
class TestValidateLicenseBasic (unittest .TestCase ):
@@ -232,6 +253,54 @@ class TestValidateLicenseExtended5(unittest.TestCase):
232
253
TestValidateLicenseExtended4 ,
233
254
TestValidateLicenseExtended5 ,
234
255
],
256
+ test_func_creator = make_validation_test ,
257
+ test_name_prefix = "test_validate_detect_" ,
258
+ regen = REGEN_TEST_FIXTURES ,
259
+ )
260
+
261
+
262
+ class TestValidateLicenseIgnorableCluesBasic (unittest .TestCase ):
263
+ # Test functions are attached to this class at import time
264
+ pytestmark = pytest .mark .scanslow
265
+
266
+
267
+ class TestValidateLicenseIgnorableClues1 (unittest .TestCase ):
268
+ # Test functions are attached to this class at import time
269
+ pytestmark = pytest .mark .scanvalidate
270
+
271
+
272
+ class TestValidateLicenseIgnorableClues2 (unittest .TestCase ):
273
+ # Test functions are attached to this class at import time
274
+ pytestmark = pytest .mark .scanvalidate
275
+
276
+
277
+ class TestValidateLicenseIgnorableClues3 (unittest .TestCase ):
278
+ # Test functions are attached to this class at import time
279
+ pytestmark = pytest .mark .scanvalidate
280
+
281
+
282
+ class TestValidateLicenseIgnorableClues4 (unittest .TestCase ):
283
+ # Test functions are attached to this class at import time
284
+ pytestmark = pytest .mark .scanvalidate
285
+
286
+
287
+ class TestValidateLicenseIgnorableClues5 (unittest .TestCase ):
288
+ # Test functions are attached to this class at import time
289
+ pytestmark = pytest .mark .scanvalidate
290
+
291
+
292
+ build_validation_tests (
293
+ _rules ,
294
+ test_classes = [
295
+ TestValidateLicenseIgnorableCluesBasic ,
296
+ TestValidateLicenseIgnorableClues1 ,
297
+ TestValidateLicenseIgnorableClues2 ,
298
+ TestValidateLicenseIgnorableClues3 ,
299
+ TestValidateLicenseIgnorableClues4 ,
300
+ TestValidateLicenseIgnorableClues5 ,
301
+ ],
302
+ test_func_creator = make_ignorable_clues_test ,
303
+ test_name_prefix = "test_ignorables_in_license_" ,
235
304
regen = REGEN_TEST_FIXTURES ,
236
305
)
237
306
0 commit comments