testDescribeMismatchDescription()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
if __name__ == '__main__':
2
    import sys
3
    sys.path.insert(0, '..')
4
    sys.path.insert(0, '../..')
5
6
from hamcrest.library.object.hasstring import *
7
8
from hamcrest.core.core.isequal import equal_to
9
from hamcrest_unit_test.matcher_test import MatcherTest
10
import unittest
11
12
__author__ = "Jon Reid"
13
__copyright__ = "Copyright 2011 hamcrest.org"
14
__license__ = "BSD, see License.txt"
15
16
17
class FakeWithStr(object):
18
19
    def __str__(self):
20
        return 'FakeWithStr'
21
22
23
class HasStringTest(MatcherTest):
24
25
    def testPassesResultOfToStrToNestedMatcher(self):
26
        self.assert_matches('equal',
27
                            has_string(equal_to('FakeWithStr')), FakeWithStr())
28
        self.assert_does_not_match('unequal',
29
                                   has_string(equal_to('FakeWithStr')), 3)
30
31
    def testProvidesConvenientShortcutForHasStringEqualTo(self):
32
        self.assert_matches('equal', has_string('FakeWithStr'), FakeWithStr())
33
        self.assert_does_not_match('unequal', has_string('FakeWithStr'), 3)
34
35
    def testHasReadableDescription(self):
36
        self.assert_description("an object with str 'foo'", has_string('foo'))
37
38
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
39
        self.assert_no_mismatch_description(has_string('FakeWithStr'),
40
                                            FakeWithStr())
41
42
    def testMismatchDescription(self):
43
        self.assert_mismatch_description("was <FakeWithStr>",
44
                                         has_string('foo'), FakeWithStr())
45
46
    def testDescribeMismatchDescription(self):
47
        self.assert_describe_mismatch("was <FakeWithStr>",
48
                                      has_string('foo'), FakeWithStr())
49
50
51
if __name__ == '__main__':
52
    unittest.main()
53