Example #1
0
def load_tests(loader, tests, pattern):

    default_checks = [e.name for e
                      in pkg_resources.iter_entry_points('flake8.extension')]
    flake8_style = engine.get_style_guide(
        parse_argv=False,
        # We are testing neutron-specific hacking rules, so there is no need
        # to run the checks registered by hacking or other flake8 extensions.
        ignore=default_checks)
    options = flake8_style.options

    for name, check in checks.__dict__.items():
        if not hasattr(check, 'name'):
            continue
        if check.name != checks.__name__:
            continue
        if not check.__doc__:
            continue
        for (lineno, (raw, line)) in enumerate(_get_lines(check)):
            code, __, filename, source = line
            lines = [part.replace(r'\t', '\t') + '\n'
                     for part in source.split(r'\n')]
            file_cases.append(("%s-line-%s" % (name, lineno),
                              dict(lines=lines, raw=raw, options=options,
                                   code=code, filename=filename)))
    return testscenarios.load_tests_apply_scenarios(loader, tests, pattern)
Example #2
0
def load_tests_input_scenario_utils(*args):
    """
    Wrapper for testscenarios to set the scenarios to avoid running a getattr
    on the CONF object at import.
    """
    if getattr(args[0], "suiteClass", None) is not None:
        loader, standard_tests, pattern = args
    else:
        standard_tests, module, loader = args
    output = None
    scenario_utils = None
    try:
        scenario_utils = InputScenarioUtils()
        scenario_flavor = scenario_utils.scenario_flavors
        scenario_image = scenario_utils.scenario_images
    except (exc_lib.InvalidCredentials, TypeError):
        output = standard_tests
    finally:
        if scenario_utils:
            scenario_utils.clear_creds()
    if output is not None:
        return output
    for test in testtools.iterate_tests(standard_tests):
        setattr(test, "scenarios", testscenarios.multiply_scenarios(scenario_image, scenario_flavor))
    return testscenarios.load_tests_apply_scenarios(*args)
Example #3
0
def load_tests(loader, tests, pattern):

    flake8_style = engine.get_style_guide(parse_argv=False,
                                          # Ignore H104 otherwise it's
                                          # raised on doctests.
                                          ignore=('F', 'H104'))
    options = flake8_style.options

    for entry in pkg_resources.iter_entry_points('flake8.extension'):
        if not entry.module_name.startswith('spotless.'):
            continue
        check = entry.load()
        name = entry.attrs[0]
        if check.skip_on_py3 and six.PY3:
            continue
        for (lineno, (raw, (code, source))) in enumerate(
                test_doctest._get_lines(check)):
            lines = [part.replace(r'\t', '\t') + '\n'
                     for part in source.split(r'\n')]
            test_doctest.file_cases.append(("%s-%s-line-%s"
                                            % (entry.name, name, lineno),
                                            dict(
                                                lines=lines,
                                                raw=raw,
                                                options=options,
                                                code=code)))

    return testscenarios.load_tests_apply_scenarios(loader, tests, pattern)
Example #4
0
def load_tests(loader, tests, pattern):

    flake8_style = engine.get_style_guide(
        parse_argv=False,
        # Ignore H104 otherwise it's
        # raised on doctests.
        ignore=("F", "H104"),
    )
    options = flake8_style.options

    for name, check in checks.__dict__.items():
        if not hasattr(check, "name"):
            continue
        if check.name != checks.__name__:
            continue
        if not check.__doc__:
            continue
        for (lineno, (raw, line)) in enumerate(_get_lines(check)):
            code, __, filename, source = line
            lines = [part.replace(r"\t", "\t") + "\n" for part in source.split(r"\n")]
            file_cases.append(
                (
                    "%s-line-%s" % (name, lineno),
                    dict(lines=lines, raw=raw, options=options, code=code, filename=filename),
                )
            )
    return testscenarios.load_tests_apply_scenarios(loader, tests, pattern)
Example #5
0
def load_tests(loader, tests, pattern):

    flake8_style = engine.get_style_guide(parse_argv=False, ignore="F")
    options = flake8_style.options

    for name, check in hacking.core.__dict__.items():
        if not name.startswith("hacking_"):
            continue
        for (lineno, (raw, (code, source))) in enumerate(_get_lines(check)):
            lines = [part.replace(r"\t", "\t") + "\n" for part in source.split(r"\n")]
            file_cases.append(("%s-line-%s" % (name, lineno), dict(lines=lines, raw=raw, options=options, code=code)))
    return testscenarios.load_tests_apply_scenarios(loader, tests, pattern)
Example #6
0
def module_load_tests(loader, found_tests, pattern):
    """Apply OptimisingTestSuite on a per-module basis.

    FIXME(zzzeek): oslo.db provides this but the contract that
    "pattern" should be None no longer seems to behave as it used
    to at the module level, so this function needs to be added in this
    form.

    """

    result = testresources.OptimisingTestSuite()
    found_tests = testscenarios.load_tests_apply_scenarios(
        loader, found_tests, pattern)
    result.addTest(found_tests)
    return result
Example #7
0
 def load_tests(*args):
     """
     Wrapper for testscenarios to set the mandatory scenarios variable
     only in case a real test loader is in place. Will be automatically
     called in case the variable "load_tests" is set.
     """
     if getattr(args[0], "suiteClass", None) is not None:
         loader, standard_tests, pattern = args
     else:
         standard_tests, module, loader = args
     for test in testtools.iterate_tests(standard_tests):
         schema_file = getattr(test, "_schema_file", None)
         if schema_file is not None:
             setattr(test, "scenarios", NegativeAutoTest.generate_scenario(schema_file))
     return testscenarios.load_tests_apply_scenarios(*args)
Example #8
0
    def load_tests(loader, found_tests, pattern):
        # pattern is None if the directive is placed within
        # a test module directly, as well as within certain test
        # discovery patterns

        if pattern is not None:
            pkg_tests = loader.discover(start_dir=this_dir, pattern=pattern)

        result = testresources.OptimisingTestSuite()
        found_tests = testscenarios.load_tests_apply_scenarios(
            loader, found_tests, pattern)
        result.addTest(found_tests)

        if pattern is not None:
            result.addTest(pkg_tests)
        return result
Example #9
0
def load_tests_input_scenario_utils(*args):
    """
    Wrapper for testscenarios to set the scenarios to avoid running a getattr
    on the CONF object at import.
    """
    if getattr(args[0], 'suiteClass', None) is not None:
        loader, standard_tests, pattern = args
    else:
        standard_tests, module, loader = args
    scenario_utils = InputScenarioUtils()
    scenario_flavor = scenario_utils.scenario_flavors
    scenario_image = scenario_utils.scenario_images
    for test in testtools.iterate_tests(standard_tests):
        setattr(test, 'scenarios', testscenarios.multiply_scenarios(
            scenario_image,
            scenario_flavor))
    return testscenarios.load_tests_apply_scenarios(*args)
Example #10
0
def load_tests(loader, tests, pattern):

    flake8_style = engine.get_style_guide(parse_argv=False,
                                          # Ignore H104 otherwise it's
                                          # raised on doctests.
                                          ignore=('F', 'H104'))
    options = flake8_style.options

    for name, check in hacking.core.__dict__.items():
        if not name.startswith("hacking_"):
            continue
        for (lineno, (raw, (code, source))) in enumerate(_get_lines(check)):
            lines = [part.replace(r'\t', '\t') + '\n'
                     for part in source.split(r'\n')]
            file_cases.append(("%s-line-%s" % (name, lineno),
                              dict(lines=lines, raw=raw, options=options,
                                   code=code)))
    return testscenarios.load_tests_apply_scenarios(loader, tests, pattern)
Example #11
0
def load_tests(loader, in_tests, pattern):
    return testscenarios.load_tests_apply_scenarios(loader, in_tests, pattern)
Example #12
0
def load_tests(loader, in_tests, pattern):
    return testscenarios.load_tests_apply_scenarios(loader, in_tests, pattern)