You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

isequal_ignoring_case.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 IsEqualIgnoringCase(BaseMatcher):
  7. def __init__(self, string):
  8. if not isinstance(string, six.string_types):
  9. raise TypeError('IsEqualIgnoringCase requires string')
  10. self.original_string = string
  11. self.lowered_string = string.lower()
  12. def _matches(self, item):
  13. if not isinstance(item, six.string_types):
  14. return False
  15. return self.lowered_string == item.lower()
  16. def describe_to(self, description):
  17. description.append_description_of(self.original_string) \
  18. .append_text(' ignoring case')
  19. def equal_to_ignoring_case(string):
  20. """Matches if object is a string equal to a given string, ignoring case
  21. differences.
  22. :param string: The string to compare against as the expected value.
  23. This matcher first checks whether the evaluated object is a string. If so,
  24. it compares it with ``string``, ignoring differences of case.
  25. Example::
  26. equal_to_ignoring_case("hello world")
  27. will match "heLLo WorlD".
  28. """
  29. return IsEqualIgnoringCase(string)