Esempio n. 1
0
def run_aiida_db_tests(tests_to_run, verbose=False):
    """
    Run all tests specified in tests_to_run.
    Return the list of test results.
    """
    # Empty test suite that will be populated
    test_suite = TestSuite()

    actually_run_tests = []
    num_tests_expected = 0

    # To avoid adding more than once the same test
    # (e.g. if you type both db and db.xxx)
    found_modulenames = set()

    for test in set(tests_to_run):
        try:
            modulenames = get_db_test_list()[test]
        except KeyError:
            if verbose:
                print >> sys.stderr, "Unknown DB test {}... skipping".format(
                    test)
            continue
        actually_run_tests.append(test)

        for modulename in modulenames:
            if modulename not in found_modulenames:
                try:
                    test_suite.addTest(
                        test_loader.loadTestsFromName(modulename))
                except AttributeError as exception:
                    try:
                        import importlib
                        import traceback
                        importlib.import_module(modulename)
                    except ImportError as exception:
                        print >> sys.stderr, (
                            "[CRITICAL] The module '{}' has an import error and the tests cannot be run:\n{}"
                            .format(modulename,
                                    traceback.format_exc(exception)))
                        sys.exit(1)
                found_modulenames.add(modulename)

        num_tests_expected = test_suite.countTestCases()

    if verbose:
        print >> sys.stderr, (
            "DB tests that will be run: {} (expecting {} tests)".format(
                ",".join(actually_run_tests), num_tests_expected))
        results = unittest.TextTestRunner(failfast=False,
                                          verbosity=2).run(test_suite)
    else:
        results = unittest.TextTestRunner(failfast=False).run(test_suite)

    if verbose:
        print "Run tests: {}".format(results.testsRun)

    return results
Esempio n. 2
0
def load_tests(*_args):
    test_cases = TestSuite()
    home = os.path.dirname(os.path.dirname(__file__))
    for package in pkgutil.iter_modules([f"{home}/blueman"], "blueman."):
        test_cases.addTest(TestImports(package.name))

    assert test_cases.countTestCases() > 0

    return test_cases
Esempio n. 3
0
 def collect_only(self, suite: unittest.TestSuite) -> None:
     t0 = time.time()
     i = 0
     print("Collect {} tests is {:.3f}s".format(suite.countTestCases(),
                                                time.time() - t0))
     print("-" * 50)
     for case in self.fsuite:
         if isnotsuite(case):  # todo remove
             i += 1
             print("{}.{}".format(i, str(case)))
Esempio n. 4
0
def load_tests(*_args):
    test_cases = TestSuite()
    home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
    for package in pkgutil.iter_modules(
        [f"{home}/blueman/{subpath}"],
            f"blueman.{subpath.replace('/', '.')}."):
        test_cases.addTest(TestImports(package.name))

    assert test_cases.countTestCases() > 0

    return test_cases
Esempio n. 5
0
def load_tests(*_args):
    expected_exceptions = {
        "blueman.plugins.mechanism.RfKill": "Hardware kill switch not found",
    }

    test_cases = TestSuite()
    home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
    for package in pkgutil.iter_modules(
        [f"{home}/blueman/{subpath}"],
            f"blueman.{subpath.replace('/', '.')}."):
        test_cases.addTest(
            TestImports(package.name, expected_exceptions.get(package.name)))

    assert test_cases.countTestCases() > 0

    return test_cases
Esempio n. 6
0
def load_tests(*_args):
    expected_exceptions = {
        "blueman.plugins.manager.PulseAudioProfile":
        "Could not load pulseaudio shared library",
    }

    test_cases = TestSuite()
    home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
    for package in pkgutil.iter_modules(
        [f"{home}/blueman/{subpath}"],
            f"blueman.{subpath.replace('/', '.')}."):
        test_cases.addTest(
            TestImports(package.name, expected_exceptions.get(package.name)))

    assert test_cases.countTestCases() > 0

    return test_cases
Esempio n. 7
0
def runtests(rootdir):
    ts = TestSuite()
    tl = TestLoader()
    tr = TextTestRunner(verbosity=2)
    for root, _, files in os.walk(rootdir):
        if not root.endswith("__pycache__"):
            for filename in files:
                filename, ext = os.path.splitext(filename)
                if filename.lower().startswith("test_") and ext.lower() in [
                        ".py", ".pyc", ".pyo"
                ]:
                    module = loadfile(root, filename, ext)
                    if module and module not in cases:
                        tests = tl.loadTestsFromModule(module)
                        ts.addTests(tests)
    print("Total Tests Found %s" % ts.countTestCases())
    tr.run(ts)
Esempio n. 8
0
def run_aiida_db_tests(tests_to_run, verbose=False):
    """
    Run all tests specified in tests_to_run.
    Return the list of test results.
    """
    # Empty test suite that will be populated
    test_suite = TestSuite()

    actually_run_tests = []
    num_tests_expected = 0

    # To avoid adding more than once the same test
    # (e.g. if you type both db and db.xxx)
    found_modulenames = set()

    for test in set(tests_to_run):
        try:
            modulenames = get_db_test_list()[test]
        except KeyError:
            if verbose:
                print >> sys.stderr, "Unknown DB test {}... skipping".format(
                    test)
            continue
        actually_run_tests.append(test)

        for modulename in modulenames:
            if modulename not in found_modulenames:
                test_suite.addTest(test_loader.loadTestsFromName(modulename))
                found_modulenames.add(modulename)

        num_tests_expected = test_suite.countTestCases()

    if verbose:
        print >> sys.stderr, (
            "DB tests that will be run: {} (expecting {} tests)".format(
                ",".join(actually_run_tests), num_tests_expected))

    results = unittest.TextTestRunner(failfast=False).run(test_suite)

    if verbose:
        print "Run tests: {}".format(results.testsRun)

    return results
Esempio n. 9
0
def load_tests(*_args):
    expected_exceptions = {
        "blueman.plugins.applet.GameControllerWakelock":
        "This is not an X11 screen",
        "blueman.plugins.applet.KillSwitch": "Hardware kill switch not found",
        "blueman.plugins.applet.NMDUNSupport": "NM python bindings not found.",
        "blueman.plugins.applet.NMPANSupport": "NM python bindings not found.",
    }

    test_cases = TestSuite()
    home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
    for package in pkgutil.iter_modules(
        [f"{home}/blueman/{subpath}"],
            f"blueman.{subpath.replace('/', '.')}."):
        test_cases.addTest(
            TestImports(package.name, expected_exceptions.get(package.name)))

    assert test_cases.countTestCases() > 0

    return test_cases
Esempio n. 10
0
def run(suite_names, verbose):
    """Run test suites."""
    if verbose > 2:
        verbose = 2

    # Tune in to zero's logs.
    logger = logging.getLogger("zero")
    # Show only warnings with no verbosity, or more if higher.
    set_log_verbosity(logging.WARNING - 10 * verbose, logger)

    # test suite to run
    try:
        test_suites = [TESTS[suite_name] for suite_name in suite_names]
    except KeyError as e:
        click.echo(
            f"Suite name {e} is invalid (use \"suites\" to list available suites)",
            err=True)
        sys.exit()

    suite = TestSuite(test_suites)
    ntests = suite.countTestCases()
    click.echo(f"Running {ntests} tests")
    run_and_exit(suite, verbosity=verbose)