File: stringendswith_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 (48 lines) | stat: -rw-r--r-- 1,786 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
import unittest

from hamcrest.library.text.stringendswith import ends_with
from hamcrest_unit_test.matcher_test import MatcherTest

__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"


EXCERPT = "EXCERPT"
matcher = ends_with(EXCERPT)


class StringEndsWithTest(MatcherTest):
    def testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring(self):
        self.assert_does_not_match("excerpt at beginning", matcher, EXCERPT + "END")
        self.assert_matches("excerpt at end", matcher, "START" + EXCERPT)
        self.assert_does_not_match("excerpt in middle", matcher, "START" + EXCERPT + "END")
        self.assert_matches("excerpt repeated", matcher, EXCERPT + EXCERPT)

        self.assert_does_not_match("excerpt not in string", matcher, "whatever")
        self.assert_does_not_match("only part of excerpt is at end of string", matcher, EXCERPT[1:])

    def testEvaluatesToTrueIfArgumentIsEqualToSubstring(self):
        self.assert_matches("excerpt is entire string", matcher, EXCERPT)

    def testMatcherCreationRequiresString(self):
        self.assertRaises(TypeError, ends_with, 3)

    def testFailsIfMatchingAgainstNonString(self):
        self.assert_does_not_match("non-string", matcher, object())

    def testHasAReadableDescription(self):
        self.assert_description("a string ending with 'EXCERPT'", matcher)

    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
        self.assert_no_mismatch_description(matcher, EXCERPT)

    def testMismatchDescription(self):
        self.assert_mismatch_description("was 'bad'", matcher, "bad")

    def testDescribeMismatch(self):
        self.assert_describe_mismatch("was 'bad'", matcher, "bad")


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