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'])
def bootstrap2(argv): global xmake_status, build_cfg prepare_bootstrap() xmake_inst_dir = inst.get_installation_dir() if len(argv)>1 and argv[1]=='--bootstrap': xmake_status='bootstrap' sys.argv=argv=argv[0:1]+argv[2:] else: if isfile(join(xmake_inst_dir,'.loaded')): log.warning( 'directly using loaded sub level version of xmake') xmake_status='loaded' if xmake_status=='loaded': run(argv) else: log.info( 'bootstrapping xmake...') build_cfg = BuildConfig() (args,_,_) = setup_config(build_cfg, True) log.info("component root is "+build_cfg.component_dir()) log.info( 'build runtime is ' + build_cfg.runtime()) create_gendir(build_cfg) log.start_logfile(join(build_cfg.genroot_dir(),"boot.log")) determine_version_suffix(build_cfg, args.version) # required by xmake version check below if args.use_current_xmake_version: log.warning( 'using actually installed version as requested by option --use-current-xmake-version') run(argv) else: v=determine_xmake_version(build_cfg) if v==None: log.warning( 'no xmake version specified (please maintain file '+XMAKE_VERSION+" or xmake.cfg in project's cfg folder") log.info("default version is "+str(args.default_xmake_version)) if args.default_xmake_version==None: if build_cfg.is_release() or build_cfg.is_milestone(): raise XmakeException('no version specified for xmake for a productive build') else: log.warning( 'using actually installed version') run(argv) else: v=args.default_xmake_version log.warning( 'using explicit default version '+v) if v==None: log.error("do not know any xmake version to use -> exit") sys.exit(2) else: v=find_latest(v) log.info( 'required xmake version is '+v) if v.endswith("-SNAPSHOT"): if build_cfg.is_release() or build_cfg.is_milestone(): log.info("version suffix is "+str(build_cfg.version_suffix())) log.error( 'this is a snapshot version, it cannot be used for release or milestone builds') raise XmakeException('snapshot version specified for xmake for a realease or milestone build') else: log.warning( 'this is a snapshot version, it cannot be used for release builds') l=get_xmake_version(v, build_cfg) if is_existing_file(xmake_loaded): os.remove(xmake_loaded) log.info( 'required xmake version found at '+l) if test_mode: cmd=[sys.executable, join(l,'xmake','bootstrap.py'), '--use-current-xmake-version'] else: cmd=[sys.executable, join(l,'xmake','xmake.py')] log.info( 'starting xmake...') cmd.extend(prepare_args(build_cfg, l,argv[1:])) if build_cfg.component_dir()!=None: os.chdir(build_cfg.component_dir()) flush() log.stop_logfile() rc=subprocess.call(cmd) sys.exit(rc)