<commit_before>import operator

from invoke.util import six, reduce

from spec import Spec, eq_, ok_, raises, assert_raises

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

from _util import load, support_path


@task
def _mytask(ctx):
    six.print_("woo!")

def _func(ctx):
    pass


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

        def can_accept_collections_as_varargs_too(self):
            sub = Collection('sub')
            ns = Collection(sub)
            eq_(ns.collections['sub'], sub)

        def kwargs_act_as_name_args_for_given_objects(self):
            sub = Collection()
            @task
            def task1(ctx):
                pass
            ns = Collection(loltask=task1, notsub=sub)
            eq_(ns['loltask'], task1)
            eq_(ns.collections['notsub'], sub)

        def initial_string_arg_acts_as_name(self):
            sub = Collection('sub')
            ns = Collection(sub)
            eq_(ns.collections['sub'], sub)

        def initial_string_arg_meshes_with_varargs_and_kwargs(self):
            @task
            def task1(ctx):
                pass
            @task
            def task2(ctx):
                pass
            sub = Collection('sub')
            ns = Collection('root', task1, sub, sometask=task2)
            for x, y in (
                (ns.name, 'root'),
                (ns['task1'], task1),
                (ns.collections['sub'], sub),
                (ns['sometask'], task2),
            ):
                eq_(x, y)

        def accepts_load_path_kwarg(self):
            eq_(Collection().loaded_from, None)
            eq_(Collection(loaded_from='a/path').loaded_from, 'a/path')

        def accepts_auto_dash_names_kwarg(self):
            assert Collection().auto_dash_names is True
            assert Collection(auto_dash_names=False).auto_dash_names is False

    class useful_special_methods:
        def _meh(self):
            @task
            def task1(ctx):
                pass
            @task
            def task2(ctx):
                pass
            return Collection('meh', task1=task1, task2=task2)

        def setup(self):
            self.c = self._meh()

        def repr_(self):
            "__repr__"
            eq_(repr(self.c), "<Collection 'meh': task1, task2>")

        def equality_should_be_useful(self):
            eq_(self.c, self._meh())

    class from_module:
        def setup(self):
            self.c = Collection.from_module(load('integration'))

        class parameters:
            def setup(self):
                self.mod = load('integration')
                self.from_module = Collection.from_module

            def name_override(self):
                eq_(self.from_module(self.mod).name, 'integration')
                eq_(
                    self.from_module(self.mod, name='not-integration').name,
                    'not-integration'
                )

            def inline_configuration(self):
                # No configuration given, none gotten
                eq_(self.from_module(self.mod).configuration(), {})
                # Config kwarg given is reflected when config obtained
                coll = self.from_module(self.mod, config={'foo': 'bar'})
                assert coll.configuration() == {'foo': 'bar'}

            def name_and_config_simultaneously(self):
                # Test w/ posargs to enforce ordering, just for safety.
                c = self.from_module(self.mod, 'the name', {'the': 'config'})
                eq_(c.name, 'the name')
                eq_(c.configuration(), {'the': 'config'})

            def auto_dash_names_passed_to_constructor(self):
                # Sanity
                assert self.from_module(self.mod).auto_dash_names is True
                # Test
                coll = self.from_module(self.mod, auto_dash_names=False)
                assert coll.auto_dash_names is False

        def adds_tasks(self):
            assert 'print-foo' in self.c

        def derives_collection_name_from_module_name(self):
            eq_(self.c.name, 'integration')<commit_msg>Add regression test proving #342<commit_after>import operator

from invoke.util import six, reduce

from spec import Spec, eq_, ok_, raises, assert_raises

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

from _util import load, support_path


@task
def _mytask(ctx):
    six.print_("woo!")

def _func(ctx):
    pass


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

        def can_accept_collections_as_varargs_too(self):
            sub = Collection('sub')
            ns = Collection(sub)
            eq_(ns.collections['sub'], sub)

        def kwargs_act_as_name_args_for_given_objects(self):
            sub = Collection()
            @task
            def task1(ctx):
                pass
            ns = Collection(loltask=task1, notsub=sub)
            eq_(ns['loltask'], task1)
            eq_(ns.collections['notsub'], sub)

        def initial_string_arg_acts_as_name(self):
            sub = Collection('sub')
            ns = Collection(sub)
            eq_(ns.collections['sub'], sub)

        def initial_string_arg_meshes_with_varargs_and_kwargs(self):
            @task
            def task1(ctx):
                pass
            @task
            def task2(ctx):
                pass
            sub = Collection('sub')
            ns = Collection('root', task1, sub, sometask=task2)
            for x, y in (
                (ns.name, 'root'),
                (ns['task1'], task1),
                (ns.collections['sub'], sub),
                (ns['sometask'], task2),
            ):
                eq_(x, y)

        def accepts_load_path_kwarg(self):
            eq_(Collection().loaded_from, None)
            eq_(Collection(loaded_from='a/path').loaded_from, 'a/path')

        def accepts_auto_dash_names_kwarg(self):
            assert Collection().auto_dash_names is True
            assert Collection(auto_dash_names=False).auto_dash_names is False

    class useful_special_methods:
        def _meh(self):
            @task
            def task1(ctx):
                pass
            @task
            def task2(ctx):
                pass
            return Collection('meh', task1=task1, task2=task2)

        def setup(self):
            self.c = self._meh()

        def repr_(self):
            "__repr__"
            eq_(repr(self.c), "<Collection 'meh': task1, task2>")

        def equality_should_be_useful(self):
            eq_(self.c, self._meh())

    class from_module:
        def setup(self):
            self.c = Collection.from_module(load('integration'))

        class parameters:
            def setup(self):
                self.mod = load('integration')
                self.from_module = Collection.from_module

            def name_override(self):
                eq_(self.from_module(self.mod).name, 'integration')
                eq_(
                    self.from_module(self.mod, name='not-integration').name,
                    'not-integration'
                )

            def inline_configuration(self):
                # No configuration given, none gotten
                eq_(self.from_module(self.mod).configuration(), {})
                # Config kwarg given is reflected when config obtained
                coll = self.from_module(self.mod, config={'foo': 'bar'})
                assert coll.configuration() == {'foo': 'bar'}

            def name_and_config_simultaneously(self):
                # Test w/ posargs to enforce ordering, just for safety.
                c = self.from_module(self.mod, 'the name', {'the': 'config'})
                eq_(c.name, 'the name')
                eq_(c.configuration(), {'the': 'config'})

            def auto_dash_names_passed_to_constructor(self):
                # Sanity
                assert self.from_module(self.mod).auto_dash_names is True
                # Test
                coll = self.from_module(self.mod, auto_dash_names=False)
                assert coll.auto_dash_names is False

        def adds_tasks(self):
            assert 'print-foo' in self.c

        def derives_collection_name_from_module_name(self):
            eq_(self.c.name, 'integration')

        def works_great_with_subclassing(self):
            class MyCollection(Collection):
                pass
            c = MyCollection.from_module(load('integration'))
            assert isinstance(c, MyCollection)
{'fraction_non_alphanumeric': 0.10116304586350669, 'fraction_numerical': 0.005595786701777485, 'mean_word_length': 1.6983422143280047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1415603', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2464, 'n_words': 555}