MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / build_tests

Function build_tests

src/licensedcode_test_utils.py:157–186  ·  view source on GitHub ↗

Dynamically build license_test methods from a sequence of LicenseTest and attach these method to the clazz license test class.

(test_dir, clazz, unknown_detection=False, regen=REGEN_TEST_FIXTURES)

Source from the content-addressed store, hash-verified

155
156
157def build_tests(test_dir, clazz, unknown_detection=False, regen=REGEN_TEST_FIXTURES):
158 """
159 Dynamically build license_test methods from a sequence of LicenseTest and
160 attach these method to the clazz license test class.
161 """
162
163 license_tests = LicenseTest.load_from(test_dir)
164
165 # TODO: check that we do not have duplicated tests with same data and text
166
167 for license_test in license_tests:
168 test_name = license_test.get_test_method_name()
169 test_file = license_test.test_file
170
171 # closure on the license_test params
172 test_method = make_test(
173 license_test,
174 unknown_detection=unknown_detection,
175 regen=regen,
176 )
177
178 # avoid duplicated test method
179 if hasattr(clazz, test_name):
180 msg = (
181 f'Duplicated test method name: {test_name}: file://{test_file}'
182 )
183 raise Exception(msg)
184
185 # attach that method to our license_test class
186 setattr(clazz, test_name, test_method)
187
188
189def make_test(license_test, unknown_detection=False, regen=REGEN_TEST_FIXTURES):

Calls 3

load_fromMethod · 0.80
make_testFunction · 0.70
get_test_method_nameMethod · 0.45

Tested by

no test coverage detected