File: stringmatches_test.py

package info (click to toggle)
pyhamcrest 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: python: 4,081; makefile: 114; sh: 15
file content (63 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
if __name__ == "__main__":
    import sys

    sys.path.insert(0, "..")
    sys.path.insert(0, "../..")

import re
import unittest

from hamcrest.library.text.stringmatches import matches_regexp
from hamcrest_unit_test.matcher_test import MatcherTest

__author__ = "Chris Rose"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"

string_matcher = matches_regexp(r"--[a-z]+--")
compiled_matcher = matches_regexp(re.compile(r"--[a-z]+--"))


class StringMatchesTest(MatcherTest):
    def testMatchesWhenPatternIsFoundAtBeginning(self):
        self.assert_matches("pattern at beginning", string_matcher, "--a-----")

    def testMatchesWhenPatternIsFoundAtEnd(self):
        self.assert_matches("pattern at end", string_matcher, "-----a--")

    def testMatchesWhenPatternIsFoundInMiddle(self):
        self.assert_matches("pattern in the middle", string_matcher, "-----a-----")

    def testMismatchesWhenPatternIsNotPresent(self):
        self.assert_does_not_match("pattern nowhere", string_matcher, "--0--")

    def testMatchesUsingCompiledExpressions(self):
        self.assert_matches("pattern nowhere", compiled_matcher, "--a--")

    def testMismatchesUsingCompiledExpressions(self):
        self.assert_does_not_match("pattern nowhere", compiled_matcher, "--0--")

    def testStringHasAReadableDescription(self):
        self.assert_description("a string matching '--[a-z]+--'", string_matcher)

    def testPatternHasAReadableDescription(self):
        self.assert_description("a string matching '--[a-z]+--'", compiled_matcher)

    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
        self.assert_no_mismatch_description(string_matcher, "--a--")

    def testStringMismatchDescription(self):
        self.assert_mismatch_description("was 'bad'", string_matcher, "bad")

    def testCompiledMismatchDescription(self):
        self.assert_mismatch_description("was 'bad'", compiled_matcher, "bad")

    def testStringDescribeMismatch(self):
        self.assert_describe_mismatch("was 'bad'", string_matcher, "bad")

    def testCompiledDescribeMismatch(self):
        self.assert_describe_mismatch("was 'bad'", compiled_matcher, "bad")


if __name__ == "__main__":
    unittest.main()