File: hasstring_test.py

package info (click to toggle)
pyhamcrest 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 556 kB
  • sloc: python: 2,938; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download | duplicates (2)
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
if __name__ == '__main__':
    import sys
    sys.path.insert(0, '..')
    sys.path.insert(0, '../..')

from hamcrest.library.object.hasstring import *

from hamcrest.core.core.isequal import equal_to
from hamcrest_unit_test.matcher_test import MatcherTest
import unittest

__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()