describe_to()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
__author__ = "Jon Reid"
2
__copyright__ = "Copyright 2011 hamcrest.org"
3
__license__ = "BSD, see License.txt"
4
5
from hamcrest.core.base_matcher import BaseMatcher
6
7
import six
8
9
class IsEqualIgnoringCase(BaseMatcher):
10
11
    def __init__(self, string):
12
        if not isinstance(string, six.string_types):
13
            raise TypeError('IsEqualIgnoringCase requires string')
14
        self.original_string = string
15
        self.lowered_string = string.lower()
16
17
    def _matches(self, item):
18
        if not isinstance(item, six.string_types):
19
            return False
20
        return self.lowered_string == item.lower()
21
22
    def describe_to(self, description):
23
        description.append_description_of(self.original_string)    \
24
                   .append_text(' ignoring case')
25
26
27
def equal_to_ignoring_case(string):
28
    """Matches if object is a string equal to a given string, ignoring case
29
    differences.
30
31
    :param string: The string to compare against as the expected value.
32
33
    This matcher first checks whether the evaluated object is a string. If so,
34
    it compares it with ``string``, ignoring differences of case.
35
36
    Example::
37
38
        equal_to_ignoring_case("hello world")
39
40
    will match "heLLo WorlD".
41
42
    """
43
    return IsEqualIgnoringCase(string)
44