|
1
|
|
|
import six |
|
2
|
|
|
from hamcrest.library.text.isequal_ignoring_case import equal_to_ignoring_case |
|
3
|
|
|
|
|
4
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
|
5
|
|
|
import unittest |
|
6
|
|
|
|
|
7
|
|
|
__author__ = "Jon Reid" |
|
8
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
|
9
|
|
|
__license__ = "BSD, see License.txt" |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
matcher = equal_to_ignoring_case('heLLo') |
|
13
|
|
|
|
|
14
|
|
View Code Duplication |
class IsEqualIgnoringCaseTest(MatcherTest): |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def testIgnoresCaseOfCharsInString(self): |
|
17
|
|
|
self.assert_matches('all upper', matcher, 'HELLO') |
|
18
|
|
|
self.assert_matches('all lower', matcher, 'hello') |
|
19
|
|
|
self.assert_matches('mixed up', matcher, 'HelLo') |
|
20
|
|
|
|
|
21
|
|
|
self.assert_does_not_match('no match', matcher, 'bye') |
|
22
|
|
|
|
|
23
|
|
|
def testFailsIfAdditionalWhitespaceIsPresent(self): |
|
24
|
|
|
self.assert_does_not_match('whitespace suffix', matcher, 'heLLo ') |
|
25
|
|
|
self.assert_does_not_match('whitespace prefix', matcher, ' heLLo') |
|
26
|
|
|
|
|
27
|
|
|
def testMatcherCreationRequiresString(self): |
|
28
|
|
|
self.assertRaises(TypeError, equal_to_ignoring_case, 3) |
|
29
|
|
|
|
|
30
|
|
|
def testFailsIfMatchingAgainstNonString(self): |
|
31
|
|
|
self.assert_does_not_match('non-string', matcher, object()) |
|
32
|
|
|
|
|
33
|
|
|
def testCanApplyUnicodeStringToUnicodeMatcher(self): |
|
34
|
|
|
self.assert_matches('unicode-unicode', |
|
35
|
|
|
equal_to_ignoring_case(six.u('heLLo')), six.u('HelLo')) |
|
36
|
|
|
|
|
37
|
|
|
def testCanApplyPlainStringToUnicodeMatcher(self): |
|
38
|
|
|
self.assert_matches('unicode-ascii', |
|
39
|
|
|
equal_to_ignoring_case(six.u('heLLo')), 'HelLo') |
|
40
|
|
|
|
|
41
|
|
|
def testCanApplyUnicodeStringToPlainMatcher(self): |
|
42
|
|
|
self.assert_matches('ascii-unicode', |
|
43
|
|
|
equal_to_ignoring_case('heLLo'), six.u('HelLo')) |
|
44
|
|
|
|
|
45
|
|
|
def testHasAReadableDescription(self): |
|
46
|
|
|
self.assert_description("'heLLo' ignoring case", matcher) |
|
47
|
|
|
|
|
48
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
|
49
|
|
|
self.assert_no_mismatch_description(matcher, 'hello') |
|
50
|
|
|
|
|
51
|
|
|
def testMismatchDescription(self): |
|
52
|
|
|
self.assert_mismatch_description("was 'bad'", matcher, 'bad') |
|
53
|
|
|
|
|
54
|
|
|
def testDescribeMismatch(self): |
|
55
|
|
|
self.assert_describe_mismatch("was 'bad'", matcher, 'bad') |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
if __name__ == '__main__': |
|
59
|
|
|
unittest.main() |
|
60
|
|
|
|