Skip to content

Commit

Permalink
Add support to regen copyright tests #930
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
  • Loading branch information
pombredanne committed Mar 2, 2018
1 parent 8b211d9 commit 4dd2080
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/cluecode/cluecode_assert_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def collect(subdir):
yield CopyrightTest(data_file, test_file)


def make_copyright_test_functions(test, test_data_dir=test_env.test_data_dir):
def make_copyright_test_functions(test, test_data_dir=test_env.test_data_dir, regen=False):
"""
Build and return a test function closing on tests arguments and the function
name. Create only a single function for multiple tests (e.g. copyrights and
Expand All @@ -180,6 +180,11 @@ def closure_test_function(*args, **kwargs):
copyrights, authors, years, holders = cluecode.copyrights.detect(test_file)
results = dict(
copyrights=copyrights, authors=authors, years=years, holders=holders,)
if regen:
for wht in what:
setattr(test, wht, results.get(wht))
test.dump()

failing = []
all_expected = []
all_results = []
Expand Down Expand Up @@ -225,13 +230,15 @@ def closure_test_function(*args, **kwargs):
return closure_test_function, test_name


def build_tests(copyright_tests, clazz, test_data_dir=test_env.test_data_dir):
def build_tests(copyright_tests, clazz, test_data_dir=test_env.test_data_dir, regen=False):
"""
Dynamically build test methods from a sequence of CopyrightTest and attach
these method to the clazz test class.
"""
for test in copyright_tests:
# closure on the test params
method, name = make_copyright_test_functions(test, test_data_dir)
if test.expected_failures:
regen = False
method, name = make_copyright_test_functions(test, test_data_dir, regen)
# attach that method to our test class
setattr(clazz, name, method)

0 comments on commit 4dd2080

Please sign in to comment.