def test_setup_tool_cfg(self, os_mock, Tools_mock, ConfiguredTool_mock, log_mock): # Prepares mocks def info(text): pass # print text # for debug only def existing_file(f): return True log_mock.info = info log_mock.error = info log_mock.warning = info prelude.XmakeException = info prelude.is_existing_file = existing_file buildConfig = BuildConfig() buildConfig.cfg_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples')) buildConfig.component_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples')) tools = Tools_mock() tools.is_declared_tool = lambda tid: False if tid != 'msvc' else True buildConfig._tools = tools # Runs test prelude.setup_tool_cfg(buildConfig) # Asserts assert (ConfiguredTool_mock.call_count > 0)
def stubBuildConfig(cfg_dir, component_dir): # template to create buildConfig in test cases cfg = BuildConfig() cfg._runtime = "linux" cfg._tools = Tools() cfg._tools.import_tools_dir=cfg.import_tools_dir cfg._tools.runtime=cfg.runtime cfg.cfg_dir = MagicMock(return_value=cfg_dir) cfg.component_dir = MagicMock(return_value=component_dir) return cfg
def _test_tag_image(self,version,forced,docker_mock): def docker(args,handler=None,dir=None,echo=True,home=None): if len(args) and '-v' in args: handler("Docker version "+version+", build ab77bde/"+version) docker_mock.docker=MagicMock(side_effect=docker) def tag_name(build_cfg,gid,aid,tmp=False): return "tag_name" docker_mock.tag_name=MagicMock(side_effect=tag_name) cfg = BuildConfig() cfg._runtime = "linux" cfg.cfg_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples')) cfg.component_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples','docker')) d=dockerbuild.build(cfg) d.tag_image(True) docker_mock.tag_image.assert_called_once_with(None, "tag_name", forced)
def test_monitoring(self, walk_mock, logGuessLevel_mock): wait=0.01 build_cfg = BuildConfig() build_cfg.cfg_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples')) build_cfg.component_dir = MagicMock(return_value=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'samples')) testResult={'detected':False, 'notify_caller':Event()} def mocked_walk(path, visit, arg): arg[1]['change']=True walk_mock.side_effect=mocked_walk def mocked__logGuessLevel(msg, prefix=None): if msg==log._MonitoringWorker.MESSAGE_ALIVE.format(wait): testResult['detected']=True testResult['notify_caller'].set() logGuessLevel_mock.side_effect=mocked__logGuessLevel log.logging_monitoring_enable(build_cfg, wait) testResult['notify_caller'].wait(60) # should not wait so much... maximum value and in this case, should fail in the assert below log._logging_monitoring=None assert(testResult['detected'])