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 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 _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 non_bool_implies_value_needed(self): assert Argument(name='a', kind=int).takes_value
def is_optional(self): Argument(name='a') Argument(name='b', kind=int)
def shows_positionalness(self): eq_(str(Argument('name', positional=True)), "<Argument: name*>")
def casts_by_default(self): a = Argument("a", kind=int) a.set_value("5") eq_(a.value, 5)
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument('a', kind=str) a.value = 'foo' eq_(a.value, 'foo')
def casts_by_default(self): a = Argument("a", kind=int) a.set_value("5") assert a.value == 5
def can_take_Argument_instance(self): a = Argument(names=('foo', )) self.c.add_arg(a) assert self.c.args['foo'] is a
def setup(self): self.c = Context(args=( Argument('foo'), Argument(names=('bar', 'biz')), Argument('baz', attr_name='wat'), ))
def args_show_as_repr(self): eq_(str(Context('bar', args=[Argument('arg1')])), "<parser/Context 'bar': {'arg1': <Argument: arg1>}>")
def _assert_order(self, name_tuples, expected_flag_order): ctx = Context(args=[Argument(names=x) for x in name_tuples]) return eq_(ctx.help_tuples(), [ctx.help_for(x) for x in expected_flag_order])
def casts_by_default(self): a = Argument('a', kind=int) a.set_value('5') assert a.value == 5
def may_validate_on_set(self): Argument('a', kind=int).value = 'five'
def is_normalized_to_a_tuple(self): ok_(isinstance(Argument(names=('a', 'b')).names, tuple))
def True_by_default(self): assert Argument(name='a').takes_value
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 False_if_kind_is_bool(self): assert not Argument(name='-b', kind=bool).takes_value
def allows_setting_value_without_casting(self): a = Argument('a', kind=int) a.set_value('5', cast=False) eq_(a.value, '5')
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument('a') a.value = 'foo' eq_(a.raw_value, 'foo')
def untransformed_appears_as_dot_value(self): "untransformed, appears as .value" a = Argument("a", kind=str) a.value = "foo" eq_(a.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 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 just_aliases_dunder_str(self): a = Argument(names=('name', 'name2')) eq_(str(a), repr(a))
def returns_default_if_not_set(self): a = Argument('a', default=25) eq_(a.value, 25)
def defaults_to_str(self): eq_(Argument('a').kind, str)
def is_None_when_no_value_was_actually_seen(self): a = Argument('a', kind=int) eq_(a.raw_value, None)
def bool_implies_no_value_needed(self): assert not Argument(name='a', kind=bool).takes_value
def casts_by_default(self): a = Argument('a', kind=int) a.set_value('5') eq_(a.value, 5)
def returns_tuple_of_all_names(self): eq_(Argument(names=('--foo', '-b')).names, ('--foo', '-b')) eq_(Argument(name='--foo').names, ('--foo', ))
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument("a") a.value = "foo" assert a.raw_value == "foo"
def may_take_name_arg(self): assert '-b' in Argument(name='-b').names
def must_get_at_least_one_name(self): Argument()
def default_arg_is_name_not_names(self): assert 'b' in Argument('b').names
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 can_declare_positional(self): eq_(Argument(name='foo', positional=True).positional, True)
def positional_is_False_by_default(self): eq_(Argument(name='foo').positional, False)
def can_set_attr_name_to_control_name_attr(self): a = Argument('foo', attr_name='bar') eq_(a.name, 'bar') # not 'foo'
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument("a") a.value = "foo" eq_(a.raw_value, "foo")
def shows_useful_info(self): eq_(str(Argument(names=('name', 'nick1', 'nick2'))), "<Argument: %s (%s)>" % ('name', 'nick1, nick2'))
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 does_not_show_nickname_parens_if_no_nicknames(self): eq_(str(Argument('name')), "<Argument: name>")
def allows_setting_value_without_casting(self): a = Argument("a", kind=int) a.set_value("5", cast=False) eq_(a.value, "5")
def available_as_dot_raw_value(self): "available as .raw_value" a = Argument('a') a.value = 'foo' assert a.raw_value == 'foo'