1
|
|
|
import six |
2
|
|
|
from hamcrest.library.text.isequal_ignoring_whitespace import * |
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_whitespace('Hello World how\n are we? ') |
13
|
|
|
|
14
|
|
View Code Duplication |
class IsEqualIgnoringWhiteSpaceTest(MatcherTest): |
|
|
|
|
15
|
|
|
|
16
|
|
|
def testPassesIfWordsAreSameButWhitespaceDiffers(self): |
17
|
|
|
self.assert_matches('less whitespace', |
18
|
|
|
matcher, 'Hello World how are we?') |
19
|
|
|
self.assert_matches('more whitespace', |
20
|
|
|
matcher, ' Hello World how are \n\n\twe?') |
21
|
|
|
|
22
|
|
|
def testFailsIfTextOtherThanWhitespaceDiffers(self): |
23
|
|
|
self.assert_does_not_match('wrong word', |
24
|
|
|
matcher, 'Hello PLANET how are we?') |
25
|
|
|
self.assert_does_not_match('incomplete', |
26
|
|
|
matcher, 'Hello World how are we') |
27
|
|
|
|
28
|
|
|
def testFailsIfWhitespaceIsAddedOrRemovedInMidWord(self): |
29
|
|
|
self.assert_does_not_match('need whitespace between Hello and World', |
30
|
|
|
matcher, 'HelloWorld how are we?') |
31
|
|
|
self.assert_does_not_match('wrong whitespace within World', |
32
|
|
|
matcher, 'Hello Wo rld how are we?') |
33
|
|
|
|
34
|
|
|
def testMatcherCreationRequiresString(self): |
35
|
|
|
self.assertRaises(TypeError, equal_to_ignoring_whitespace, 3) |
36
|
|
|
|
37
|
|
|
def testFailsIfMatchingAgainstNonString(self): |
38
|
|
|
self.assert_does_not_match('non-string', matcher, object()) |
39
|
|
|
|
40
|
|
|
def testCanApplyUnicodeStringToUnicodeMatcher(self): |
41
|
|
|
self.assert_matches('unicode-unicode', |
42
|
|
|
equal_to_ignoring_whitespace(six.u('foo\nbar')), |
43
|
|
|
six.u('foo bar')) |
44
|
|
|
|
45
|
|
|
def testCanApplyPlainStringToUnicodeMatcher(self): |
46
|
|
|
self.assert_matches('unicode-ascii', |
47
|
|
|
equal_to_ignoring_whitespace(six.u('foo\nbar')), |
48
|
|
|
'foo bar') |
49
|
|
|
|
50
|
|
|
def testCanApplyUnicodeStringToPlainMatcher(self): |
51
|
|
|
self.assert_matches('ascii-unicode', |
52
|
|
|
equal_to_ignoring_whitespace('foo\n bar'), |
53
|
|
|
six.u('foo bar')) |
54
|
|
|
|
55
|
|
|
def testDescribesItselfAsIgnoringWhiteSpace(self): |
56
|
|
|
self.assert_description("'foo\\nbar' ignoring whitespace", |
57
|
|
|
equal_to_ignoring_whitespace('foo\nbar')) |
58
|
|
|
|
59
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
60
|
|
|
self.assert_no_mismatch_description( |
61
|
|
|
equal_to_ignoring_whitespace('foo\nbar'), 'foo bar') |
62
|
|
|
|
63
|
|
|
def testMismatchDescription(self): |
64
|
|
|
self.assert_mismatch_description("was 'bad'", matcher, 'bad') |
65
|
|
|
|
66
|
|
|
def testDescribeMismatch(self): |
67
|
|
|
self.assert_describe_mismatch("was 'bad'", matcher, 'bad') |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
if __name__ == '__main__': |
71
|
|
|
unittest.main() |
72
|
|
|
|