Completed
Pull Request — master (#80)
by
unknown
36s
created

StringEndsWithTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 47
loc 47
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testHasAReadableDescription() 2 2 1
A testCanApplyPlainStringToUnicodeMatcher() 3 3 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 2 2 1
A testFailsIfMatchingAgainstNonString() 2 2 1
A testMatcherCreationRequiresString() 2 2 1
A testEvaluatesToTrueIfArgumentIsEqualToSubstring() 2 2 1
A testDescribeMismatch() 2 2 1
A testMismatchDescription() 2 2 1
A testCanApplyUnicodeStringToPlainMatcher() 3 3 1
A testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() 12 12 1
A testCanApplyUnicodeStringToUnicodeMatcher() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import six
2
3
from hamcrest.library.text.stringendswith import *
4
5
from hamcrest_unit_test.matcher_test import MatcherTest
6
import unittest
7
8
__author__ = "Jon Reid"
9
__copyright__ = "Copyright 2011 hamcrest.org"
10
__license__ = "BSD, see License.txt"
11
12
13
EXCERPT = 'EXCERPT'
14
matcher = ends_with(EXCERPT)
15
16 View Code Duplication
class StringEndsWithTest(MatcherTest):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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__':
66
    unittest.main()
67