Esempio n. 1
0
 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']
Esempio n. 2
0
 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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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
Esempio n. 6
0
    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'
Esempio n. 7
0
 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)
Esempio n. 8
0
 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