Code Duplication    Length = 42-54 lines in 4 locations

tests/hamcrest_unit_test/text/isequal_ignoring_whitespace_test.py 1 location

@@ 14-67 (lines=54) @@
11
12
matcher = equal_to_ignoring_whitespace('Hello World   how\n are we? ')
13
14
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__':

tests/hamcrest_unit_test/text/stringendswith_test.py 1 location

@@ 16-62 (lines=47) @@
13
EXCERPT = 'EXCERPT'
14
matcher = ends_with(EXCERPT)
15
16
class StringEndsWithTest(MatcherTest):
17
18
    def testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring(self):
19
        self.assert_does_not_match('excerpt at beginning',
20
                                   matcher, EXCERPT + 'END')
21
        self.assert_matches('excerpt at end', matcher, 'START' + EXCERPT)
22
        self.assert_does_not_match('excerpt in middle',
23
                                   matcher, 'START' + EXCERPT + 'END')
24
        self.assert_matches('excerpt repeated', matcher, EXCERPT + EXCERPT)
25
26
        self.assert_does_not_match('excerpt not in string',
27
                                   matcher, 'whatever')
28
        self.assert_does_not_match('only part of excerpt is at end of string',
29
                                   matcher, EXCERPT[1:])
30
31
    def testEvaluatesToTrueIfArgumentIsEqualToSubstring(self):
32
        self.assert_matches('excerpt is entire string', matcher, EXCERPT)
33
34
    def testMatcherCreationRequiresString(self):
35
        self.assertRaises(TypeError, ends_with, 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
                            ends_with(six.u('baz')), six.u('foo bar baz'))
43
44
    def testCanApplyPlainStringToUnicodeMatcher(self):
45
        self.assert_matches('unicode-ascii',
46
                            ends_with(six.u('baz')), 'foo bar baz')
47
48
    def testCanApplyUnicodeStringToPlainMatcher(self):
49
        self.assert_matches('ascii-unicode',
50
                            ends_with(six.u('baz')), six.u('foo bar baz'))
51
52
    def testHasAReadableDescription(self):
53
        self.assert_description("a string ending with 'EXCERPT'", matcher)
54
55
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
56
        self.assert_no_mismatch_description(matcher, EXCERPT)
57
58
    def testMismatchDescription(self):
59
        self.assert_mismatch_description("was 'bad'", matcher, 'bad')
60
61
    def testDescribeMismatch(self):
62
        self.assert_describe_mismatch("was 'bad'", matcher, 'bad')
63
64
65
if __name__ == '__main__':

tests/hamcrest_unit_test/text/stringstartswith_test.py 1 location

@@ 19-63 (lines=45) @@
16
matcher = starts_with(EXCERPT)
17
stringstartswith = starts_with(EXCERPT)
18
19
class StringStartsWithTest(MatcherTest):
20
21
    def testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring(self):
22
        self.assert_matches('excerpt at beginning', matcher, EXCERPT + 'END')
23
        self.assert_does_not_match('excerpt at end',
24
                                   matcher, 'START' + EXCERPT)
25
        self.assert_does_not_match('excerpt in middle',
26
                                   matcher, 'START' + EXCERPT + 'END')
27
        self.assert_matches('excerpt repeated', matcher, EXCERPT + EXCERPT)
28
29
        self.assert_does_not_match('excerpt not in string',matcher, 'whatever')
30
        self.assert_does_not_match('only part of excerpt',matcher, EXCERPT[1:])
31
32
    def testEvaluatesToTrueIfArgumentIsEqualToSubstring(self):
33
        self.assert_matches('excerpt is entire string', matcher, EXCERPT)
34
35
    def testMatcherCreationRequiresString(self):
36
        self.assertRaises(TypeError, starts_with, 3)
37
38
    def testFailsIfMatchingAgainstNonString(self):
39
        self.assert_does_not_match('non-string', matcher, object())
40
41
    def testCanApplyUnicodeStringToUnicodeMatcher(self):
42
        self.assert_matches('unicode-unicode',
43
                            starts_with(six.u('foo')), six.u('foo bar baz'))
44
45
    def testCanApplyPlainStringToUnicodeMatcher(self):
46
        self.assert_matches('unicode-ascii',
47
                            starts_with(six.u('foo')), 'foo bar baz')
48
49
    def testCanApplyUnicodeStringToPlainMatcher(self):
50
        self.assert_matches('ascii-unicode',
51
                            starts_with(six.u('foo')), six.u('foo bar baz'))
52
53
    def testHasAReadableDescription(self):
54
        self.assert_description("a string starting with 'EXCERPT'", matcher)
55
56
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
57
        self.assert_no_mismatch_description(matcher, EXCERPT)
58
59
    def testMismatchDescription(self):
60
        self.assert_mismatch_description("was 'bad'", matcher, 'bad')
61
62
    def testDescribeMismatch(self):
63
        self.assert_describe_mismatch("was 'bad'", matcher, 'bad')
64
65
66
if __name__ == '__main__':

tests/hamcrest_unit_test/text/isequal_ignoring_case_test.py 1 location

@@ 14-55 (lines=42) @@
11
12
matcher = equal_to_ignoring_case('heLLo')
13
14
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__':