tests.hamcrest_unit_test.text.StringContainsInOrderTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %
Metric Value
dl 0
loc 32
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testMatcherCreationRequiresString() 0 2 1
A testHasAReadableDescription() 0 2 1
A testMatchesIfOrderIsCorrect() 0 3 1
A testMismatchDescription() 0 2 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 0 2 1
A testDoesNotMatchIfExpectedSubstringsAreMissing() 0 4 1
A testDoesNotMatchIfOrderIsIncorrect() 0 3 1
A testFailsIfMatchingAgainstNonString() 0 2 1
A testDescribeMismatch() 0 2 1
1
if __name__ == '__main__':
2
    import sys
3
    sys.path.insert(0, '..')
4
    sys.path.insert(0, '../..')
5
6
from hamcrest.library.text import string_contains_in_order
7
8
from hamcrest.core.string_description import StringDescription
9
from hamcrest_unit_test.matcher_test import MatcherTest
10
import unittest
11
12
__author__ = "Romilly Cocking"
13
__copyright__ = "Copyright 2011 hamcrest.org"
14
__license__ = "BSD, see License.txt"
15
16
17
matcher = string_contains_in_order('string one', 'string two', 'string three')
18
19
class StringContainsInOrderTest(MatcherTest):
20
21
    def testMatchesIfOrderIsCorrect(self):
22
        self.assert_matches('correct order', matcher,
23
                            'string one then string two followed by string three')
24
25
    def testDoesNotMatchIfOrderIsIncorrect(self):
26
        self.assert_does_not_match('incorrect order', matcher,
27
                                    'string two then string one followed by string three')
28
29
    def testDoesNotMatchIfExpectedSubstringsAreMissing(self):
30
        self.assert_does_not_match('missing string one', matcher, 'string two then string three')
31
        self.assert_does_not_match('missing string two', matcher, 'string one then string three')
32
        self.assert_does_not_match('missing string three', matcher, 'string one then string two')
33
34
    def testMatcherCreationRequiresString(self):
35
        self.assertRaises(TypeError, string_contains_in_order, 3)
36
37
    def testFailsIfMatchingAgainstNonString(self):
38
        self.assert_does_not_match('non-string', matcher, object())
39
40
    def testHasAReadableDescription(self):
41
        self.assert_description("a string containing 'string one', 'string two', 'string three' in order", matcher)
42
43
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
44
        self.assert_no_mismatch_description(matcher, 'string one then string two followed by string three')
45
46
    def testMismatchDescription(self):
47
        self.assert_mismatch_description("was 'bad'", matcher, 'bad')
48
49
    def testDescribeMismatch(self):
50
        self.assert_describe_mismatch("was 'bad'", matcher, 'bad')
51