Exemple #1
0
 def setup(self):
     s = super(Executor_, self)
     s.setup()
     self.task1 = Task(Mock(return_value=7))
     self.task2 = Task(Mock(return_value=10), pre=[self.task1])
     self.task3 = Task(Mock(), pre=[self.task1])
     self.task4 = Task(Mock(return_value=15), post=[self.task1])
     coll = Collection()
     coll.add_task(self.task1, name='task1')
     coll.add_task(self.task2, name='task2')
     coll.add_task(self.task3, name='task3')
     coll.add_task(self.task4, name='task4')
     self.executor = Executor(collection=coll)
Exemple #2
0
 def setup(self):
     # Normal, non-task/collection related Context
     self.vanilla = Context(args=(
         Argument('foo'),
         Argument('bar', help="bar the baz")
     ))
     # Task/Collection generated Context
     # (will expose flags n such)
     @task(help={'otherarg': 'other help'}, optional=['optval'])
     def mytask(ctx, myarg, otherarg, optval):
         pass
     col = Collection(mytask)
     self.tasked = col.to_contexts()[0]
Exemple #3
0
        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
Exemple #4
0
    def setup(self):
        @task(positional=[], iterable=["my_list"], incrementable=["verbose"])
        def my_task(
            c,
            mystring,
            s,
            boolean=False,
            b=False,
            v=False,
            long_name=False,
            true_bool=True,
            _leading_underscore=False,
            trailing_underscore_=False,
            my_list=None,
            verbose=0,
        ):
            pass

        @task(aliases=["my_task27"])
        def my_task2(c):
            pass

        @task(default=True)
        def my_task3(c, mystring):
            pass

        @task
        def my_task4(c, clean=False, browse=False):
            pass

        @task(aliases=["other"], default=True)
        def sub_task(c):
            pass

        sub_coll = Collection("sub_coll", sub_task)
        self.c = Collection(my_task, my_task2, my_task3, my_task4, sub_coll)
Exemple #5
0
        def boolean_is_equivalent_to_tasks_and_or_collections(self):
            # No tasks or colls? Empty/false
            assert not Collection()
            # Tasks but no colls? True
            @task
            def foo(c):
                pass

            assert Collection(foo)
            # Colls but no tasks: True
            assert Collection(foo=Collection(foo))
            # TODO: whether a tree that is not "empty" but has nothing BUT
            # other empty collections in it, should be true or false, is kinda
            # questionable - but since it would result in no usable task names,
            # let's say it's False. (Plus this lets us just use .task_names as
            # the shorthand impl...)
            assert not Collection(foo=Collection())
Exemple #6
0
 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
Exemple #7
0
 def allows_collection_and_config(self):
     coll = Collection()
     conf = Config()
     e = Executor(collection=coll, config=conf)
     assert e.collection is coll
     assert e.config is conf
Exemple #8
0
 def allows_specifying_defaultness(self):
     collection = Collection("foo")
     self.c.add_collection(collection, default=True)
     assert self.c.default == collection.name
Exemple #9
0
 def accepts_load_path_kwarg(self):
     eq_(Collection().loaded_from, None)
     eq_(Collection(loaded_from='a/path').loaded_from, 'a/path')
Exemple #10
0
 def raises_ValueError_if_collection_named_same_as_task(self):
     self.c.add_task(_mytask, 'sub')
     self.c.add_collection(Collection('sub'))
Exemple #11
0
 def ValueError_for_empty_subcol_task_name_and_no_default(self):
     self.c.add_collection(Collection('whatever'))
     self.c['whatever']
Exemple #12
0
 def initial_string_arg_acts_as_name(self):
     sub = Collection("sub")
     ns = Collection(sub)
     assert ns.collections["sub"] == sub
Exemple #13
0
 def raises_ValueError_if_task_added_mirrors_subcollection_name(self):
     self.c.add_collection(Collection('sub'))
     self.c.add_task(_mytask, 'sub')
Exemple #14
0
 def honors_own_default_subcollection(self):
     task = Task(_func, default=True)
     sub = Collection("sub")
     sub.add_task(task, default=True)
     self.c.add_collection(sub, default=True)
     assert self.c[""] is task
Exemple #15
0
 def ValueError_for_empty_subcol_task_name_and_no_default(self):
     self.c.add_collection(Collection("whatever"))
     with raises(ValueError):
         self.c["whatever"]
Exemple #16
0
 def can_accept_collections_as_varargs_too(self):
     sub = Collection("sub")
     ns = Collection(sub)
     assert ns.collections["sub"] == sub
Exemple #17
0
 def finds_subcollection_tasks_by_dotted_name(self):
     sub = Collection("sub")
     sub.add_task(_mytask)
     self.c.add_collection(sub)
     assert self.c["sub._mytask"] is _mytask
Exemple #18
0
 def raises_ValueError_if_collection_named_same_as_task(self):
     self.c.add_task(_mytask, "sub")
     with raises(ValueError):
         self.c.add_collection(Collection("sub"))
Exemple #19
0
 def uses_blank_config_by_default(self):
     e = Executor(collection=Collection())
     assert isinstance(e.config, Config)
Exemple #20
0
 def accepts_load_path_kwarg(self):
     assert Collection().loaded_from is None
     assert Collection(loaded_from="a/path").loaded_from == "a/path"
Exemple #21
0
        # SSH connection closes after contextmanager is finished
        self.command_user.append(self.user)
        self.user = user
        try:
            yield
        finally:
            self.command_user.pop()
            self.close()

context = CliConnection(host=host,user="******")

class Taskset(object):
    """
    NOTE: This should be added to the repo
    """
    def __init__(self, context):
        self.context = context

    def run(self, cmd, echo=True, **kwargs):
        self.context.run(cmd, echo=echo, **kwargs)

class CliTaskset(Taskset):
    @task
    def which_user(self):
        self.run("whoami") # bar
        with self.context.update_config(user="******"):
            self.run("whoami") # root

ns = Collection()
ns.add_collection(Collection.from_class(CliTaskset(context)), name="clitaskset")
Exemple #22
0
 def initial_string_arg_acts_as_name(self):
     sub = Collection('sub')
     ns = Collection(sub)
     eq_(ns.collections['sub'], sub)
Exemple #23
0
 def adds_collection_as_subcollection_of_self(self):
     c2 = Collection('foo')
     self.c.add_collection(c2)
     assert 'foo' in self.c.collections
Exemple #24
0
 def raises_ValueError_if_task_added_mirrors_subcollection_name(self):
     self.c.add_collection(Collection("sub"))
     with raises(ValueError):
         self.c.add_task(_mytask, "sub")
Exemple #25
0
 def finds_subcollection_tasks_by_dotted_name(self):
     sub = Collection('sub')
     sub.add_task(_mytask)
     self.c.add_collection(sub)
     eq_(self.c['sub._mytask'], _mytask)
Exemple #26
0
 def subcollection_paths_may_be_dotted(self):
     leaf = Collection('leaf', self.task)
     leaf.configure({'key': 'leaf-value'})
     middle = Collection('middle', leaf)
     root = Collection('root', middle)
     eq_(root.configuration('middle.leaf.task'), {'key': 'leaf-value'})
Exemple #27
0
 def can_accept_collections_as_varargs_too(self):
     sub = Collection('sub')
     ns = Collection(sub)
     eq_(ns.collections['sub'], sub)
Exemple #28
0
 def adds_collection_as_subcollection_of_self(self):
     c2 = Collection("foo")
     self.c.add_collection(c2)
     assert "foo" in self.c.collections
Exemple #29
0
 def setup(self):
     self.c = Collection()
Exemple #30
0
 def setup(self):
     self.root = Collection()
     self.task = Task(_func, name='task')