def merge(arg, default, override, args, kwargs): '''Merge all the possible arguments into a tuple and a dictionary. :param arg: The argument's name. :param default: The argument's default value or an instance of _POSITIONAL. :param override: A tuple containing (args, kwargs) given to @arg. :param args: The arguments extracted from the docstring. :param kwargs: The keyword arguments extracted from the docstring.''' opts = [arg] if not isinstance(default, _POSITIONAL): opts = list(ensure_dashes(args or opts)) kwargs.update({'default': default, 'dest': arg}) kwargs.update(action_by_type(default)) else: # positionals can't have a metavar, otherwise the help is screwed # if one really wants the metavar, it can be added with @arg kwargs['metavar'] = None kwargs.update(override[1]) return override[0] or opts, kwargs
def testFunc(self): self.assertEqual(self.result, list(ensure_dashes(self.opts)))
def test_ensure_dashes(opts, result): assert result == list(ensure_dashes(opts))