File: hasstring_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 (46 lines) | stat: -rw-r--r-- 1,562 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
if __name__ == "__main__":
    import sys

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

import unittest

from hamcrest.core.core.isequal import equal_to
from hamcrest.library.object.hasstring import has_string
from hamcrest_unit_test.matcher_test import MatcherTest

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


class FakeWithStr(object):
    def __str__(self):
        return "FakeWithStr"


class HasStringTest(MatcherTest):
    def testPassesResultOfToStrToNestedMatcher(self):
        self.assert_matches("equal", has_string(equal_to("FakeWithStr")), FakeWithStr())
        self.assert_does_not_match("unequal", has_string(equal_to("FakeWithStr")), 3)

    def testProvidesConvenientShortcutForHasStringEqualTo(self):
        self.assert_matches("equal", has_string("FakeWithStr"), FakeWithStr())
        self.assert_does_not_match("unequal", has_string("FakeWithStr"), 3)

    def testHasReadableDescription(self):
        self.assert_description("an object with str 'foo'", has_string("foo"))

    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
        self.assert_no_mismatch_description(has_string("FakeWithStr"), FakeWithStr())

    def testMismatchDescription(self):
        self.assert_mismatch_description("was <FakeWithStr>", has_string("foo"), FakeWithStr())

    def testDescribeMismatchDescription(self):
        self.assert_describe_mismatch("was <FakeWithStr>", has_string("foo"), FakeWithStr())


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