Example #1
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(root=support)
        self.vanilla = self.loader.load_collection('decorator')

    def allows_access_to_wrapped_object(self):
        def lolcats():
            pass
        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load_collection('decorator_multi_default')

    def sets_arg_help(self):
        eq_(self.vanilla['punch'].help['why'], 'Motive')

    def sets_arg_kind(self):
        skip()

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla['one_positional'].positional, ['pos'])
        eq_(self.vanilla['two_positionals'].positional, ['pos1', 'pos2'])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla['implicit_positionals'].positional, ['pos1', 'pos2'])
Example #2
0
    class update_path:
        def setup(self):
            self.l = Loader(root=support)

        def does_not_modify_argument(self):
            path = []
            new_path = self.l.update_path(path)
            eq_(path, [])
            assert len(new_path) > 0

        def inserts_self_root_parent_at_front_of_path(self):
            "Inserts self.root at front of path"
            eq_(self.l.update_path([])[0], self.l.root)

        def does_not_insert_if_exists(self):
            "Doesn't insert self.root if it's already in the path"
            new_path = self.l.update_path([self.l.root])
            eq_(len(new_path), 1) # not 2
Example #3
0
    class update_path:
        def setup(self):
            self.l = Loader(root=support)

        def does_not_modify_argument(self):
            path = []
            new_path = self.l.update_path(path)
            eq_(path, [])
            assert len(new_path) > 0

        def inserts_self_root_parent_at_front_of_path(self):
            "Inserts self.root at front of path"
            eq_(self.l.update_path([])[0], self.l.root)

        def adds_to_front_if_exists(self):
            "Inserts self.root at front of path even if it's already elsewhere"
            new_path = self.l.update_path([self.l.root])
            eq_(len(new_path), 2) # lol ?
            eq_(new_path[0], self.l.root)
Example #4
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(root=support)
        self.vanilla = self.loader.load_collection('decorator')

    def allows_access_to_wrapped_object(self):
        dummy = _Dummy()
        eq_(task(dummy).body, dummy)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load_collection('decorator_multi_default')
Example #5
0
 def raises_CollectionNotFound_for_missing_collections(self):
     result = Loader(root=support).find_collection('nope')
Example #6
0
 def defaults_to_tasks_collection(self):
     "defaults to 'tasks' collection"
     result = Loader(root=support + '/implicit/').load_collection()
     eq_(type(result), Collection)
Example #7
0
 def raises_ImportError_if_found_collection_cannot_be_imported(self):
     # Instead of masking with a CollectionNotFound
     Loader(root=support).load_collection('oops')
Example #8
0
 def raises_CollectionNotFound_if_not_found(self):
     Loader(root=support).load_collection('nope')
Example #9
0
File: tasks.py Project: Ivoz/invoke
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(root=support)
        self.vanilla = self.loader.load_collection('decorator')

    def allows_access_to_wrapped_object(self):
        def lolcats():
            pass
        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_multiple_aliases(self):
        eq_(self.vanilla['foo'], self.vanilla['otherbar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load_collection('decorator_multi_default')

    def sets_arg_help(self):
        eq_(self.vanilla['punch'].help['why'], 'Motive')

    def sets_arg_kind(self):
        skip()

    def sets_which_args_are_optional(self):
        eq_(self.vanilla['optional_values'].optional, ('myopt',))

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla['one_positional'].positional, ['pos'])
        eq_(self.vanilla['two_positionals'].positional, ['pos1', 'pos2'])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla['implicit_positionals'].positional, ['pos1', 'pos2'])

    def context_arguments_should_not_appear_in_implicit_positional_list(self):
        @ctask
        def mytask(ctx):
            pass
        eq_(len(mytask.positional), 0)

    def pre_tasks_stored_as_simple_list_of_strings(self):
        @task(pre=['whatever'])
        def func():
            pass
        eq_(func.pre, ['whatever'])

    def allows_star_args_as_shortcut_for_pre(self):
        @task('my', 'pre', 'tasks')
        def func():
            pass
        eq_(func.pre, ('my', 'pre', 'tasks'))

    @raises(TypeError)
    def no_ambiguity_between_star_args_and_pre_kwarg(self):
        @task('lol', 'wut', pre=['no', 'wai'])
        def func():
            pass

    def passes_in_contextualized_kwarg(self):
        @task
        def task1():
            pass
        @task(contextualized=True)
        def task2(ctx):
            pass
        assert not task1.contextualized
        assert task2.contextualized

    def sets_name(self):
        @task(name='foo')
        def bar():
            pass
        eq_(bar.name, 'foo')
Example #10
0
 def exposes_discovery_root(self):
     root = '/tmp/'
     eq_(Loader(root=root).root, root)
Example #11
0
 def setup(self):
     self.loader = Loader(root=support)
     self.vanilla = self.loader.load_collection('decorator')
Example #12
0
class task_(Spec):
    "@task"

    def setup(self):
        self.loader = Loader(root=support)
        self.vanilla = self.loader.load_collection('decorator')

    def allows_access_to_wrapped_object(self):
        def lolcats():
            pass

        eq_(task(lolcats).body, lolcats)

    def allows_alias_specification(self):
        eq_(self.vanilla['foo'], self.vanilla['bar'])

    def allows_multiple_aliases(self):
        eq_(self.vanilla['foo'], self.vanilla['otherbar'])

    def allows_default_specification(self):
        eq_(self.vanilla[''], self.vanilla['biz'])

    @raises(ValueError)
    def raises_ValueError_on_multiple_defaults(self):
        self.loader.load_collection('decorator_multi_default')

    def sets_arg_help(self):
        eq_(self.vanilla['punch'].help['why'], 'Motive')

    def sets_arg_kind(self):
        skip()

    def sets_which_args_are_optional(self):
        eq_(self.vanilla['optional_values'].optional, ('myopt', ))

    def allows_annotating_args_as_positional(self):
        eq_(self.vanilla['one_positional'].positional, ['pos'])
        eq_(self.vanilla['two_positionals'].positional, ['pos1', 'pos2'])

    def when_positional_arg_missing_all_non_default_args_are_positional(self):
        eq_(self.vanilla['implicit_positionals'].positional, ['pos1', 'pos2'])

    def context_arguments_should_not_appear_in_implicit_positional_list(self):
        @ctask
        def mytask(ctx):
            pass

        eq_(len(mytask.positional), 0)

    def pre_tasks_stored_as_simple_list_of_strings(self):
        @task(pre=['whatever'])
        def func():
            pass

        eq_(func.pre, ['whatever'])

    def allows_star_args_as_shortcut_for_pre(self):
        @task('my', 'pre', 'tasks')
        def func():
            pass

        eq_(func.pre, ('my', 'pre', 'tasks'))

    @raises(TypeError)
    def no_ambiguity_between_star_args_and_pre_kwarg(self):
        @task('lol', 'wut', pre=['no', 'wai'])
        def func():
            pass

    def passes_in_contextualized_kwarg(self):
        @task
        def task1():
            pass

        @task(contextualized=True)
        def task2(ctx):
            pass

        assert not task1.contextualized
        assert task2.contextualized

    def sets_name(self):
        @task(name='foo')
        def bar():
            pass

        eq_(bar.name, 'foo')
Example #13
0
 def allows_default_specification(self):
     c = Loader(root=support).load_collection('decorator')
     eq_(c.get(), c.get('biz'))
Example #14
0
 def allows_alias_specification(self):
     c = Loader(root=support).load_collection('decorator')
     eq_(c.get('foo'), c.get('bar'))
Example #15
0
 def setup(self):
     self.l = Loader(root=support)
Example #16
0
 def setup(self):
     self.loader = Loader(start=support)
     self.vanilla = self.loader.load('decorator')
Example #17
0
 def has_a_default_discovery_root(self):
     eq_(Loader().root, os.getcwd())
Example #18
0
File: tasks.py Project: Ivoz/invoke
 def setup(self):
     self.loader = Loader(root=support)
     self.vanilla = self.loader.load_collection('decorator')
Example #19
0
 def returns_collection_object_if_name_found(self):
     result = Loader(root=support).load_collection('foo')
     eq_(type(result), Collection)