substringmatcher.py 695 B

1234567891011121314151617181920
  1. __author__ = "Jon Reid"
  2. __copyright__ = "Copyright 2011 hamcrest.org"
  3. __license__ = "BSD, see License.txt"
  4. from hamcrest.core.base_matcher import BaseMatcher
  5. import six
  6. class SubstringMatcher(BaseMatcher):
  7. def __init__(self, substring):
  8. if not isinstance(substring, six.string_types):
  9. raise TypeError(self.__class__.__name__ + ' requires string')
  10. self.substring = substring
  11. def describe_to(self, description):
  12. description.append_text('a string ') \
  13. .append_text(self.relationship()) \
  14. .append_text(' ') \
  15. .append_description_of(self.substring)