Exemplo n.º 1
0
def test(ctx, pytest_args='', which='adhoc', quiet=False):
    """
    Run the test suite against ad-hoc created infrastructure.
    """
    testenv = getattr(ctx.qabel.testing, which)
    start_servers = testenv.get('start_servers', False)
    pallin = Executor(namespace, ctx.config)
    if start_servers:
        # For correct resolution of pre/post tasks this is needed, a bit ugly but oh well.
        result = pallin.execute(
            ('start', {'background': True, 'quiet': quiet})
        )
        start_servers = result[start]  # only stop them if we actually had to start them
    command_line = ['py.test']
    for app in APPS:
        *_, app = app.split('/')
        app_url = '--{app}-url {url}'.format(app=app, url=testenv[app])
        command_line.append(app_url)
    command_line.append(pytest_args)
    command_line = ' '.join(command_line)
    print_bold(command_line)
    try:
        ctx.run(command_line, pty=True)
    finally:
        if start_servers:
            pallin.execute(('stop', {}))
Exemplo n.º 2
0
 def _call_objs(self, contextualized):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body, contextualized=contextualized)
     t2 = Task(post_body, contextualized=contextualized)
     t3 = Task(Mock(),
         pre=[call(t1, 5, foo='bar')],
         post=[call(t2, 7, biz='baz')],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute('t3')
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     eq_(kwargs, {'foo': 'bar'})
     if contextualized:
         assert isinstance(args[0], Context)
         eq_(args[1], 5)
     else:
         eq_(args, (5,))
     # Post-task asserts
     args, kwargs = post_body.call_args
     eq_(kwargs, {'biz': 'baz'})
     if contextualized:
         assert isinstance(args[0], Context)
         eq_(args[1], 7)
     else:
         eq_(args, (7,))
Exemplo n.º 3
0
 def _call_objs(self, contextualized):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body, contextualized=contextualized)
     t2 = Task(post_body, contextualized=contextualized)
     t3 = Task(
         Mock(),
         pre=[call(t1, 5, foo='bar')],
         post=[call(t2, 7, biz='baz')],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute('t3')
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     eq_(kwargs, {'foo': 'bar'})
     if contextualized:
         assert isinstance(args[0], Context)
         eq_(args[1], 5)
     else:
         eq_(args, (5, ))
     # Post-task asserts
     args, kwargs = post_body.call_args
     eq_(kwargs, {'biz': 'baz'})
     if contextualized:
         assert isinstance(args[0], Context)
         eq_(args[1], 7)
     else:
         eq_(args, (7, ))
Exemplo n.º 4
0
 def default_tasks_called_when_no_tasks_specified(self):
     # NOTE: when no tasks AND no default, Program will print global
     # help. We just won't do anything at all, which is fine for now.
     task = Task(Mock('default-task'))
     coll = Collection()
     coll.add_task(task, name='mytask', default=True)
     executor = Executor(collection=coll)
     executor.execute()
     task.body.assert_called_with()
Exemplo n.º 5
0
 def calls_default_to_empty_args_always(self):
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(), pre=[t1], post=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(('t3', {'something': 'meh'}))
     for body in (pre_body, post_body):
         eq_(body.call_args, tuple())
Exemplo n.º 6
0
 def calls_default_to_empty_args_always(self):
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(), pre=[t1], post=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(('t3', {'something': 'meh'}))
     for body in (pre_body, post_body):
         eq_(body.call_args, tuple())
Exemplo n.º 7
0
 def default_tasks_called_when_no_tasks_specified(self):
     # NOTE: when no tasks AND no default, Program will print global
     # help. We just won't do anything at all, which is fine for now.
     task = Task(Mock('default-task'))
     coll = Collection()
     coll.add_task(task, name='mytask', default=True)
     executor = Executor(collection=coll)
     executor.execute()
     task.body.assert_called_with()
Exemplo n.º 8
0
 def deduping_treats_different_calls_to_same_task_differently(self):
     body = Mock()
     t1 = Task(body)
     pre = [call(t1, 5), call(t1, 7), call(t1, 5)]
     t2 = Task(Mock(), pre=pre)
     c = Collection(t1=t1, t2=t2)
     e = Executor(collection=c)
     e.execute('t2')
     # Does not call the second t1(5)
     body.assert_has_calls([mock_call(5), mock_call(7)])
Exemplo n.º 9
0
 def deduping_treats_different_calls_to_same_task_differently(self):
     body = Mock()
     t1 = Task(body)
     pre = [call(t1, 5), call(t1, 7), call(t1, 5)]
     t2 = Task(Mock(), pre=pre)
     c = Collection(t1=t1, t2=t2)
     e = Executor(collection=c)
     e.execute('t2')
     # Does not call the second t1(5)
     body.assert_has_calls([mock_call(5), mock_call(7)])
Exemplo n.º 10
0
 def calls_default_to_empty_args_always(self):
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(), pre=[t1], post=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(('t3', {'something': 'meh'}))
     for body in (pre_body, post_body):
         args = body.call_args[0]
         eq_(len(args), 1)
         ok_(isinstance(args[0], Context))
Exemplo n.º 11
0
 def default_tasks_called_when_no_tasks_specified(self):
     # NOTE: when no tasks AND no default, Program will print global
     # help. We just won't do anything at all, which is fine for now.
     task = Task(Mock("default-task"))
     coll = Collection()
     coll.add_task(task, name="mytask", default=True)
     executor = Executor(collection=coll)
     executor.execute()
     args = task.body.call_args[0]
     assert isinstance(args[0], Context)
     assert len(args) == 1
Exemplo n.º 12
0
 def default_tasks_called_when_no_tasks_specified(self):
     # NOTE: when no tasks AND no default, Program will print global
     # help. We just won't do anything at all, which is fine for now.
     task = Task(Mock('default-task'))
     coll = Collection()
     coll.add_task(task, name='mytask', default=True)
     executor = Executor(collection=coll)
     executor.execute()
     args = task.body.call_args[0]
     assert isinstance(args[0], Context)
     assert len(args) == 1
Exemplo n.º 13
0
 def calls_default_to_empty_args_always(self):
     dep_body, followup_body = Mock(), Mock()
     t1 = Task(dep_body)
     t2 = Task(followup_body)
     t3 = Task(Mock(), depends_on=[t1], afterwards=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(('t3', {'something': 'meh'}))
     for body in (dep_body, followup_body):
         args = body.call_args[0]
         eq_(len(args), 1)
         ok_(isinstance(args[0], Context))
Exemplo n.º 14
0
 def calls_default_to_empty_args_always(self):
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(), pre=[t1], post=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(('t3', {'something': 'meh'}))
     for body in (pre_body, post_body):
         args = body.call_args[0]
         assert len(args) == 1
         assert isinstance(args[0], Context)
Exemplo n.º 15
0
 def calls_default_to_empty_args_always(self):
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(), pre=[t1], post=[t2])
     e = Executor(collection=Collection(t1=t1, t2=t2, t3=t3))
     e.execute(("t3", {"something": "meh"}))
     for body in (pre_body, post_body):
         args = body.call_args[0]
         assert len(args) == 1
         assert isinstance(args[0], Context)
Exemplo n.º 16
0
 def hands_task_specific_configuration_to_context(self):
     @task
     def mytask(ctx):
         eq_(ctx.my_key, 'value')
     @task
     def othertask(ctx):
         eq_(ctx.my_key, 'othervalue')
     inner1 = Collection('inner1', mytask)
     inner1.configure({'my_key': 'value'})
     inner2 = Collection('inner2', othertask)
     inner2.configure({'my_key': 'othervalue'})
     c = Collection(inner1, inner2)
     e = Executor(collection=c)
     e.execute('inner1.mytask', 'inner2.othertask')
Exemplo n.º 17
0
 def deduping_treats_different_calls_to_same_task_differently(self):
     body = Mock()
     t1 = Task(body)
     pre = [call(t1, 5), call(t1, 7), call(t1, 5)]
     t2 = Task(Mock(), pre=pre)
     c = Collection(t1=t1, t2=t2)
     e = Executor(collection=c)
     e.execute('t2')
     # Does not call the second t1(5)
     param_list = []
     for body_call in body.call_args_list:
         assert isinstance(body_call[0][0], Context)
         param_list.append(body_call[0][1])
     assert set(param_list) == {5, 7}
Exemplo n.º 18
0
 def hands_task_specific_configuration_to_context(self):
     @task
     def mytask(ctx):
         eq_(ctx.my_key, 'value')
     @task
     def othertask(ctx):
         eq_(ctx.my_key, 'othervalue')
     inner1 = Collection('inner1', mytask)
     inner1.configure({'my_key': 'value'})
     inner2 = Collection('inner2', othertask)
     inner2.configure({'my_key': 'othervalue'})
     c = Collection(inner1, inner2)
     e = Executor(collection=c)
     e.execute('inner1.mytask', 'inner2.othertask')
Exemplo n.º 19
0
 def graph_treats_different_calls_to_same_task_differently(self):
     body = Mock()
     t1 = Task(body)
     dep = [call(t1, 5), call(t1, 7), call(t1, 5)]
     t2 = Task(Mock(), depends_on=dep)
     c = Collection(t1=t1, t2=t2)
     e = Executor(collection=c)
     e.execute('t2')
     # Does not call the second t1(5)
     param_list = []
     for body_call in body.call_args_list:
         ok_(isinstance(body_call[0][0], Context))
         param_list.append(body_call[0][1])
     ok_(set(param_list) == set((5, 7)))
Exemplo n.º 20
0
 def deduping_treats_different_calls_to_same_task_differently(self):
     body = Mock()
     t1 = Task(body)
     pre = [call(t1, 5), call(t1, 7), call(t1, 5)]
     t2 = Task(Mock(), pre=pre)
     c = Collection(t1=t1, t2=t2)
     e = Executor(collection=c)
     e.execute("t2")
     # Does not call the second t1(5)
     param_list = []
     for body_call in body.call_args_list:
         assert isinstance(body_call[0][0], Context)
         param_list.append(body_call[0][1])
     assert set(param_list) == {5, 7}
Exemplo n.º 21
0
        def hands_task_specific_configuration_to_context(self):
            @task
            def mytask(c):
                assert c.my_key == "value"

            @task
            def othertask(c):
                assert c.my_key == "othervalue"

            inner1 = Collection("inner1", mytask)
            inner1.configure({"my_key": "value"})
            inner2 = Collection("inner2", othertask)
            inner2.configure({"my_key": "othervalue"})
            c = Collection(inner1, inner2)
            e = Executor(collection=c)
            e.execute("inner1.mytask", "inner2.othertask")
Exemplo n.º 22
0
        def hands_task_specific_configuration_to_context(self):
            @task
            def mytask(c):
                assert c.my_key == "value"

            @task
            def othertask(c):
                assert c.my_key == "othervalue"

            inner1 = Collection("inner1", mytask)
            inner1.configure({"my_key": "value"})
            inner2 = Collection("inner2", othertask)
            inner2.configure({"my_key": "othervalue"})
            c = Collection(inner1, inner2)
            e = Executor(collection=c)
            e.execute("inner1.mytask", "inner2.othertask")
Exemplo n.º 23
0
 def _call_objs(self):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(Mock(),
         pre=[call(t1, 5, foo='bar')],
         post=[call(t2, 7, biz='baz')],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute('t3')
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     assert kwargs == {'foo': 'bar'}
     assert isinstance(args[0], Context)
     assert args[1] == 5
     # Post-task asserts
     args, kwargs = post_body.call_args
     assert kwargs == {'biz': 'baz'}
     assert isinstance(args[0], Context)
     assert args[1] == 7
Exemplo n.º 24
0
 def call_objs_play_well_with_context_args(self):
     # Setup
     dep_body, followup_body = Mock(), Mock()
     t1 = Task(dep_body)
     t2 = Task(followup_body)
     t3 = Task(Mock(),
         depends_on=[call(t1, 5, foo='bar')],
         afterwards=[call(t2, 7, biz='baz')],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute('t3')
     # Dependency asserts
     args, kwargs = dep_body.call_args
     eq_(kwargs, {'foo': 'bar'})
     assert isinstance(args[0], Context)
     eq_(args[1], 5)
     # Followup asserts
     args, kwargs = followup_body.call_args
     eq_(kwargs, {'biz': 'baz'})
     assert isinstance(args[0], Context)
     eq_(args[1], 7)
Exemplo n.º 25
0
 def _call_objs(self):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(
         Mock(),
         pre=[call(t1, 5, foo="bar")],
         post=[call(t2, 7, biz="baz")],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute("t3")
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     assert kwargs == {"foo": "bar"}
     assert isinstance(args[0], Context)
     assert args[1] == 5
     # Post-task asserts
     args, kwargs = post_body.call_args
     assert kwargs == {"biz": "baz"}
     assert isinstance(args[0], Context)
     assert args[1] == 7
Exemplo n.º 26
0
 def _call_objs(self):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(
         Mock(),
         pre=[call(t1, 5, foo='bar')],
         post=[call(t2, 7, biz='baz')],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute('t3')
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     assert kwargs == {'foo': 'bar'}
     assert isinstance(args[0], Context)
     assert args[1] == 5
     # Post-task asserts
     args, kwargs = post_body.call_args
     assert kwargs == {'biz': 'baz'}
     assert isinstance(args[0], Context)
     assert args[1] == 7
Exemplo n.º 27
0
 def _call_objs(self):
     # Setup
     pre_body, post_body = Mock(), Mock()
     t1 = Task(pre_body)
     t2 = Task(post_body)
     t3 = Task(
         Mock(),
         pre=[call(t1, 5, foo="bar")],
         post=[call(t2, 7, biz="baz")],
     )
     c = Collection(t1=t1, t2=t2, t3=t3)
     e = Executor(collection=c)
     e.execute("t3")
     # Pre-task asserts
     args, kwargs = pre_body.call_args
     assert kwargs == {"foo": "bar"}
     assert isinstance(args[0], Context)
     assert args[1] == 5
     # Post-task asserts
     args, kwargs = post_body.call_args
     assert kwargs == {"biz": "baz"}
     assert isinstance(args[0], Context)
     assert args[1] == 7