def test_task_dependencies_with_post_definition_injections_custom_names(self): import pybuilder.reactor with patch("pybuilder.reactor.Task"): @task def task1(): pass @task @depends(task1) def task2(): pass @task("task_3") @depends(task1) @dependents(task2) def task3(): pass module1 = ModuleType("mock_module_one") module1.task1 = task1 module1.task2 = task2 module2 = ModuleType("mock_module_two") module2.task3 = task3 self.reactor.collect_tasks_and_actions_and_initializers(module1) pybuilder.reactor.Task.assert_has_calls([call("task1", task1, [], ''), call("task2", task2, [TaskDependency(task1)], '')]) self.reactor.collect_tasks_and_actions_and_initializers(module2) pybuilder.reactor.Task.assert_has_calls([call("task_3", task3, [TaskDependency(task1)], '')]) self.execution_manager.register_late_task_dependencies.assert_has_calls( [call({}), call({"task2": [TaskDependency("task_3")]})])
def test_list_all_covered_modules_duplicate(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') with patch.dict('sys.modules', module_a=module_a_val, module_b=module_b_val): with patch(import_patch) as import_func: returned_modules = _list_all_covered_modules(MagicMock(), ['module_a', 'module_b', 'module_a'], []) self.assertEquals([module_a_val, module_b_val], returned_modules) import_func.assert_not_called()
def test_should_return_rev_and_travis_info_when_count_travis(self): environ_get = patch("pybuilder.vcs.os.environ.get").start() environ_get.return_value = "456" self.execute_command.side_effect = [(1, "", ""), # not git (0, "", ""), # is svn (0, "123", "any-stderr")] travis = count_travis() if "123" not in travis or "456" not in travis: self.assertEquals(False, True)
def test_list_all_covered_modules_load(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') with patch.dict('sys.modules', module_a=module_a_val): with patch(import_patch) as import_func: import_func.return_value = module_b_val returned_modules = _list_all_covered_modules(MagicMock(), ['module_a', 'module_b'], []) self.assertEquals([module_a_val, module_b_val], returned_modules) import_func.assert_called_once_with('module_b')
def test_should_return_rev_and_travis_info_when_count_travis(self): environ_get = patch("pybuilder.vcs.os.environ.get").start() environ_get.return_value = "456" self.execute_command.side_effect = [ (1, "", ""), # not git (0, "", ""), # is svn (0, "123", "any-stderr") ] travis = count_travis() if "123" not in travis or "456" not in travis: self.assertEqual(False, True)
def test_list_all_covered_modules_exclusions(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') logger = MagicMock() with patch.dict('sys.modules', module_a=module_a_val, module_b=module_b_val): with patch(import_patch) as import_func: returned_modules = _list_all_covered_modules(logger, ['module_a', 'module_b', 'module_c'], ['module_c']) self.assertEquals([module_a_val, module_b_val], returned_modules) import_func.assert_not_called() logger.debug.assert_called_with("Module '%s' was excluded", 'module_c')
def test_list_all_covered_modules_all_loaded(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') with patch.dict('sys.modules', module_a=module_a_val, module_b=module_b_val): with patch(import_patch) as import_func: returned_modules = _list_all_covered_modules( MagicMock(), ['module_a', 'module_b'], []) self.assertEquals([module_a_val, module_b_val], returned_modules) import_func.assert_not_called()
def test_list_all_covered_modules_not_imported(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') with patch.dict('sys.modules', module_a=module_a_val): with patch(import_patch) as import_func: import_func.return_value = module_b_val returned_modules, non_imported_modules = _list_all_covered_modules(MagicMock(), ['module_a', 'module_b'], [], False) self.assertEquals([module_a_val, module_b_val], returned_modules) self.assertEquals([module_b_val.__name__], non_imported_modules) import_func.assert_called_once_with('module_b')
def test_list_all_covered_modules_exclusions(self): module_a_val = MagicMock(__name__='module_a', __file__='module_a.py') module_b_val = MagicMock(__name__='module_b', __file__='module_b.py') logger = MagicMock() with patch.dict('sys.modules', module_a=module_a_val, module_b=module_b_val): with patch(import_patch) as import_func: returned_modules, non_imported_modules = _list_all_covered_modules(logger, ['module_a', 'module_b', 'module_c'], ['module_c'], True) self.assertEquals([module_a_val, module_b_val], returned_modules) import_func.assert_not_called() logger.debug.assert_called_with("Module '%s' was excluded", 'module_c')
def test_task_dependencies(self): import pybuilder.reactor with patch("pybuilder.reactor.Task"): @task def task1(): pass @task @depends(task1) def task2(): pass @task def task3(): pass @task @depends(optional(task3)) @dependents("task6") def task4(): pass @task @dependents("task6", optional(task3)) def task5(): pass @task @depends(task1, optional(task2)) def task6(): pass module = ModuleType("mock_module") module.task1 = task1 module.task2 = task2 module.task3 = task3 module.task4 = task4 module.task5 = task5 module.task6 = task6 self.reactor.collect_tasks_and_actions_and_initializers(module) pybuilder.reactor.Task.assert_has_calls([call("task1", task1, [], ''), call("task2", task2, [TaskDependency(task1)], ''), call("task3", task3, [TaskDependency(task5, True)], ''), call("task4", task4, [TaskDependency(task3, True)], ''), call("task5", task5, [], ''), call("task6", task6, [TaskDependency(task1), TaskDependency(task2, True), TaskDependency(task4), TaskDependency(task5)], '')])
def test_task_dependencies_with_post_definition_injections_custom_names( self): import pybuilder.reactor with patch("pybuilder.reactor.Task"): @task def task1(): pass @task @depends(task1) def task2(): pass @task("task_3") @depends(task1) @dependents(task2) def task3(): pass module1 = ModuleType("mock_module_one") module1.task1 = task1 module1.task2 = task2 module2 = ModuleType("mock_module_two") module2.task3 = task3 self.reactor.collect_project_annotations(module1) pybuilder.reactor.Task.assert_has_calls([ call("task1", task1, [], ''), call("task2", task2, [TaskDependency(task1)], '') ]) self.reactor.collect_project_annotations(module2) pybuilder.reactor.Task.assert_has_calls( [call("task_3", task3, [TaskDependency(task1)], '')]) self.execution_manager.register_late_task_dependencies.assert_has_calls( [call({}), call({"task2": [TaskDependency("task_3")]})])
def setUp(self): self.project = Project('basedir') self.os_patcher = patch("pybuilder.ci_server_interaction.os") self.mock_os = self.os_patcher.start()
def setUp(self): self.execute_command = patch("pybuilder.vcs.execute_command_and_capture_output").start()
def setUp(self): self.execute_command = patch( "pybuilder.vcs.execute_command_and_capture_output").start()