예제 #1
0
    def test_glob_should_return_list_with_single_module_when_directory_contains_package(self):
        when(os).walk("spam").thenReturn([("spam", ["eggs"], []),
                                         ("spam/eggs", [], ["__init__.py"])])

        self.assertEquals(["eggs"], discover_modules_matching("spam", "*"))

        verify(os).walk("spam")
예제 #2
0
def execute_tests_matching(runner_generator,
                           logger,
                           test_source,
                           file_glob,
                           test_method_prefix=None):
    output_log_file = StringIO()
    try:
        if "stream" in runner_generator.func_code.co_varnames:
            runner_generator = partial(runner_generator,
                                       stream=output_log_file)
    except AttributeError:  # not a function, maybe a class?
        try:
            if "stream" in runner_generator.__init__.func_code.co_varnames:
                runner_generator = partial(runner_generator,
                                           stream=output_log_file)
        except Exception:
            pass

    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        loader = unittest.defaultTestLoader
        if test_method_prefix:
            loader.testMethodPrefix = test_method_prefix
        tests = loader.loadTestsFromNames(test_modules)
        result = _instrument_runner(
            runner_generator, logger,
            _create_runner(runner_generator)).run(tests)
        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #3
0
    def test_glob_should_return_list_with_single_module_when_directory_contains_package(self):
        when(os).walk("spam").thenReturn([("spam", ["eggs"], []),
                                         ("spam/eggs", [], ["__init__.py"])])

        self.assertEquals(["eggs"], discover_modules_matching("spam", "*"))

        verify(os).walk("spam")
예제 #4
0
 def test_should_only_match_py_files_regardless_of_glob(self):
     when(os).walk("pet_shop").thenReturn([("pet_shop", [],
                                            ["parrot.txt", "parrot.py", "parrot.pyc", "parrot.py~", "slug.py"])])
     expected_result = ["parrot"]
     actual_result = discover_modules_matching("pet_shop", "*parrot*")
     self.assertEquals(set(expected_result), set(actual_result))
     verify(os).walk("pet_shop")
예제 #5
0
    def test_should_honor_suffix_without_stripping_it_from_module_names(self):
        when(pybuilder.utils).discover_files_matching(any(), any()).thenReturn(
            ['/path/to/tests/reactor_tests.py'])

        self.assertEquals(["reactor_tests"],
                          discover_modules_matching("/path/to/tests/",
                                                    "*_tests"))
예제 #6
0
    def test_should_not_eat_first_character_of_modules_when_source_path_ends_with_slash(
            self):
        when(pybuilder.utils).discover_files_matching(any(), any()).thenReturn(
            ['/path/to/tests/reactor_tests.py'])

        self.assertEquals(["reactor_tests"],
                          discover_modules_matching("/path/to/tests/", "*"))
예제 #7
0
 def test_should_only_match_py_files_regardless_of_glob(self):
     when(os).walk("pet_shop").thenReturn([("pet_shop", [],
                                            ["parrot.txt", "parrot.py", "parrot.pyc", "parrot.py~", "slug.py"])])
     expected_result = ["parrot"]
     actual_result = discover_modules_matching("pet_shop", "*parrot*")
     self.assertEquals(set(expected_result), set(actual_result))
     verify(os).walk("pet_shop")
예제 #8
0
def execute_tests_matching(logger, test_source, module_glob):
    test_module_names = discover_modules_matching(test_source, module_glob)
    test_modules = import_modules(test_module_names)

    test_collector = TestCollector()

    for test_module in test_modules:
        test_collector.collect_tests(test_module)

    test_runner = TestRunner()
    test_runner.add_test_run_listener(TestListener(logger))
    return test_runner.run_tests(test_collector.test_suite)
def execute_tests_matching(logger, test_source, module_glob):
    test_module_names = discover_modules_matching(test_source, module_glob)
    test_modules = import_modules(test_module_names)

    test_collector = TestCollector()

    for test_module in test_modules:
        test_collector.collect_tests(test_module)

    test_runner = TestRunner()
    test_runner.add_test_run_listener(TestListener(logger))
    return test_runner.run_tests(test_collector.test_suite)
예제 #10
0
def execute_tests_matching(runner_generator, logger, test_source, file_glob, test_method_prefix=None):
    output_log_file = StringIO()
    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        loader = unittest.defaultTestLoader
        if test_method_prefix:
            loader.testMethodPrefix = test_method_prefix
        tests = loader.loadTestsFromNames(test_modules)
        result = _instrument_runner(runner_generator, logger, _create_runner(runner_generator, output_log_file)).run(
            tests)
        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #11
0
def execute_tests_matching(runner_generator, logger, test_source, file_glob, test_method_prefix=None):
    output_log_file = StringIO()
    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        loader = unittest.defaultTestLoader
        if test_method_prefix:
            loader.testMethodPrefix = test_method_prefix
        tests = loader.loadTestsFromNames(test_modules)
        result = _instrument_runner(runner_generator, logger, _create_runner(runner_generator, output_log_file)).run(
            tests)
        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #12
0
def execute_tests_matching(test_source, file_glob, test_method_prefix=None):
    output_log_file = StringIO()

    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        loader = unittest.defaultTestLoader
        if test_method_prefix:
            loader.testMethodPrefix = test_method_prefix
        tests = loader.loadTestsFromNames(test_modules)
        result = TestNameAwareTextTestRunner(stream=output_log_file).run(tests)
        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #13
0
def execute_tests_matching(tools,
                           runner_generator,
                           logger,
                           test_source,
                           file_glob,
                           test_method_prefix=None,
                           remote_debug=0):
    output_log_file = StringIO()
    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        runner = _instrument_runner(
            runner_generator, logger,
            _create_runner(runner_generator, output_log_file))

        try:
            proc, pipe = start_unittest_tool(tools,
                                             test_modules,
                                             test_method_prefix,
                                             logging=remote_debug)
            try:
                pipe.register_remote(runner)
                pipe.register_remote_type(unittest.result.TestResult)
                tests = pipe.get_exposed("unittest_tests")
                result = runner.run(tests)
            except PipeShutdownError:
                pass
            finally:
                try:
                    pipe.close()
                finally:
                    try:
                        proc.join()
                    finally:
                        if sys.version_info[:2] >= (3, 7):
                            proc.close()

            remote_closed_cause = pipe.remote_close_cause()
            if remote_closed_cause is not None:
                raise remote_closed_cause
        finally:
            del tool_logger.handlers[:]

        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #14
0
def execute_tests_matching(runner_generator, logger, test_source, file_glob, test_method_prefix=None):
    output_log_file = StringIO()
    try:
        if "stream" in runner_generator.func_code.co_varnames:
            runner_generator = partial(runner_generator, stream=output_log_file)
    except AttributeError:  # not a function, maybe a class?
        try:
            if "stream" in runner_generator.__init__.func_code.co_varnames:
                runner_generator = partial(runner_generator, stream=output_log_file)
        except Exception:
            pass

    try:
        test_modules = discover_modules_matching(test_source, file_glob)
        loader = unittest.defaultTestLoader
        if test_method_prefix:
            loader.testMethodPrefix = test_method_prefix
        tests = loader.loadTestsFromNames(test_modules)
        result = _instrument_runner(runner_generator, logger, _create_runner(runner_generator)).run(tests)
        return result, output_log_file.getvalue()
    finally:
        output_log_file.close()
예제 #15
0
    def test_should_honor_suffix_without_stripping_it_from_module_names(self):
        when(pybuilder.utils).discover_files_matching(any(), any()).thenReturn(['/path/to/tests/reactor_tests.py'])

        self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*_tests"))
예제 #16
0
    def test_should_not_eat_first_character_of_modules_when_source_path_ends_with_slash(self):
        when(pybuilder.utils).discover_files_matching(any(), any()).thenReturn(['/path/to/tests/reactor_tests.py'])

        self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*"))
예제 #17
0
 def test_should_only_match_py_files_regardless_of_glob(self, walk):
     expected_result = ["parrot"]
     actual_result = discover_modules_matching("pet_shop", "*parrot*")
     self.assertEquals(set(expected_result), set(actual_result))
     walk.assert_called_with("pet_shop")
예제 #18
0
    def test_glob_should_return_list_with_single_module_when_directory_contains_package(self, walk):
        self.assertEquals(["eggs"], discover_modules_matching("spam", "*"))

        walk.assert_called_with("spam")
예제 #19
0
 def test_should_honor_suffix_without_stripping_it_from_module_names(
         self, _):
     self.assertEquals(["reactor_tests"],
                       discover_modules_matching("/path/to/tests/",
                                                 "*_tests"))
예제 #20
0
 def test_should_not_eat_first_character_of_modules_when_source_path_ends_with_slash(
         self, _):
     self.assertEquals(["reactor_tests"],
                       discover_modules_matching("/path/to/tests/", "*"))
예제 #21
0
    def test_glob_should_return_list_with_single_module_when_directory_contains_package(
            self, walk):
        self.assertEquals(["eggs"], discover_modules_matching("spam", "*"))

        walk.assert_called_with("spam")
예제 #22
0
 def test_should_only_match_py_files_regardless_of_glob(self, walk):
     expected_result = ["parrot"]
     actual_result = discover_modules_matching("pet_shop", "*parrot*")
     self.assertEquals(set(expected_result), set(actual_result))
     walk.assert_called_with("pet_shop")
예제 #23
0
 def test_should_not_eat_first_character_of_modules_when_source_path_ends_with_slash(self, _):
     self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*"))
예제 #24
0
 def test_should_honor_suffix_without_stripping_it_from_module_names(self, _):
     self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*_tests"))