Пример #1
0
def test_group_get_command_looks_for_the_given_command_in_transparent_groups():
    foo = kitipy.Task(name='foo')
    acme = kitipy.Group(name='acme', tasks=[foo])
    root = kitipy.Group(name='root', transparents=[acme])

    click_ctx = click.Context(root)
    assert root.get_command(click_ctx, 'foo') == foo
Пример #2
0
def test_task_is_disabled_when_it_is_hidden(click_ctx):
    filter = mock.Mock(return_value=True)
    task = kitipy.Task(name='foobar', filters=[filter])
    task.hidden = True

    assert task.is_enabled(click_ctx) == False
    filter.assert_called()
Пример #3
0
def test_group_list_commands_looks_for_commands_in_transparent_groups():
    foo = kitipy.Task(name='foo')
    bar = kitipy.Task(name='bar')
    foobar = kitipy.Task(name='foobar', filters=[lambda _: False])
    acme = kitipy.Group(name='acme', tasks=[foo])
    plop = kitipy.Group(name='plop', tasks=[bar, foobar])

    ktp = kitipy.Task(name='ktp')
    baz = click.Command(name='baz')
    knp = kitipy.Task(name='knp', filters=[lambda _: False])

    root = kitipy.Group(commands={'baz': baz},
                        tasks=[ktp, knp],
                        transparents=[acme, plop])

    click_ctx = click.Context(root)
    assert root.list_commands(click_ctx) == ['bar', 'baz', 'foo', 'ktp']
Пример #4
0
def test_group_get_command_fails_to_find_disabled_tasks_from_transparent_group(
):
    foo = kitipy.Task(name='foo', filters=[lambda _: False])
    acme = kitipy.Group(tasks=[foo])
    root = kitipy.Group(name='root', transparents=[acme])

    click_ctx = click.Context(root)
    assert root.get_command(click_ctx, 'foo') is None
Пример #5
0
def test_group_get_command_still_retrieves_usual_commands():
    foo = kitipy.Task(name='foo')
    bar = click.Command(name='bar')
    root = kitipy.Group(commands={'bar': bar}, tasks=[foo])

    click_ctx = click.Context(root)
    assert root.get_command(click_ctx, 'foo') is not None
    assert root.get_command(click_ctx, 'bar') is not None
Пример #6
0
def test_task_invoke_calls_the_task_callback(kctx):
    task = kitipy.Task(name='foobar')
    task.callback = mock.Mock()

    click_ctx = click.Context(task, obj=kctx)

    task.invoke(click_ctx)

    task.callback.assert_called()
Пример #7
0
def test_group_list_command_raises_an_exception_if_the_name_of_a_command_and_of_a_task_from_a_transparent_group_collides(
):
    foo = kitipy.Task(name='foo')
    acme = kitipy.Group(name='acme', tasks=[foo])
    root = kitipy.Group(tasks=[foo], transparents=[acme])

    click_ctx = click.Context(root)
    with pytest.raises(RuntimeError):
        root.list_commands(click_ctx)
Пример #8
0
def test_group_get_command_raises_an_exception_if_the_name_of_tasks_from_two_transparent_groups_collides(
):
    foo = kitipy.Task(name='foo')
    acme = kitipy.Group(name='acme', tasks=[foo])
    plop = kitipy.Group(name='plop', tasks=[foo])

    root = kitipy.Group(transparents=[acme, plop])

    click_ctx = click.Context(root)
    with pytest.raises(RuntimeError):
        root.get_command(click_ctx, 'foo')
Пример #9
0
def test_group_merging_adds_source_commands_and_transparent_groups():
    src_foo = kitipy.Task(name='foo')
    src_bar = click.Command(name='bar')
    src_baz = kitipy.Group(name='baz')
    src_acme = kitipy.Group(name='acme', tasks=[src_baz])
    src = kitipy.Group(commands={'bar': src_bar},
                       tasks=[src_foo],
                       transparents=[src_acme])

    dest_first = kitipy.Task(name='first')
    dest = kitipy.Group(tasks=[dest_first])
    dest.merge(src)

    expected = [
        'bar',
        'baz',
        'first',
        'foo',
    ]
    assert dest.list_commands(click_ctx) == expected
    assert dest.transparent_groups == [src_acme]
Пример #10
0
def test_task_invoke_updates_the_executor_basedir_using_the_task_cwd(
        click_ctx, kctx):
    task = kitipy.Task(name='foobar', cwd='some/base/dir')
    task.invoke(click_ctx)

    kctx.cd.assert_called_with('some/base/dir')
Пример #11
0
def test_invoke_disabled_task_raises_an_exception(click_ctx):
    task = kitipy.Task(name='foobar')
    task.hidden = True

    with pytest.raises(kitipy.TaskError):
        task.invoke(click_ctx)
Пример #12
0
def test_task_is_enabled(click_ctx):
    filter = mock.Mock(return_value=True)
    task = kitipy.Task(name='foobar', filters=[filter])

    assert task.is_enabled(click_ctx) == True
    filter.assert_called()
Пример #13
0
def test_task_is_disabled_when_one_of_its_filter_is_negative(click_ctx):
    filter = mock.Mock(return_value=False)
    task = kitipy.Task(name='foobar', filters=[filter])

    assert task.is_enabled(click_ctx) == False
    filter.assert_called()