Esempio n. 1
0
 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
Esempio n. 2
0
 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 _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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 10
0
 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 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
Esempio n. 14
0
 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
Esempio n. 15
0
 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
Esempio n. 16
0
 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
Esempio n. 17
0
 def _matches(self, item):
     return False if not hasmethod(item, 'valid') else item.valid()
Esempio n. 18
0
 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
Esempio n. 19
0
 def _matches(self, obj):
     return hasmethod(obj, self.method_name)
Esempio n. 20
0
 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
Esempio n. 22
0
 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))
Esempio n. 23
0
 def _matches(self, item):
     if not hasmethod(item, '__len__'):
         return False
     return self.len_matcher.matches(len(item))
Esempio n. 24
0
 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))
Esempio n. 25
0
 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))
Esempio n. 26
0
 def _matches(self, sequence):
     if hasmethod(sequence, '__iter__'):
         for item in sequence:
             if self.element_matcher.matches(item):
                 return True
     return False
Esempio n. 27
0
 def _matches(self, item: Sized) -> bool:
     if not hasmethod(item, "__len__"):
         return False
     return self.len_matcher.matches(len(item))
Esempio n. 28
0
 def _matches(self, dish):
     if not hasmethod(dish, "ingredients"):
         return False
     return all(is_vegan(ingredient) for ingredient in dish.ingredients())
Esempio n. 29
0
 def _matches(self, item: str) -> bool:
     if not hasmethod(item, "startswith"):
         return False
     return item.startswith(self.substring)
Esempio n. 30
0
 def _matches(self, dictionary):
     if hasmethod(dictionary, 'keys'):
         for key in dictionary.keys():
             if self.key_matcher.matches(key):
                 return True
     return False
Esempio n. 31
0
 def _matches(self, sequence):
     if hasmethod(sequence, '__iter__'):
         for item in sequence:
             if self.element_matcher.matches(item):
                 return True
     return False
Esempio n. 32
0
 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
Esempio n. 34
0
 def _matches(self, item):
     if not hasmethod(item, '__len__'):
         return False
     return self.len_matcher.matches(len(item))
Esempio n. 35
0
 def _matches(self, item):
     return False if not hasmethod(item, 'valid') else item.valid()
Esempio n. 36
0
 def _matches(self, item):
     """Test whether item matches."""
     if not hasmethod(item, 'weekday'):
         return False
     return item.weekday() == self.day
Esempio n. 37
0
 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)
Esempio n. 38
0
 def _matches(self, item):
     if not hasmethod(item, "endswith"):
         return False
     return item.endswith(self.substring)
Esempio n. 39
0
 def _matches(self, item):
     """Test whether item matches."""
     if not hasmethod(item, 'weekday'):
         return False
     return item.weekday() == self.day
 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
Esempio n. 43
0
 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
Esempio n. 45
0
 def _matches(self, item: str) -> bool:
     if not hasmethod(item, "find"):
         return False
     return item.find(self.substring) >= 0
Esempio n. 46
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
Esempio n. 47
0
 def _matches(self, item):
     if not hasmethod(item, 'find'):
         return False
     return item.find(self.substring) >= 0
Esempio n. 48
0
 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 value in list(dictionary.values()):
             if self.value_matcher.matches(value):
                 return True
     return False
Esempio n. 50
0
 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
Esempio n. 51
0
 def _matches(self, item):
     if not hasmethod(item, 'find'):
         return False
     return item.find(self.substring) >= 0