1
|
|
|
from __future__ import absolute_import |
2
|
|
|
|
3
|
|
|
from hamcrest.core.core.described_as import * |
4
|
|
|
|
5
|
|
|
from hamcrest.core.core.isanything import anything |
6
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
7
|
|
|
from .nevermatch import NeverMatch |
8
|
|
|
import unittest |
9
|
|
|
|
10
|
|
|
__author__ = "Jon Reid" |
11
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
12
|
|
|
__license__ = "BSD, see License.txt" |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class DescribedAsTest(MatcherTest): |
16
|
|
|
|
17
|
|
|
def testOverridesDescriptionOfNestedMatcherWithConstructorArgument(self): |
18
|
|
|
m1 = described_as('m1 description', anything()) |
19
|
|
|
m2 = described_as('m2 description', NeverMatch()) |
20
|
|
|
|
21
|
|
|
self.assert_description('m1 description', m1) |
22
|
|
|
self.assert_description('m2 description', m2) |
23
|
|
|
|
24
|
|
|
def testAppendsValuesToDescription(self): |
25
|
|
|
m = described_as('value 1 = %0, value 2 = %1', anything(), 33, 97) |
26
|
|
|
|
27
|
|
|
self.assert_description('value 1 = <33>, value 2 = <97>', m) |
28
|
|
|
|
29
|
|
|
def testDelegatesMatchingToNestedMatcher(self): |
30
|
|
|
m1 = described_as('irrelevant', anything()) |
31
|
|
|
m2 = described_as('irrelevant', NeverMatch()) |
32
|
|
|
|
33
|
|
|
self.assertTrue(m1.matches(object())) |
34
|
|
|
self.assertTrue(not m2.matches('hi')) |
35
|
|
|
|
36
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
37
|
|
|
self.assert_no_mismatch_description( |
38
|
|
|
described_as('irrelevant', anything()), |
39
|
|
|
object()) |
40
|
|
|
|
41
|
|
|
def testDelegatesMismatchDescriptionToNestedMatcher(self): |
42
|
|
|
self.assert_mismatch_description( |
43
|
|
|
NeverMatch.mismatch_description, |
44
|
|
|
described_as('irrelevant', NeverMatch()), |
45
|
|
|
'hi') |
46
|
|
|
|
47
|
|
|
def testDelegatesDescribeMismatchToNestedMatcher(self): |
48
|
|
|
self.assert_describe_mismatch( |
49
|
|
|
NeverMatch.mismatch_description, |
50
|
|
|
described_as('irrelevant', NeverMatch()), |
51
|
|
|
'hi') |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
if __name__ == '__main__': |
55
|
|
|
unittest.main() |
56
|
|
|
|