Пример #1
0
 def test_hardcoded_tasks(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=FakeLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell': 'zsh', 'hardcode_tasks': True}, [])
     got = output.getvalue()
     assert 't1' in got
Пример #2
0
    def test_zsh_arg_line(self):
        opt1 = CmdOption({'name': 'o1', 'default': '', 'help': 'my desc'})
        assert '' == TabCompletion._zsh_arg_line(opt1)

        opt2 = CmdOption({
            'name': 'o2',
            'default': '',
            'help': 'my desc',
            'short': 's'
        })
        assert "'-s[my desc]' \\" == TabCompletion._zsh_arg_line(opt2)

        opt3 = CmdOption({
            'name': 'o3',
            'default': '',
            'help': 'my desc',
            'long': 'lll'
        })
        assert "'--lll[my desc]' \\" == TabCompletion._zsh_arg_line(opt3)

        opt4 = CmdOption({
            'name': 'o4',
            'default': '',
            'help': 'my desc [b]a',
            'short': 's',
            'long': 'lll'
        })
        assert ("'(-s|--lll)'{-s,--lll}'[my desc [b\]a]' \\" ==
                TabCompletion._zsh_arg_line(opt4))
Пример #3
0
 def test_cmds_with_params(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=DodoTaskLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell': 'zsh', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert "tabcompletion: generate script" in got
Пример #4
0
 def test_hardcoded_tasks(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=FakeLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell':'zsh', 'hardcode_tasks': True}, [])
     got = output.getvalue()
     assert 't1' in got
Пример #5
0
 def test_cmds_with_params(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=DodoTaskLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell':'zsh', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert "tabcompletion: generate script" in got
Пример #6
0
 def test_with_dodo__dinamic_tasks(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=DodoTaskLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell': 'bash', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert 'dodof' in got
     assert 't1' not in got
     assert 'tabcompletion' in got
Пример #7
0
 def test_with_dodo__dinamic_tasks(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=DodoTaskLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell':'bash', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert 'dodof' in got
     assert 't1' not in got
     assert 'tabcompletion' in got
Пример #8
0
 def test_cmd_takes_file_args(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=FakeLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell': 'bash', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert """help)
         COMPREPLY=( $(compgen -W "${tasks} ${sub_cmds}" -- $cur) )
         return 0""" in got
     assert """tabcompletion)
         COMPREPLY=( $(compgen -f -- $cur) )
         return 0""" in got
Пример #9
0
 def test_cmd_takes_file_args(self, doit_app):
     output = StringIO()
     cmd = TabCompletion(task_loader=FakeLoader(), outstream=output)
     cmd.doit_app = doit_app
     cmd.execute({'shell':'bash', 'hardcode_tasks': False}, [])
     got = output.getvalue()
     assert """help)
         COMPREPLY=( $(compgen -W "${tasks} ${sub_cmds}" -- $cur) )
         return 0"""  in got
     assert """tabcompletion)
         COMPREPLY=( $(compgen -f -- $cur) )
         return 0"""  in got
Пример #10
0
    def test_cmd_arg_list(self):
        no_args = TabCompletion._zsh_arg_list(Command())
        assert "'*::task:(($tasks))'" not in no_args
        assert "'::cmd:(($commands))'" not in no_args

        class CmdTakeTasks(Command):
            doc_usage = '[TASK ...]'
        with_task_args = TabCompletion._zsh_arg_list(CmdTakeTasks())
        assert "'*::task:(($tasks))'" in with_task_args
        assert "'::cmd:(($commands))'" not in with_task_args

        class CmdTakeCommands(Command):
            doc_usage = '[COMMAND ...]'
        with_cmd_args = TabCompletion._zsh_arg_list(CmdTakeCommands())
        assert "'*::task:(($tasks))'" not in with_cmd_args
        assert "'::cmd:(($commands))'" in with_cmd_args
Пример #11
0
    def test_zsh_arg_line(self):
        opt1 = CmdOption({'name':'o1', 'default':'', 'help':'my desc'})
        assert '' == TabCompletion._zsh_arg_line(opt1)

        opt2 = CmdOption({'name':'o2', 'default':'', 'help':'my desc',
                          'short':'s'})
        assert "'-s[my desc]' \\" == TabCompletion._zsh_arg_line(opt2)

        opt3 = CmdOption({'name':'o3', 'default':'', 'help':'my desc',
                          'long':'lll'})
        assert "'--lll[my desc]' \\" == TabCompletion._zsh_arg_line(opt3)

        opt4 = CmdOption({'name':'o4', 'default':'', 'help':'my desc [b]a',
                          'short':'s', 'long':'lll'})
        assert ("'(-s|--lll)'{-s,--lll}'[my desc [b\]a]' \\" ==
                TabCompletion._zsh_arg_line(opt4))
Пример #12
0
    def test_zsh_arg_line(self):
        opt1 = CmdOption({'name': 'o1', 'default': '', 'help': 'my desc'})
        assert '' == TabCompletion._zsh_arg_line(opt1)

        opt2 = CmdOption({
            'name': 'o2',
            'default': '',
            'help': 'my desc',
            'short': 's'
        })
        assert '"-s[my desc]" \\' == TabCompletion._zsh_arg_line(opt2)

        opt3 = CmdOption({
            'name': 'o3',
            'default': '',
            'help': 'my desc',
            'long': 'lll'
        })
        assert '"--lll[my desc]" \\' == TabCompletion._zsh_arg_line(opt3)

        opt4 = CmdOption({
            'name': 'o4',
            'default': '',
            'help': 'my desc [b]a',
            'short': 's',
            'long': 'lll'
        })
        assert ('"(-s|--lll)"{-s,--lll}"[my desc [b\]a]" \\' ==
                TabCompletion._zsh_arg_line(opt4))

        # escaping `"` test
        opt5 = CmdOption({
            'name': 'o5',
            'default': '',
            'help': '''my "des'c [b]a''',
            'short': 's',
            'long': 'lll'
        })
        assert ('''"(-s|--lll)"{-s,--lll}"[my \\"des'c [b\]a]" \\''' ==
                TabCompletion._zsh_arg_line(opt5))
Пример #13
0
    def test_zsh_arg_line(self):
        opt1 = CmdOption({'name':'o1', 'default':'', 'help':'my desc'})
        assert '' == TabCompletion._zsh_arg_line(opt1)

        opt2 = CmdOption({'name':'o2', 'default':'', 'help':'my desc',
                          'short':'s'})
        assert '"-s[my desc]" \\' == TabCompletion._zsh_arg_line(opt2)

        opt3 = CmdOption({'name':'o3', 'default':'', 'help':'my desc',
                          'long':'lll'})
        assert '"--lll[my desc]" \\' == TabCompletion._zsh_arg_line(opt3)

        opt4 = CmdOption({'name':'o4', 'default':'', 'help':'my desc [b]a',
                          'short':'s', 'long':'lll'})
        assert ('"(-s|--lll)"{-s,--lll}"[my desc [b\]a]" \\' ==
                TabCompletion._zsh_arg_line(opt4))

        # escaping `"` test
        opt5 = CmdOption({'name':'o5', 'default':'',
                          'help':'''my "des'c [b]a''',
                          'short':'s', 'long':'lll'})
        assert ('''"(-s|--lll)"{-s,--lll}"[my \\"des'c [b\]a]" \\''' ==
                TabCompletion._zsh_arg_line(opt5))
Пример #14
0
def test_invalid_shell_option(doit_app):
    cmd = TabCompletion()
    pytest.raises(InvalidCommand, cmd.execute, {
        'shell': 'another_shell',
        'hardcode_tasks': False
    }, [])
Пример #15
0
def doit_app(request):
    app = DoitMain()
    app.sub_cmds['tabcompletion'] = TabCompletion()
    app.sub_cmds['help'] = Help()
    return app