@@ -13,36 +13,36 @@ class Dog:
13
13
14
14
def test_objects_are_objects (self ):
15
15
fido = self .Dog ()
16
- self .assertEqual (__ , isinstance (fido , object ))
16
+ self .assertEqual (True , isinstance (fido , object ))
17
17
18
18
def test_classes_are_types (self ):
19
- self .assertEqual (__ , self .Dog .__class__ == type )
19
+ self .assertEqual (True , self .Dog .__class__ == type )
20
20
21
21
def test_classes_are_objects_too (self ):
22
- self .assertEqual (__ , issubclass (self .Dog , object ))
22
+ self .assertEqual (True , issubclass (self .Dog , object ))
23
23
24
24
def test_objects_have_methods (self ):
25
25
fido = self .Dog ()
26
- self .assertEqual (__ , len (dir (fido )))
26
+ self .assertEqual (26 , len (dir (fido )))
27
27
28
28
def test_classes_have_methods (self ):
29
- self .assertEqual (__ , len (dir (self .Dog )))
29
+ self .assertEqual (26 , len (dir (self .Dog )))
30
30
31
31
def test_creating_objects_without_defining_a_class (self ):
32
32
singularity = object ()
33
- self .assertEqual (__ , len (dir (singularity )))
33
+ self .assertEqual (23 , len (dir (singularity )))
34
34
35
35
def test_defining_attributes_on_individual_objects (self ):
36
36
fido = self .Dog ()
37
37
fido .legs = 4
38
38
39
- self .assertEqual (__ , fido .legs )
39
+ self .assertEqual (4 , fido .legs )
40
40
41
41
def test_defining_functions_on_individual_objects (self ):
42
42
fido = self .Dog ()
43
43
fido .wag = lambda : 'fidos wag'
44
44
45
- self .assertEqual (__ , fido .wag ())
45
+ self .assertEqual ("fidos wag" , fido .wag ())
46
46
47
47
def test_other_objects_are_not_affected_by_these_singleton_functions (self ):
48
48
fido = self .Dog ()
@@ -52,7 +52,7 @@ def wag():
52
52
return 'fidos wag'
53
53
fido .wag = wag
54
54
55
- with self .assertRaises (___ ): rover .wag ()
55
+ with self .assertRaises (AttributeError ): rover .wag ()
56
56
57
57
# ------------------------------------------------------------------
58
58
@@ -75,19 +75,19 @@ def growl(cls):
75
75
return "classmethod growl, arg: cls=" + cls .__name__
76
76
77
77
def test_since_classes_are_objects_you_can_define_singleton_methods_on_them_too (self ):
78
- self .assertRegex (self .Dog2 .growl (), __ )
78
+ self .assertRegex (self .Dog2 .growl (), "classmethod growl" )
79
79
80
80
def test_classmethods_are_not_independent_of_instance_methods (self ):
81
81
fido = self .Dog2 ()
82
- self .assertRegex (fido .growl (), __ )
83
- self .assertRegex (self .Dog2 .growl (), __ )
82
+ self .assertRegex (fido .growl (), "classmethod" )
83
+ self .assertRegex (self .Dog2 .growl (), "classmethod" )
84
84
85
85
def test_staticmethods_are_unbound_functions_housed_in_a_class (self ):
86
- self .assertRegex (self .Dog2 .bark (), __ )
86
+ self .assertRegex (self .Dog2 .bark (), "staticmethod" )
87
87
88
88
def test_staticmethods_also_overshadow_instance_methods (self ):
89
89
fido = self .Dog2 ()
90
- self .assertRegex (fido .bark (), __ )
90
+ self .assertRegex (fido .bark (), "staticmethod" )
91
91
92
92
# ------------------------------------------------------------------
93
93
@@ -114,20 +114,20 @@ def set_name(cls, name):
114
114
115
115
def test_classmethods_can_not_be_used_as_properties (self ):
116
116
fido = self .Dog3 ()
117
- with self .assertRaises (___ ): fido .name = "Fido"
117
+ with self .assertRaises (TypeError ): fido .name = "Fido"
118
118
119
119
def test_classes_and_instances_do_not_share_instance_attributes (self ):
120
120
fido = self .Dog3 ()
121
121
fido .set_name_from_instance ("Fido" )
122
122
fido .set_name ("Rover" )
123
- self .assertEqual (__ , fido .get_name_from_instance ())
124
- self .assertEqual (__ , self .Dog3 .get_name ())
123
+ self .assertEqual ("Fido" , fido .get_name_from_instance ())
124
+ self .assertEqual ("Rover" , self .Dog3 .get_name ())
125
125
126
126
def test_classes_and_instances_do_share_class_attributes (self ):
127
127
fido = self .Dog3 ()
128
128
fido .set_name ("Fido" )
129
- self .assertEqual (__ , fido .get_name ())
130
- self .assertEqual (__ , self .Dog3 .get_name ())
129
+ self .assertEqual ("Fido" , fido .get_name ())
130
+ self .assertEqual ("Fido" , self .Dog3 .get_name ())
131
131
132
132
# ------------------------------------------------------------------
133
133
@@ -142,13 +142,13 @@ def a_static_method():
142
142
a_static_method = staticmethod (a_static_method )
143
143
144
144
def test_you_can_define_class_methods_without_using_a_decorator (self ):
145
- self .assertEqual (__ , self .Dog4 .a_class_method ())
145
+ self .assertEqual ("dogs class method" , self .Dog4 .a_class_method ())
146
146
147
147
def test_you_can_define_static_methods_without_using_a_decorator (self ):
148
- self .assertEqual (__ , self .Dog4 .a_static_method ())
148
+ self .assertEqual ("dogs static method" , self .Dog4 .a_static_method ())
149
149
150
150
# ------------------------------------------------------------------
151
151
152
152
def test_heres_an_easy_way_to_explicitly_call_class_methods_from_instance_methods (self ):
153
153
fido = self .Dog4 ()
154
- self .assertEqual (__ , fido .__class__ .a_class_method ())
154
+ self .assertEqual ("dogs class method" , fido .__class__ .a_class_method ())
0 commit comments