1
|
|
|
from __future__ import absolute_import |
2
|
|
|
|
3
|
|
|
from hamcrest.core.core.is_ import * |
4
|
|
|
|
5
|
|
|
import six |
6
|
|
|
from hamcrest.core.core.isequal import equal_to |
7
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
8
|
|
|
from .nevermatch import NeverMatch |
9
|
|
|
|
10
|
|
|
try: |
11
|
|
|
import unittest2 as unittest |
12
|
|
|
except ImportError: |
13
|
|
|
import unittest |
14
|
|
|
|
15
|
|
|
__author__ = "Jon Reid" |
16
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
17
|
|
|
__license__ = "BSD, see License.txt" |
18
|
|
|
|
19
|
|
|
if six.PY2: |
20
|
|
|
class OldClass: |
21
|
|
|
pass |
22
|
|
|
|
23
|
|
|
class IsTest(MatcherTest): |
24
|
|
|
|
25
|
|
|
def testDelegatesMatchingToNestedMatcher(self): |
26
|
|
|
self.assert_matches('should match', is_(equal_to(True)), True) |
27
|
|
|
self.assert_matches('should match', is_(equal_to(False)), False) |
28
|
|
|
self.assert_does_not_match('should not match', is_(equal_to(True)), False) |
29
|
|
|
self.assert_does_not_match('should not match', is_(equal_to(False)), True) |
30
|
|
|
|
31
|
|
|
def testDescriptionShouldPassThrough(self): |
32
|
|
|
self.assert_description('<True>', is_(equal_to(True))) |
33
|
|
|
|
34
|
|
|
def testProvidesConvenientShortcutForIsEqualTo(self): |
35
|
|
|
self.assert_matches('should match', is_('A'), 'A'); |
36
|
|
|
self.assert_matches('should match', is_('B'), 'B'); |
37
|
|
|
self.assert_does_not_match('should not match', is_('A'), 'B'); |
38
|
|
|
self.assert_does_not_match('should not match', is_('B'), 'A'); |
39
|
|
|
self.assert_description("'A'", is_('A')); |
40
|
|
|
|
41
|
|
|
def testProvidesConvenientShortcutForIsInstanceOf(self): |
42
|
|
|
self.assert_matches('should match', is_(str), 'A'); |
43
|
|
|
self.assert_does_not_match('should not match', is_(int), 'A'); |
44
|
|
|
|
45
|
|
|
@unittest.skipUnless(six.PY2, "Old-style classes are not relevant under Python3+") |
46
|
|
|
def testProvidesConvenientShortcutForIsInstanceOfOldStyleClass(self): |
47
|
|
|
self.assert_matches('should match', is_(OldClass), OldClass()) |
48
|
|
|
|
49
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
50
|
|
|
self.assert_no_mismatch_description(is_('A'), 'A') |
51
|
|
|
|
52
|
|
|
def testDelegatesMismatchDescriptionToNestedMatcher(self): |
53
|
|
|
self.assert_mismatch_description( |
54
|
|
|
NeverMatch.mismatch_description, |
55
|
|
|
is_(NeverMatch()), |
56
|
|
|
'hi') |
57
|
|
|
|
58
|
|
|
def testDelegatesDescribeMismatchToNestedMatcher(self): |
59
|
|
|
self.assert_describe_mismatch( |
60
|
|
|
NeverMatch.mismatch_description, |
61
|
|
|
is_(NeverMatch()), |
62
|
|
|
'hi') |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
if __name__ == '__main__': |
66
|
|
|
unittest.main() |
67
|
|
|
|