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

IsEqualIgnoringCaseTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testMismatchDescription() 2 2 1
A testFailsIfAdditionalWhitespaceIsPresent() 3 3 1
A testCanApplyUnicodeStringToUnicodeMatcher() 3 3 1
A testDescribeMismatch() 2 2 1
A testCanApplyUnicodeStringToPlainMatcher() 3 3 1
A testFailsIfMatchingAgainstNonString() 2 2 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 2 2 1
A testCanApplyPlainStringToUnicodeMatcher() 3 3 1
A testIgnoresCaseOfCharsInString() 6 6 1
A testHasAReadableDescription() 2 2 1
A testMatcherCreationRequiresString() 2 2 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
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):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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