Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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')
Exemplo n.º 5
0
def test_group_is_disabled_when_it_is_hidden(click_ctx):
    filter = mock.Mock(return_value=True)
    group = kitipy.Group(name='foobar', filters=[filter])
    group.hidden = True

    assert group.is_enabled(click_ctx) == False
    filter.assert_called()
Exemplo n.º 6
0
def test_stack_group_decorator_from_group_object_creates_a_child_transparent_group(
):
    root = kitipy.Group(name='root')
    acme = root.stack_group()(lambda: ())

    assert isinstance(acme, kitipy.StackGroup)
    assert root.transparent_groups == [acme]
Exemplo n.º 7
0
def test_group_decorator_from_group_object_creates_a_child_group():
    root = kitipy.Group(name='root')
    acme = root.group(name='acme', cwd='some/basedir')(lambda _: ())

    assert root.tasks == [acme]
    assert isinstance(acme, kitipy.Group)
    assert acme.name == 'acme'
    assert acme.cwd == 'some/basedir'
Exemplo n.º 8
0
def test_task_decorator_from_group_object_creates_a_new_task_object():
    root = kitipy.Group(name='root')
    task = root.task(name='foo', cwd='some/base/dir')(lambda _: ())

    assert root.tasks == [task]
    assert isinstance(task, kitipy.Task)
    assert task.name == 'foo'
    assert task.cwd == 'some/base/dir'
Exemplo n.º 9
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']
Exemplo n.º 10
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
Exemplo n.º 11
0
def test_group_invoke_updates_the_executor_basedir_using_the_group_cwd(kctx):
    group = kitipy.Group(name='foobar',
                         cwd='some/base/dir',
                         callback=mock.Mock(),
                         invoke_without_command=True)

    click_ctx = click.Context(group, obj=kctx)
    group.invoke(click_ctx)

    kctx.cd.assert_called_with('some/base/dir')
    group.callback.assert_called()
Exemplo n.º 12
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]
Exemplo n.º 13
0
def test_group_is_enabled(click_ctx):
    filter = mock.Mock(return_value=True)
    group = kitipy.Group(name='foobar', filters=[filter])

    assert group.is_enabled(click_ctx) == True
    filter.assert_called()
Exemplo n.º 14
0
def test_group_is_disabled_when_one_of_its_filter_is_negative(click_ctx):
    filter = mock.Mock(return_value=False)
    group = kitipy.Group(name='foobar', filters=[filter])

    assert group.is_enabled(click_ctx) == False
    filter.assert_called()
Exemplo n.º 15
0
def test_group_get_command_cannot_retrieve_transparent_groups_themselves():
    acme = kitipy.Group(name='acme')
    root = kitipy.Group(transparents=[acme])

    click_ctx = click.Context(root)
    assert root.get_command(click_ctx, 'acme') is None
Exemplo n.º 16
0
def test_invoke_disabled_group_raises_an_exception(click_ctx):
    group = kitipy.Group(name='foobar')
    group.hidden = True

    with pytest.raises(kitipy.TaskError):
        group.invoke(click_ctx)