def _validate_no_extra_named(self, named, spec): if not spec.kwargs: extra = set(named) - set(spec.positional) - set(spec.kwonlyargs) if extra: raise DataError("%s '%s' got unexpected named argument%s %s." % (spec.type, spec.name, plural_or_not(extra), seq2str(sorted(extra))))
def _validate_no_named_only_missing(self, named, spec): defined = set(named) | set(spec.defaults) missing = [arg for arg in spec.kwonlyargs if arg not in defined] if missing: raise DataError("%s '%s' missing named-only argument%s %s." % (spec.type, spec.name, plural_or_not(missing), seq2str(sorted(missing))))
def _get_test_selector_msgs(self): parts = [] for explanation, selector in [('with tags', self.include_tags), ('without tags', self.exclude_tags), ('named', self.include_tests)]: if selector: parts.append(self._format_selector_msg(explanation, selector)) return utils.seq2str(parts, quote='')
def _get_test_selector_msgs(self): parts = [] for explanation, selector in [('with tags', self.include_tags), ('without tags', self.exclude_tags), ('named', self.include_tests)]: if selector: parts.append(self._format_selector_msg(explanation, selector)) return seq2str(parts, quote='')
def __init__(self, type, name, args=(), alias=None, source=None): if type not in self.ALLOWED_TYPES: raise ValueError("Invalid import type '%s'. Should be one of %s." % (type, seq2str(self.ALLOWED_TYPES, lastsep=' or '))) self.type = type self.name = name self.args = args self.alias = alias self.source = source
def __init__(self, type, name, args=(), alias=None, source=None): if type not in self.ALLOWED_TYPES: raise ValueError( "Invalid import type '%s'. Should be one of %s." % (type, seq2str(self.ALLOWED_TYPES, lastsep=' or '))) self.type = type self.name = name self.args = args self.alias = alias self.source = source
def _convert(self, value, explicit_type=True): try: # This is compatible with the enum module in Python 3.4, its # enum34 backport, and the older enum module. `self._enum[value]` # wouldn't work with the old enum module. return getattr(self._enum, value) except AttributeError: members = self._get_members(self._enum) raise ValueError("%s does not have member '%s'. Available: %s" % (self.type_name, value, seq2str(members)))
def validate_type_dict(self, types): # 'return' isn't used for anything yet but it may be shown by Libdoc # in the future. Trying to be forward compatible. names = set(self._argspec.argument_names + ['return']) extra = [t for t in types if t not in names] if extra: raise DataError('Type information given to non-existing ' 'argument%s %s.' % (s(extra), seq2str(sorted(extra)))) return types
def list_should_not_contain_duplicates(self, list_, msg=None): """Fails if any element in the ``list`` is found from it more than once. The default error message lists all the elements that were found from the ``list`` multiple times, but it can be overridden by giving a custom ``msg``. All multiple times found items and their counts are also logged. This keyword works with all iterables that can be converted to a list. The original iterable is never altered. """ if not isinstance(list_, list): list_ = list(list_) dupes = [] for item in list_: if item not in dupes: count = list_.count(item) if count > 1: logger.info("'%s' found %d times." % (item, count)) dupes.append(item) if dupes: raise AssertionError( msg or '%s found multiple times.' % seq2str(dupes))
def list_should_not_contain_duplicates(self, list_, msg=None): """Fails if any element in the ``list`` is found from it more than once. The default error message lists all the elements that were found from the ``list`` multiple times, but it can be overridden by giving a custom ``msg``. All multiple times found items and their counts are also logged. This keyword works with all iterables that can be converted to a list. The original iterable is never altered. """ if not isinstance(list_, list): list_ = list(list_) dupes = [] for item in list_: if item not in dupes: count = list_.count(item) if count > 1: logger.info("'%s' found %d times." % (item, count)) dupes.append(item) if dupes: raise AssertionError(msg or '%s found multiple times.' % seq2str(dupes))
def _verify_format(self, type, format, valid): format = format.upper() if format not in valid: raise DataError("%s must be %s, got '%s'." % (type, seq2str(valid, lastsep=' or '), format)) return format
def _format_selector_msg(self, explanation, selector): if len(selector) == 1 and explanation[-1] == 's': explanation = explanation[:-1] return '%s %s' % (explanation, utils.seq2str(selector, lastsep=' or '))
def _format_selector_msg(self, explanation, selector): if len(selector) == 1 and explanation[-1] == 's': explanation = explanation[:-1] return '%s %s' % (explanation, seq2str(selector, lastsep=' or '))