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

StringStartsWithTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanApplyPlainStringToUnicodeMatcher() 3 3 1
A testMatcherCreationRequiresString() 2 2 1
A testCanApplyUnicodeStringToUnicodeMatcher() 3 3 1
A testEvaluatesToTrueIfArgumentIsEqualToSubstring() 2 2 1
A testMismatchDescription() 2 2 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 2 2 1
A testCanApplyUnicodeStringToPlainMatcher() 3 3 1
A testHasAReadableDescription() 2 2 1
A testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() 10 10 1
A testFailsIfMatchingAgainstNonString() 2 2 1
A testDescribeMismatch() 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
3
from hamcrest.library.text.stringstartswith import *
4
5
from hamcrest.core.assert_that import assert_that
6
from hamcrest.core.core.isnot import is_not
7
from hamcrest_unit_test.matcher_test import MatcherTest
8
import unittest
9
10
__author__ = "Jon Reid"
11
__copyright__ = "Copyright 2011 hamcrest.org"
12
__license__ = "BSD, see License.txt"
13
14
15
EXCERPT = 'EXCERPT'
16
matcher = starts_with(EXCERPT)
17
stringstartswith = starts_with(EXCERPT)
18
19 View Code Duplication
class StringStartsWithTest(MatcherTest):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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__':
67
    unittest.main()
68