def build_tests(test_dir, clazz, regen=False):
    """
    Dynamically build license_test methods from a sequence of LicenseTest and
    attach these method to the clazz license test class.
    """

    license_tests = (LicenseTest(data_file, test_file)
                     for data_file, test_file in get_test_file_pairs(test_dir))

    # TODO: check that we do not have duplicated tests with same data and text

    for license_test in license_tests:
        test_name = license_test.get_test_method_name()
        test_file = license_test.test_file

        # closure on the license_test params
        test_method = make_test(license_test, regen=regen)

        # avoid duplicated test method
        if hasattr(clazz, test_name):
            msg = (
                'Duplicated test method name: {test_name}: file://{test_file}'
            ).format(**locals())
            raise Exception(msg)

        # attach that method to our license_test class
        setattr(clazz, test_name, test_method)
Exemple #2
0
 def load_from(test_dir):
     """
     Return an iterable of LicenseTest objects loaded from `test_dir`
     """
     return [
         LicenseTest(data_file, test_file)
         for data_file, test_file in get_test_file_pairs(test_dir)
     ]
Exemple #3
0
def load_filetype_tests(test_dir):
    """
    Yield an iterable of FileTypeTest loaded from test data files in `test_dir`.
    """
    all_test_files = get_test_file_pairs(test_dir)

    for data_file, test_file in all_test_files:
        yield FileTypeTest(data_file, test_file)
Exemple #4
0
def load_copyright_tests(test_dir=test_env.test_data_dir):
    """
    Yield an iterable of CopyrightTest loaded from test data files in `test_dir`.
    """
    test_dirs = (path.join(test_dir, td) for td in
        ('copyrights', 'ics', 'holders', 'authors', 'years', 'generated'))

    all_test_files = chain.from_iterable(
        get_test_file_pairs(td) for td in test_dirs)

    for data_file, test_file in all_test_files:
        yield CopyrightTest(data_file, test_file)