tests.hamcrest_unit_test.text.StringStartsWithTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %
Metric Value
dl 0
loc 45
rs 10
wmc 11

11 Methods

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

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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