Esempio n. 1
0
def test_regular_exception(m_trace, m_main, mock_cli_command):
    m_main.side_effect = Exception("Boom!")
    invoke = get_invoke(mock_cli_command)

    invoke(Mock(), "mock args")

    m_trace.assert_called_once_with(Exception, m_main.side_effect, None)
Esempio n. 2
0
def test_clean_exit(m_main, mock_cli_command):
    m_main.side_effect = ClickShellCleanExit("Boom!")
    invoke = get_invoke(mock_cli_command)

    with pytest.raises(SystemExit) as exc:
        invoke(Mock(), "mock args")

    assert exc.value.args[0] == 0
Esempio n. 3
0
def test_unclean_exit_specific_code(m_main, mock_cli_command):
    expected_error_code = 127

    m_main.side_effect = ClickShellUncleanExit("Boom!", expected_error_code)
    invoke = get_invoke(mock_cli_command)

    with pytest.raises(SystemExit) as exc:
        invoke(Mock(), "mock args")

    assert exc.value.args[0] == expected_error_code
Esempio n. 4
0
    def test_get_invoke_command(self):
        time_str = str(datetime.now())

        @click.command()
        def test_command():
            click.echo(time_str)
            return time_str

        fun = get_invoke(test_command)

        assert callable(fun)

        ret = fun(None, '')

        # Make sure it returned the correct thing
        assert ret is False
Esempio n. 5
0
    def test_get_invoke_group(self):
        time_str = str(datetime.now())

        @click.group(invoke_without_command=True)
        def main_level():
            pass

        @main_level.group()
        def test_group():
            pass

        @test_group.command()
        def foo():
            click.echo(time_str)
            return time_str

        @test_group.command()
        def bar():
            click.echo('foo')
            return 'foo'

        fun = get_invoke(test_group)

        assert callable(fun)

        # This should be the help function
        ret = fun(None, '')
        assert ret is False

        # Also help
        ret = fun(None, '--help')
        assert ret is False

        # non-existant
        ret = fun(None, 'foobar')
        assert ret is False

        ret = fun(None, 'foo')
        assert ret is False

        ret = fun(None, 'bar')
        assert ret is False
Esempio n. 6
0
def test_click_exception(m_main, mock_cli_command):
    m_main.side_effect = click.ClickException("Boom!")
    invoke = get_invoke(mock_cli_command)

    invoke(Mock(), "mock args")
Esempio n. 7
0
def test_normal_sys_exit(m_main, mock_cli_command):
    m_main.side_effect = SystemExit("Boom!")
    invoke = get_invoke(mock_cli_command)

    invoke(Mock(), "mock args")
Esempio n. 8
0
def test_click_abort(m_main, mock_cli_command):
    m_main.side_effect = click.Abort("Boom!")
    invoke = get_invoke(mock_cli_command)

    invoke(Mock(), "mock args")