def test_dictvalues(dict_): """Test the dictvalues() function, which returns an iterator of a dictionary's values and also works with simpledict() class instances. """ values = dictvalues(dict_) # dictvalues() should not return lists, only iterators assert not isinstance(values, list) # compare with reference sequence from dict method assert all(map(is_, values, dict_.values())) # and check that iterator is exhausted with pytest.raises(StopIteration): next(values)
def args(self): """Iterate the Keyword's argument spec in Robot's Dynamic API style, usable by Test Libraries' ``.get_keyword_arguments()`` method. """ # First look for custom override args list: if self.func.args: for arg in self.func.args: yield arg return # Then fall back to the Keyword function's implicit argspec # generated by Test Library's @keyword decorator: argspec = self.func.argspec posargs = argspec.args[1:] defaults = argspec.defaults if defaults: for arg, defaults_index in zip( posargs, range(-len(posargs), 0) ): try: default = defaults[defaults_index] except IndexError: yield arg else: yield '%s=%s' % (arg, default) else: for arg in posargs: yield arg if argspec.varargs: yield '*' + argspec.varargs if argspec.keywords: yield '**' + argspec.keywords # if the Library has any session handlers or context handlers # with activated auto_explicit option # then always provide **kwargs # to support explicit <session>= and <context>= switching # for single Keyword calls: elif any(hcls.meta.auto_explicit for hcls in dictvalues(self.libinstance.session_handlers)) \ or any(getattr(hcls, 'auto_explicit', False) for hcls in self.context_handlers): yield '**options'
def args(self): """Iterate the Keyword's argument spec in Robot's Dynamic API style, usable by Test Libraries' ``.get_keyword_arguments()`` method. """ # First look for custom override args list: if self.func.args: for arg in self.func.args: yield arg return # Then fall back to the Keyword function's implicit argspec # generated by Test Library's @keyword decorator: argspec = self.func.argspec posargs = argspec.args[1:] defaults = argspec.defaults if defaults: for arg, defaults_index in zip(posargs, range(-len(posargs), 0)): try: default = defaults[defaults_index] except IndexError: yield arg else: yield '%s=%s' % (arg, default) else: for arg in posargs: yield arg if argspec.varargs: yield '*' + argspec.varargs if argspec.keywords: yield '**' + argspec.keywords # if the Library has any session handlers or context handlers # with activated auto_explicit option # then always provide **kwargs # to support explicit <session>= and <context>= switching # for single Keyword calls: elif any(hcls.meta.auto_explicit for hcls in dictvalues(self.libinstance.session_handlers)) \ or any(getattr(hcls, 'auto_explicit', False) for hcls in self.context_handlers): yield '**options'