Completed
Pull Request — master (#67)
by
unknown
01:24
created

tests.hamcrest_unit_test.core.IsTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %
Metric Value
dl 0
loc 40
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A IsTest.testProvidesConvenientShortcutForIsInstanceOfOldStyleClass() 0 3 1
A IsTest.testDelegatesMatchingToNestedMatcher() 0 5 1
A IsTest.testDelegatesDescribeMismatchToNestedMatcher() 0 5 1
A IsTest.testSuccessfulMatchDoesNotGenerateMismatchDescription() 0 2 1
A IsTest.testDelegatesMismatchDescriptionToNestedMatcher() 0 5 1
A IsTest.testDescriptionShouldPassThrough() 0 2 1
A IsTest.testProvidesConvenientShortcutForIsEqualTo() 0 6 1
A IsTest.testProvidesConvenientShortcutForIsInstanceOf() 0 3 1
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