def list_kind_triggers_append_instead_of_overwrite(self): # TODO: when put this way it makes the API look pretty strange; # maybe a sign we should switch to explicit setter methods # (selected on kind, perhaps) instead of using an implicit setter a = Argument('mylist', kind=list) assert a.value == [] a.value = 'val1' assert a.value == ['val1'] a.value = 'val2' assert a.value == ['val1', 'val2']
def list_kind_triggers_append_instead_of_overwrite(self): # TODO: when put this way it makes the API look pretty strange; # maybe a sign we should switch to explicit setter methods # (selected on kind, perhaps) instead of using an implicit setter a = Argument("mylist", kind=list) assert a.value == [] a.value = "val1" assert a.value == ["val1"] a.value = "val2" assert a.value == ["val1", "val2"]
def incrementable_True_triggers_increment_of_default(self): a = Argument('verbose', kind=int, default=0, incrementable=True) assert a.value == 0 # NOTE: parser currently just goes "Argument.takes_value is false? # Gonna stuff True/False in there." So this looks pretty silly out # of context (as with list-types above.) a.value = True assert a.value == 1 for _ in range(4): a.value = True assert a.value == 5
def incrementable_True_triggers_increment_of_default(self): a = Argument("verbose", kind=int, default=0, incrementable=True) assert a.value == 0 # NOTE: parser currently just goes "Argument.takes_value is false? # Gonna stuff True/False in there." So this looks pretty silly out # of context (as with list-types above.) a.value = True assert a.value == 1 for _ in range(4): a.value = True assert a.value == 5
def hosts_flag_still_triggers_parameterization(self): body = Mock(pre=[], post=[]) coll = Collection(mytask=InvokeTask(body)) hosts = Argument(name="hosts") hosts.value = "host1,host2,host3" core_args = ParseResult([ParserContext(args=[hosts])]) Executor(coll, core=core_args).execute("mytask") assert body.call_count == 3
def _get_executor(hosts_flag=None, hosts_kwarg=None, post=None, remainder=""): post_tasks = [] if post is not None: post_tasks.append(post) hosts = Argument(name="hosts") if hosts_flag is not None: hosts.value = hosts_flag core_args = ParseResult([ParserContext(args=[hosts])]) core_args.remainder = remainder task = Mock(pre=[], post=[]) coll = Collection(mytask=Task(task, post=post_tasks, hosts=hosts_kwarg)) return task, Executor(coll, core=core_args)
def _get_executor(hosts_flag=None, hosts_kwarg=None, post=None, remainder=""): post_tasks = [] if post is not None: post_tasks.append(post) hosts = Argument(name="hosts") if hosts_flag is not None: hosts.value = hosts_flag core_args = ParseResult([ParserContext(args=[hosts])]) core_args.remainder = remainder body = Mock(pre=[], post=[]) task = Task(body, post=post_tasks, hosts=hosts_kwarg) coll = Collection(mytask=task) return body, Executor(coll, core=core_args)
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument('a') a.value = 'foo' eq_(a.raw_value, 'foo')
def transformed_appears_as_dot_value_with_original_as_raw_value(self): "transformed, modified value is .value, original is .raw_value" a = Argument('a', kind=int) a.value = '5' assert a.value == 5 assert a.raw_value == '5'
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument('a', kind=str) a.value = 'foo' assert a.value == 'foo'
def non_list_kind_tests_for_None_value(self): arg = Argument("a") assert not arg.got_value arg.value = "something" assert arg.got_value
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument("a", kind=str) a.value = "foo" eq_(a.value, "foo")
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument('a') a.value = 'foo' assert a.raw_value == 'foo'
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument("a") a.value = "foo" assert a.raw_value == "foo"
def list_kind_test_for_empty_list_value(self): arg = Argument("a", kind=list) assert not arg.got_value arg.value = "append-me" assert arg.got_value
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument('a', kind=str) a.value = 'foo' eq_(a.value, 'foo')
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument("a") a.value = "foo" eq_(a.raw_value, "foo")
def transformed_appears_as_dot_value_with_original_as_raw_value(self): "transformed, modified value is .value, original is .raw_value" a = Argument("a", kind=int) a.value = "5" eq_(a.value, 5) eq_(a.raw_value, "5")
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument("a", kind=str) a.value = "foo" assert a.value == "foo"