def can_clone_into_a_subclass(self): orig = Call(self.task) class MyCall(Call): pass clone = orig.clone(into=MyCall) assert clone == orig assert isinstance(clone, MyCall)
def can_be_given_extra_kwargs_to_clone_with(self): orig = Call(self.task) class MyCall(Call): def __init__(self, *args, **kwargs): self.hooray = kwargs.pop("hooray") super(MyCall, self).__init__(*args, **kwargs) clone = orig.clone(into=MyCall, with_={"hooray": "woo"}) assert clone.hooray == "woo"
def includes_args_and_kwargs(self): call = Call( self.task, args=("posarg1", "posarg2"), # Single-key dict to avoid dict ordering issues kwargs={"kwarg1": "val1"}, ) expected = "<Call 'mytask', args: ('posarg1', 'posarg2'), kwargs: {'kwarg1': 'val1'}>" # noqa assert str(call) == expected
def returns_new_but_equivalent_object(self): orig = Call(self.task) clone = orig.clone() assert clone is not orig assert clone == orig
def creates_a_new_Context_from_given_config(self): conf = Config(defaults={"foo": "bar"}) c = Call(_).make_context(conf) assert isinstance(c, Context) assert c.foo == "bar"
def requires_config_argument(self): with raises(TypeError): Call(_).make_context()
def skips_aka_if_explicit_name_same_as_task_name(self): call = Call(self.task, called_as="mytask") assert str(call) == "<Call 'mytask', args: (), kwargs: {}>"
def includes_aka_if_explicit_name_given(self): call = Call(self.task, called_as="notmytask") expected = "<Call 'mytask' (called as: 'notmytask'), args: (), kwargs: {}>" # noqa assert str(call) == expected
def is_first_posarg(self): assert Call(_).task is _
def may_be_given(self): assert Call(_, kwargs={"foo": "bar"}).kwargs == {"foo": "bar"}
def defaults_to_empty_dict(self): assert Call(_).kwargs == dict()
def may_be_given(self): assert Call(_, args=(1, 2, 3)).args == (1, 2, 3)
def defaults_to_empty_tuple(self): assert Call(_).args == tuple()
def may_be_given(self): assert Call(_, called_as="foo").called_as == "foo"
def defaults_to_None(self): assert Call(_).called_as is None
def includes_task_name(self): call = Call(self.task) assert str(call) == "<Call 'mytask', args: (), kwargs: {}>"
def is_required(self): with raises(TypeError): Call()