Completed
Pull Request — master (#70)
by
unknown
01:14
created

StringMatchesTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 40
rs 10
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testMatchesWhenPatternIsFoundAtEnd() 0 2 1
A testCompiledDescribeMismatch() 0 2 1
A testStringHasAReadableDescription() 0 2 1
A testMatchesUsingCompiledExpressions() 0 2 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 0 2 1
A testMismatchesWhenPatternIsNotPresent() 0 2 1
A testMismatchesUsingCompiledExpressions() 0 2 1
A testMatchesWhenPatternIsFoundAtBeginning() 0 2 1
A testPatternHasAReadableDescription() 0 2 1
A testStringMismatchDescription() 0 2 1
A testCompiledMismatchDescription() 0 2 1
A testMatchesWhenPatternIsFoundInMiddle() 0 2 1
A testStringDescribeMismatch() 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.stringmatches import *
7
from hamcrest_unit_test.matcher_test import MatcherTest
8
9
import re
10
try:
11
    import unittest2 as unittest
12
except ImportError:
13
    import unittest
14
15
__author__ = "Chris Rose"
16
__copyright__ = "Copyright 2011 hamcrest.org"
17
__license__ = "BSD, see License.txt"
18
19
string_matcher = matches_regexp(r'--[a-z]+--')
20
compiled_matcher = matches_regexp(re.compile(r'--[a-z]+--'))
21
22
class StringMatchesTest(MatcherTest):
23
24
    def testMatchesWhenPatternIsFoundAtBeginning(self):
25
        self.assert_matches('pattern at beginning', string_matcher, "--a-----")
26
27
    def testMatchesWhenPatternIsFoundAtEnd(self):
28
        self.assert_matches('pattern at end', string_matcher, "-----a--")
29
30
    def testMatchesWhenPatternIsFoundInMiddle(self):
31
        self.assert_matches('pattern in the middle', string_matcher, "-----a-----")
32
33
    def testMismatchesWhenPatternIsNotPresent(self):
34
        self.assert_does_not_match('pattern nowhere', string_matcher, "--0--")
35
36
    def testMatchesUsingCompiledExpressions(self):
37
        self.assert_matches('pattern nowhere', compiled_matcher, "--a--")
38
39
    def testMismatchesUsingCompiledExpressions(self):
40
        self.assert_does_not_match('pattern nowhere', compiled_matcher, "--0--")
41
42
    def testStringHasAReadableDescription(self):
43
        self.assert_description("a string matching '--[a-z]+--'", string_matcher)
44
45
    def testPatternHasAReadableDescription(self):
46
        self.assert_description("a string matching '--[a-z]+--'", compiled_matcher)
47
48
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
49
        self.assert_no_mismatch_description(string_matcher, '--a--')
50
51
    def testStringMismatchDescription(self):
52
        self.assert_mismatch_description("was 'bad'", string_matcher, 'bad')
53
54
    def testCompiledMismatchDescription(self):
55
        self.assert_mismatch_description("was 'bad'", compiled_matcher, 'bad')
56
57
    def testStringDescribeMismatch(self):
58
        self.assert_describe_mismatch("was 'bad'", string_matcher, 'bad')
59
60
    def testCompiledDescribeMismatch(self):
61
        self.assert_describe_mismatch("was 'bad'", compiled_matcher, 'bad')
62
63
64
if __name__ == '__main__':
65
    unittest.main()
66