Exemplo n.º 1
0
def run_tests(tests):
    any_failures = False

    for test_spec in tests:
        test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.'))
        # TODO(aneeshusa): switch back to scandir on Python 3.5+
        tests = sorted(path for path in os.listdir(test_dir)
                       if is_python_script(os.path.join(test_dir, path)))
        for test in tests:
            test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3])
            test_mod = importlib.import_module(test_mod_name)
            if not hasattr(test_mod, 'run'):  # Not a test script
                continue

            try:
                result = test_mod.run()
            except Exception as e:
                message = 'Test \'{}\' raised an exception:'.format(test)
                result = Failure(message, str(e))

            if result.is_success():
                print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message))
            else:
                any_failures = True
                print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message))
                for line in result.output.splitlines():
                    print('         {}'.format(line))

    return 1 if any_failures else 0
Exemplo n.º 2
0
def run_tests(tests):
    any_failures = False

    for test_spec in tests:
        test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.'))

        python_scripts = filter(is_python_script, os.scandir(test_dir))
        tests = sorted([entry.name for entry in python_scripts])

        for test in tests:
            test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3])
            test_mod = importlib.import_module(test_mod_name)
            if not hasattr(test_mod, 'run'):  # Not a test script
                continue

            try:
                result = test_mod.run()
            except Exception as e:
                message = 'Test \'{}\' raised an exception:'.format(test)
                result = Failure(message, str(e))

            if result.is_success():
                print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message))
            else:
                any_failures = True
                print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message))
                for line in result.output.splitlines():
                    print('         {}'.format(line))

    return 1 if any_failures else 0
Exemplo n.º 3
0
def run_tests(tests):
    any_failures = False

    for test_spec in tests:
        test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.'))
        # TODO(aneeshusa): switch back to scandir on Python 3.5+
        tests = sorted(
            path for path in os.listdir(test_dir)
            if is_python_script(os.path.join(test_dir, path))
        )
        for test in tests:
            test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3])
            test_mod = importlib.import_module(test_mod_name)
            if not hasattr(test_mod, 'run'):  # Not a test script
                continue

            try:
                result = test_mod.run()
            except Exception as e:
                message = 'Test \'{}\' raised an exception:'.format(test)
                result = Failure(message, str(e))

            if result.is_success():
                print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message))
            else:
                any_failures = True
                print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message))
                for line in result.output.splitlines():
                    print('         {}'.format(line))

    return 1 if any_failures else 0