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")
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()
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")
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"))
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/", "*"))
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(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()
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()
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()
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()
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"))
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/", "*"))
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")
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")
def test_should_honor_suffix_without_stripping_it_from_module_names( self, _): self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*_tests"))
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/", "*"))
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")
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/", "*"))
def test_should_honor_suffix_without_stripping_it_from_module_names(self, _): self.assertEquals(["reactor_tests"], discover_modules_matching("/path/to/tests/", "*_tests"))