def _matches(self, item): if not hasmethod(item, 'lower'): return False low = item.lower() if not hasmethod(low, 'find'): return False return low.find(self.substring.lower()) >= 0
def _matches(self, sequence): if not hasmethod(sequence, '__len__') \ or not hasmethod(sequence, '__iter__'): return False if len(sequence) == 0: return False for item in sequence: if not self.matcher.matches(item): return False return True
def _matching_keys(self, item): key_matches: MutableMapping[K, V] = {} if hasmethod(item, "items"): for key, value in item.items(): if self.key_matcher.matches(key): key_matches[key] = value return key_matches
def _matches(self, item: Mapping[K, V]) -> bool: if hasmethod(item, "items"): for key, value in item.items(): if self.key_matcher.matches( key) and self.value_matcher.matches(value): return True return False
def _matches(self, dictionary): if hasmethod(dictionary, "items"): for key, value in dictionary.items(): if self.key_matcher.matches( key) and self.value_matcher.matches(value): return True return False
def _matches(self, item): if not hasmethod(item, "find"): return False from_index = 0 for substring in self.substrings: from_index = item.find(substring, from_index) if from_index == -1: return False return True
def _matches(self, dictionary): if hasmethod(dictionary, 'keys'): expkeys = self.key_matcher.split(',') for expkey in expkeys: if expkey not in dictionary.keys(): return False return True else: return False
def _matches(self, item): if not hasmethod(item, 'find'): return False from_index = 0 for substring in self.substrings: from_index = item.find(substring, from_index) if from_index == -1: return False return True
def matches(self, sequence, mismatch_description=None): if not hasmethod(sequence, '__iter__'): if mismatch_description: super(IsSequenceContainingInAnyOrder, self) \ .describe_mismatch(sequence, mismatch_description) return False matchsequence = MatchInAnyOrder(self.matchers, mismatch_description) for item in sequence: if not matchsequence.matches(item): return False return matchsequence.isfinished(sequence)
def append_description_of(self, value: Any) -> Description: if not ismock(value) and hasmethod(value, "describe_to"): value.describe_to(self) elif isinstance(value, str): self.append(repr(value)) else: description = str(value) if description[:1] == "<" and description[-1:] == ">": self.append(description) else: self.append("<") self.append(description) self.append(">") return self
def append_description_of(self, value): if hasmethod(value, "describe_to"): value.describe_to(self) elif six.PY3 and isinstance(value, six.text_type): self.append(repr(value)) elif isinstance(value, six.binary_type): self.append_string_in_python_syntax(value) elif isinstance(value, six.text_type): self.append_string_in_python_syntax(value) else: description = str(value) if description[:1] == "<" and description[-1:] == ">": self.append(description) else: self.append("<") self.append(description) self.append(">") return self
def append_description_of(self, value): if not ismock(value) and hasmethod(value, 'describe_to'): value.describe_to(self) elif six.PY3 and isinstance(value, six.text_type): self.append(repr(value)) elif six.PY2 and isinstance(value, six.binary_type): self.append_string_in_python_syntax(value) elif isinstance(value, six.text_type): self.append_string_in_python_syntax(value) else: description = str(value) if description[:1] == '<' and description[-1:] == '>': self.append(description) else: self.append('<') self.append(description) self.append('>') return self
def append_description_of(self, value): if hasmethod(value, 'describe_to'): value.describe_to(self) elif six.PY3 and isinstance(value, six.text_type): self.append(repr(value)) elif isinstance(value, six.binary_type): self.append_string_in_python_syntax(value) elif isinstance(value, six.text_type): self.append_string_in_python_syntax(value) else: description = str(value) if description[:1] == '<' and description[-1:] == '>': self.append(description) else: self.append('<') self.append(description) self.append('>') return self
def _matches(self, item): return False if not hasmethod(item, 'valid') else item.valid()
def _matches(self, dictionary): if hasmethod(dictionary, 'items'): for key, value in dictionary.items(): if self.key_matcher.matches(key) and self.value_matcher.matches(value): return True return False
def _matches(self, obj): return hasmethod(obj, self.method_name)
def _matches(self, item): if not hasmethod(item, 'startswith'): return False return item.startswith(self.substring)
def _matches(self, dictionary): if hasmethod(dictionary, 'values'): for key in dictionary.keys(): if self.key_matcher.matches(key): return isinstance(dictionary[key], dict) return False
def describe_mismatch(self, item, mismatch_description): super(HasLength, self).describe_mismatch(item, mismatch_description) if hasmethod(item, '__len__'): mismatch_description.append_text(' with length of ') \ .append_description_of(len(item))
def _matches(self, item): if not hasmethod(item, '__len__'): return False return self.len_matcher.matches(len(item))
def describe_mismatch(self, item: Sized, mismatch_description: Description) -> None: super(HasLength, self).describe_mismatch(item, mismatch_description) if hasmethod(item, "__len__"): mismatch_description.append_text(" with length of ").append_description_of(len(item))
def _matches(self, sequence): if hasmethod(sequence, '__iter__'): for item in sequence: if self.element_matcher.matches(item): return True return False
def _matches(self, item: Sized) -> bool: if not hasmethod(item, "__len__"): return False return self.len_matcher.matches(len(item))
def _matches(self, dish): if not hasmethod(dish, "ingredients"): return False return all(is_vegan(ingredient) for ingredient in dish.ingredients())
def _matches(self, item: str) -> bool: if not hasmethod(item, "startswith"): return False return item.startswith(self.substring)
def _matches(self, dictionary): if hasmethod(dictionary, 'keys'): for key in dictionary.keys(): if self.key_matcher.matches(key): return True return False
def _matches(self, dictionary): if hasmethod(dictionary, "keys"): for key in dictionary.keys(): if self.key_matcher.matches(key): return True return False
def _matches(self, item): if not hasmethod(item, "weekday"): return False return item.weekday() == self.day
def _matches(self, item): """Test whether item matches.""" if not hasmethod(item, 'weekday'): return False return item.weekday() == self.day
def _matches(self, request): request_body = self._get_value(request) if not isinstance(request_body, basestring) and not hasmethod(request_body, 'find'): return False return self._contains(self.expected, request_body)
def _matches(self, item): if not hasmethod(item, "endswith"): return False return item.endswith(self.substring)
def _matches(self, dictionary): if hasmethod(dictionary, "values"): for value in dictionary.values(): if self.value_matcher.matches(value): return True return False
def _matches(self, item): if not hasmethod(item, 'lower'): return False return item.lower().find(self.substring.lower()) >= 0
def _matches(self, dictionary): if hasmethod(dictionary, 'values'): for value in dictionary.values(): if self.value_matcher.matches(value): return True return False
def _matches(self, item): if not hasmethod(item, "count"): return False self.actual_count = item.count(self.substring) return self.actual_count == self.expected_count
def _matches(self, item: Mapping[Any, V]) -> bool: if hasmethod(item, "values"): for value in item.values(): if self.value_matcher.matches(value): return True return False
def _matches(self, item: str) -> bool: if not hasmethod(item, "find"): return False return item.find(self.substring) >= 0
def _matches(self, item: Mapping[K, Any]) -> bool: if hasmethod(item, "keys"): for key in item.keys(): if self.key_matcher.matches(key): return True return False
def _matches(self, item): if not hasmethod(item, 'find'): return False return item.find(self.substring) >= 0
def _matches(self, dictionary): if hasmethod(dictionary, 'values'): for value in list(dictionary.values()): if self.value_matcher.matches(value): return True return False