Completed
Pull Request — master (#75)
by Cézar
01:32
created

tests.hamcrest_unit_test.core.OldStyleIsInstanceTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %
Metric Value
dl 0
loc 28
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A OldStyleIsInstanceTest.testDescribeMismatch() 0 3 1
A OldStyleIsInstanceTest.testHasAReadableDescription() 0 3 1
A OldStyleIsInstanceTest.testSuccessfulMatchDoesNotGenerateMismatchDescription() 0 3 1
A OldStyleIsInstanceTest.testMatchesOldStyleSubclass() 0 3 1
A OldStyleIsInstanceTest.testMatchesOldStyleClass() 0 6 1
A OldStyleIsInstanceTest.testMismatchDescriptionShowsActualArgument() 0 3 1
1
import sys
2
3
if __name__ == '__main__':
4
    sys.path.insert(0, '..')
5
    sys.path.insert(0, '../..')
6
7
from hamcrest.core.core.isinstanceof import *
8
9
from hamcrest_unit_test.matcher_test import MatcherTest
10
11
try:
12
    import unittest2 as unittest
13
except ImportError:
14
    import unittest
15
16
__author__ = "Jon Reid"
17
__copyright__ = "Copyright 2011 hamcrest.org"
18
__license__ = "BSD, see License.txt"
19
20
21 View Code Duplication
class IsInstanceOfTest(MatcherTest):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
22
23
    def testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass(self):
24
        self.assert_matches('same class', instance_of(int), 1)
25
26
        self.assert_does_not_match('different class', instance_of(int), 'hi')
27
        self.assert_does_not_match('None', instance_of(int), None)
28
29
    def testMatcherCreationRequiresType(self):
30
        self.assertRaises(TypeError, instance_of, 'not a type')
31
32
    def testHasAReadableDescription(self):
33
        self.assert_description('an instance of int', instance_of(int));
34
35
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
36
        self.assert_no_mismatch_description(instance_of(int), 3)
37
38
    def testMismatchDescriptionShowsActualArgument(self):
39
        self.assert_mismatch_description("was 'bad'", instance_of(int), 'bad')
40
41
    def testDescribeMismatch(self):
42
        self.assert_describe_mismatch("was 'bad'", instance_of(int), 'bad')
43
44
45
if sys.version_info < (3,):
46
    class Parent():
47
        pass
48
49
    class Child(Parent):
50
        pass
51
52
class OldStyleIsInstanceTest(MatcherTest):
53
54
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
55
    def testMatchesOldStyleClass(self):
56
        self.assert_matches('same class', instance_of(Parent), Parent())
57
58
        self.assert_does_not_match('different class', instance_of(Parent), 'not a Parent')
59
        self.assert_does_not_match('None', instance_of(Parent), None)
60
61
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
62
    def testMatchesOldStyleSubclass(self):
63
        self.assert_matches('same class', instance_of(Parent), Child())
64
65
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
66
    def testHasAReadableDescription(self):
67
        self.assert_description('an instance of Parent', instance_of(Parent));
68
69
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
70
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
71
        self.assert_no_mismatch_description(instance_of(Parent), Parent())
72
73
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
74
    def testMismatchDescriptionShowsActualArgument(self):
75
        self.assert_mismatch_description("was 'bad'", instance_of(Parent), 'bad')
76
77
    @unittest.skipIf(sys.version_info >= (3,), "Old-style classes are not relevant under Python3+")
78
    def testDescribeMismatch(self):
79
        self.assert_describe_mismatch("was 'bad'", instance_of(Parent), 'bad')
80
81
if __name__ == '__main__':
82
    unittest.main()
83