1
+ import inspect
2
+
3
+ import pytest
4
+
5
+ from person import Person , Father , Mother , Child
6
+
7
+
8
+ @pytest .fixture
9
+ def person ():
10
+ return Person ()
11
+
12
+
13
+ @pytest .fixture
14
+ def dad ():
15
+ return Father ()
16
+
17
+
18
+ @pytest .fixture
19
+ def mom ():
20
+ return Mother ()
21
+
22
+
23
+ @pytest .fixture
24
+ def child ():
25
+ return Child ()
26
+
27
+
28
+ def test_string_repr_person (person ):
29
+ assert str (person ) == 'I am a person'
30
+
31
+
32
+ def test_string_repr_dad (dad ):
33
+ assert str (dad ) == 'I am a person and cool daddy'
34
+
35
+
36
+ def test_string_repr_mom (mom ):
37
+ assert str (mom ) == 'I am a person and awesome mom'
38
+
39
+
40
+ def test_string_repr_child (child ):
41
+ assert str (child ) == 'I am the coolest kid'
42
+
43
+
44
+ def test_mro_of_person ():
45
+ assert Person .__mro__ == (Person , object )
46
+
47
+
48
+ def test_mro_of_dad ():
49
+ assert Father .__mro__ == (Father , Person , object )
50
+
51
+
52
+ def test_mro_of_mom ():
53
+ assert Mother .__mro__ == (Mother , Person , object )
54
+
55
+
56
+ def test_mro_of_child ():
57
+ assert Child .__mro__ == (Child , Father , Mother , Person , object )
58
+
59
+
60
+ def test_subclass_person ():
61
+ assert issubclass (Person , object )
62
+
63
+
64
+ def test_subclass_dad ():
65
+ assert issubclass (Father , Person )
66
+ assert issubclass (Father , object )
67
+
68
+
69
+ def test_subclass_mom ():
70
+ assert issubclass (Mother , Person )
71
+ assert issubclass (Mother , object )
72
+
73
+
74
+ def test_subclass_child ():
75
+ assert issubclass (Child , Father )
76
+ assert issubclass (Child , Mother )
77
+ assert issubclass (Child , Person )
78
+ assert issubclass (Child , object )
79
+
80
+
81
+ def test_use_inheritance ():
82
+ # dry code!
83
+ # should not duplicate substr in subclass
84
+ substr = 'I am a person'
85
+ for src in (inspect .getsource (Father ),
86
+ inspect .getsource (Mother )):
87
+ assert substr not in src
0 commit comments