<commit_before>from spec import Spec, skip, eq_, raises

from invoke.collection import Collection
from invoke.tasks import task, Task


@task
def _mytask():
    print "woo!"


class Collection_(Spec):
    class init:
        "__init__"
        def can_accept_task_varargs(self):
            "can accept tasks as *args"
            @task
            def task1():
                pass
            @task
            def task2():
                pass
            c = Collection(task1, task2)
            assert 'task1' in c
            assert 'task2' in c

    class add_task:
        def setup(self):
            self.c = Collection()

        def associates_given_callable_with_given_name(self):
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def uses_function_name_as_implicit_name(self):
            self.c.add_task(_mytask)
            assert '_mytask' in self.c

        @raises(ValueError)
        def raises_ValueError_if_no_name_and_non_function(self):
            # Can't use a lambda here as they are technically real functions.
            class Callable(object):
                def __call__(self):
                    pass
            self.c.add_task(Task(Callable()))

        def allows_specifying_aliases(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar',))
            eq_(self.c['bar'], _mytask)

        def allows_specifying_multiple_aliases(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar', 'biz'))
            eq_(self.c['bar'], _mytask)
            eq_(self.c['biz'], _mytask)

        def allows_flagging_as_default(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        @raises(ValueError)
        def raises_ValueError_on_multiple_defaults(self):
            self.c.add_task(_mytask, 'foo', default=True)
            self.c.add_task(_mytask, 'bar', default=True)

    class add_collection:
        def adds_collection_as_subcollection_of_self(self):
            skip()

    class get:
        def setup(self):
            self.c = Collection()

        def finds_own_tasks_by_name(self):
            # TODO: duplicates an add_task test above, fix?
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def finds_subcollection_tasks_by_dotted_name(self):
            skip()

        def honors_aliases_in_own_tasks(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar',))
            eq_(self.c['bar'], _mytask)

        def honors_subcollection_aliases(self):
            skip()

        def honors_own_default_task_with_no_args(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        def honors_subcollection_default_tasks_on_subcollection_name(self):
            skip()

        def is_aliased_to_dunder_getitem(self):
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def honors_own_default_task_getitem(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        @raises(ValueError)
        def raises_ValueError_for_no_name_and_no_default(self):
            self.c['']

    class to_contexts:
        def setup(self):
            @task
            def mytask(text, boolean=False, number=5):
                print text
            @task
            def mytask2():
                pass
            self.c = Collection(mytask, mytask2)
            self.contexts = self.c.to_contexts()
            self.context = self.contexts[1]

        def returns_iterable_of_Contexts_corresponding_to_tasks(self):
            eq_(self.context.name, 'mytask')
            eq_(len(self.contexts), 2)

        def allows_flaglike_access_via_flags(self):
            assert '--text' in self.context.flags

        def positional_arglist_preserves_order_given(self):
            @task(positional=('second', 'first'))
            def mytask(first, second, third):
                pass
            c = Collection()
            c.add_task('mytask', mytask)
            ctx = c.to_contexts()[0]
            eq_(ctx.positional_args, [ctx.args['second'], ctx.args['first']])<commit_msg>Fix other failing test.<commit_after>from spec import Spec, skip, eq_, raises

from invoke.collection import Collection
from invoke.tasks import task, Task


@task
def _mytask():
    print "woo!"


class Collection_(Spec):
    class init:
        "__init__"
        def can_accept_task_varargs(self):
            "can accept tasks as *args"
            @task
            def task1():
                pass
            @task
            def task2():
                pass
            c = Collection(task1, task2)
            assert 'task1' in c
            assert 'task2' in c

    class add_task:
        def setup(self):
            self.c = Collection()

        def associates_given_callable_with_given_name(self):
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def uses_function_name_as_implicit_name(self):
            self.c.add_task(_mytask)
            assert '_mytask' in self.c

        @raises(ValueError)
        def raises_ValueError_if_no_name_and_non_function(self):
            # Can't use a lambda here as they are technically real functions.
            class Callable(object):
                def __call__(self):
                    pass
            self.c.add_task(Task(Callable()))

        def allows_specifying_aliases(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar',))
            eq_(self.c['bar'], _mytask)

        def allows_specifying_multiple_aliases(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar', 'biz'))
            eq_(self.c['bar'], _mytask)
            eq_(self.c['biz'], _mytask)

        def allows_flagging_as_default(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        @raises(ValueError)
        def raises_ValueError_on_multiple_defaults(self):
            self.c.add_task(_mytask, 'foo', default=True)
            self.c.add_task(_mytask, 'bar', default=True)

    class add_collection:
        def adds_collection_as_subcollection_of_self(self):
            skip()

    class get:
        def setup(self):
            self.c = Collection()

        def finds_own_tasks_by_name(self):
            # TODO: duplicates an add_task test above, fix?
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def finds_subcollection_tasks_by_dotted_name(self):
            skip()

        def honors_aliases_in_own_tasks(self):
            self.c.add_task(_mytask, 'foo', aliases=('bar',))
            eq_(self.c['bar'], _mytask)

        def honors_subcollection_aliases(self):
            skip()

        def honors_own_default_task_with_no_args(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        def honors_subcollection_default_tasks_on_subcollection_name(self):
            skip()

        def is_aliased_to_dunder_getitem(self):
            self.c.add_task(_mytask, 'foo')
            eq_(self.c['foo'], _mytask)

        def honors_own_default_task_getitem(self):
            self.c.add_task(_mytask, 'foo', default=True)
            eq_(self.c[''], _mytask)

        @raises(ValueError)
        def raises_ValueError_for_no_name_and_no_default(self):
            self.c['']

    class to_contexts:
        def setup(self):
            @task
            def mytask(text, boolean=False, number=5):
                print text
            @task
            def mytask2():
                pass
            self.c = Collection(mytask, mytask2)
            self.contexts = self.c.to_contexts()
            self.context = self.contexts[1]

        def returns_iterable_of_Contexts_corresponding_to_tasks(self):
            eq_(self.context.name, 'mytask')
            eq_(len(self.contexts), 2)

        def allows_flaglike_access_via_flags(self):
            assert '--text' in self.context.flags

        def positional_arglist_preserves_order_given(self):
            @task(positional=('second', 'first'))
            def mytask(first, second, third):
                pass
            c = Collection()
            c.add_task(mytask)
            ctx = c.to_contexts()[0]
            eq_(ctx.positional_args, [ctx.args['second'], ctx.args['first']])
{'fraction_non_alphanumeric': 0.10871624822359072, 'fraction_numerical': 0.0028422548555187117, 'mean_word_length': 2.0160714285714287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6137114', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2584, 'n_words': 481}