def _run_with_kw(self, cmd, *a, **kw): cmd = self.main.sub_cmds[cmd] options, _ = CmdParse(cmd.options).parse([]) options.update(kw) if isinstance(cmd, Command): cmd.execute(options=options, args=a) else: # Doit command cmd.execute(options, a)
def _run_with_kw(self, cmd, *a, **kw): # cyclic import hack from nikola.plugin_categories import Command cmd = self.main.sub_cmds[cmd] options, _ = CmdParse(cmd.options).parse([]) options.update(kw) if isinstance(cmd, Command): cmd.execute(options=options, args=a) else: # Doit command cmd.execute(options, a)
def _run_with_kw(self, cmd, *a, **kw): # cyclic import hack from nikola.plugin_categories import Command cmd = self._doitargs['cmds'].get_plugin(cmd) try: opt = cmd.get_options() except TypeError: cmd = cmd(config=self._config, **self._doitargs) opt = cmd.get_options() options, _ = CmdParse(opt).parse([]) options.update(kw) if isinstance(cmd, Command): cmd.execute(options=options, args=a) else: # Doit command cmd.execute(options, a)
def testPluginBackend(self, depfile_name): mycmd = self.MyCmd(task_loader=ModuleTaskLoader({}), config={'BACKEND': {'j2': 'doit.dependency:JsonDB'}}) params, args = CmdParse(mycmd.get_options()).parse(['--backend', 'j2']) params['dep_file'] = depfile_name mycmd.execute(params, args) assert mycmd.dep_manager.db_class is mycmd._backends['j2']
def testCustomCodec(self, depfile_name): class MyCodec(JSONCodec): pass mycmd = self.MyCmd(task_loader=ModuleTaskLoader({})) params, args = CmdParse(mycmd.get_options()).parse([]) params['codec_cls'] = MyCodec params['dep_file'] = depfile_name mycmd.execute(params, args) assert isinstance(mycmd.dep_manager.backend.codec, MyCodec)
def testCustomChecker(self, depfile_name): class MyChecker(FileChangedChecker): pass mycmd = self.MyCmd(task_loader=ModuleTaskLoader({})) params, args = CmdParse(mycmd.get_options()).parse([]) params['check_file_uptodate'] = MyChecker params['dep_file'] = depfile_name mycmd.execute(params, args) assert isinstance(mycmd.dep_manager.checker, MyChecker)
def test_env_val_bool(self): opt_foo = { 'name': 'foo', 'long': 'foo', 'type': bool, 'env_var': 'FOO', 'default': False, } cmd = CmdParse([CmdOption(opt_foo)]) # get from env os.environ['FOO'] = '1' params, args = cmd.parse([]) assert params['foo'] == True # get from env os.environ['FOO'] = '0' params, args = cmd.parse([]) assert params['foo'] == False
def test_env_val(self): opt_foo = { 'name': 'foo', 'long': 'foo', 'type': str, 'env_var': 'FOO', 'default': 'zero' } cmd = CmdParse([CmdOption(opt_foo)]) # get default params, args = cmd.parse([]) assert params['foo'] == 'zero' # get from env os.environ['FOO'] = 'bar' params2, args2 = cmd.parse([]) assert params2['foo'] == 'bar' # command line has precedence params2, args2 = cmd.parse(['--foo', 'XXX']) assert params2['foo'] == 'XXX'
def cmd(self, request): opt_list = (opt_bool, opt_rare, opt_int, opt_no) options = [CmdOption(o) for o in opt_list] cmd = CmdParse(options) return cmd
def testInvalidChecker(self): mycmd = self.MyCmd(task_loader=ModuleTaskLoader({})) params, args = CmdParse(mycmd.get_options()).parse([]) params['check_file_uptodate'] = 'i dont exist' pytest.raises(InvalidCommand, mycmd.execute, params, args)
def cmd(self, request): opt_list = (opt_bool, opt_rare, opt_int, opt_no, opt_append, opt_choices_desc, opt_choices_nodesc) options = [CmdOption(o) for o in opt_list] cmd = CmdParse(options) return cmd