@@ -18,16 +18,16 @@ def test_calling_undefined_functions_normally_results_in_errors(self):
18
18
try :
19
19
typical .foobar ()
20
20
except Exception as exception :
21
- self .assertEqual (__ , type (exception ).__name__ )
22
- self .assertMatch (__ , exception [0 ])
21
+ self .assertEqual ('AttributeError' , type (exception ).__name__ )
22
+ self .assertMatch ("'TypicalObject' object has no attribute 'foobar'" , exception [0 ])
23
23
24
24
def test_calling_getattribute_causes_an_attribute_error (self ):
25
25
typical = self .TypicalObject ()
26
26
27
27
try :
28
28
typical .__getattribute__ ('foobar' )
29
29
except AttributeError as exception :
30
- self .assertMatch (__ , exception [0 ])
30
+ self .assertMatch ("'TypicalObject' object has no attribute 'foobar'" , exception [0 ])
31
31
32
32
# THINK ABOUT IT:
33
33
#
@@ -43,17 +43,17 @@ def __getattribute__(self, attr_name):
43
43
def test_all_attribute_reads_are_caught (self ):
44
44
catcher = self .CatchAllAttributeReads ()
45
45
46
- self .assertMatch (__ , catcher .foobar )
46
+ self .assertMatch ("Someone called 'foobar' and it could not be found" , catcher .foobar )
47
47
48
48
def test_intercepting_return_values_can_disrupt_the_call_chain (self ):
49
49
catcher = self .CatchAllAttributeReads ()
50
50
51
- self .assertMatch (__ , catcher .foobaz ) # This is fine
51
+ self .assertMatch ("Someone called 'foobaz' and it could not be found" , catcher .foobaz ) # This is fine
52
52
53
53
try :
54
54
catcher .foobaz (1 )
55
55
except TypeError as ex :
56
- self .assertMatch (__ , ex [0 ])
56
+ self .assertMatch ("'str' object is not callable" , ex [0 ])
57
57
58
58
# foobaz returns a string. What happens to the '(1)' part?
59
59
# Try entering this into a python console to reproduce the issue:
@@ -64,7 +64,7 @@ def test_intercepting_return_values_can_disrupt_the_call_chain(self):
64
64
def test_changes_to_the_getattribute_implementation_affects_getattr_function (self ):
65
65
catcher = self .CatchAllAttributeReads ()
66
66
67
- self .assertMatch (__ , getattr (catcher , 'any_attribute' ))
67
+ self .assertMatch ("Someone called 'any_attribute' and it could not be found" , getattr (catcher , 'any_attribute' ))
68
68
69
69
# ------------------------------------------------------------------
70
70
@@ -79,16 +79,16 @@ def __getattribute__(self, attr_name):
79
79
def test_foo_attributes_are_caught (self ):
80
80
catcher = self .WellBehavedFooCatcher ()
81
81
82
- self .assertEqual (__ , catcher .foo_bar )
83
- self .assertEqual (__ , catcher .foo_baz )
82
+ self .assertEqual ('Foo to you too' , catcher .foo_bar )
83
+ self .assertEqual ('Foo to you too' , catcher .foo_baz )
84
84
85
85
def test_non_foo_messages_are_treated_normally (self ):
86
86
catcher = self .WellBehavedFooCatcher ()
87
87
88
88
try :
89
89
catcher .normal_undefined_attribute
90
90
except AttributeError as ex :
91
- self .assertMatch (__ , ex [0 ])
91
+ self .assertMatch ("'WellBehavedFooCatcher' object has no attribute 'normal_undefined_attribute'" , ex [0 ])
92
92
93
93
# ------------------------------------------------------------------
94
94
@@ -125,7 +125,7 @@ def test_getattribute_is_a_bit_overzealous_sometimes(self):
125
125
catcher = self .RecursiveCatcher ()
126
126
catcher .my_method ()
127
127
global stack_depth
128
- self .assertEqual (__ , stack_depth )
128
+ self .assertEqual (11 , stack_depth )
129
129
130
130
# ------------------------------------------------------------------
131
131
@@ -146,17 +146,17 @@ def test_getattr_ignores_known_attributes(self):
146
146
catcher = self .MinimalCatcher ()
147
147
catcher .my_method ()
148
148
149
- self .assertEqual (__ , catcher .no_of_getattr_calls )
149
+ self .assertEqual (0 , catcher .no_of_getattr_calls )
150
150
151
151
def test_getattr_only_catches_unknown_attributes (self ):
152
152
catcher = self .MinimalCatcher ()
153
153
catcher .purple_flamingos ()
154
154
catcher .free_pie ()
155
155
156
- self .assertEqual (__ ,
156
+ self .assertEqual ('DuffObject' ,
157
157
type (catcher .give_me_duff_or_give_me_death ()).__name__ )
158
158
159
- self .assertEqual (__ , catcher .no_of_getattr_calls )
159
+ self .assertEqual (3 , catcher .no_of_getattr_calls )
160
160
161
161
# ------------------------------------------------------------------
162
162
@@ -177,9 +177,9 @@ def test_setattr_intercepts_attribute_assignments(self):
177
177
fanboy .comic = 'The Laminator, issue #1'
178
178
fanboy .pie = 'blueberry'
179
179
180
- self .assertEqual (__ , fanboy .a_pie )
180
+ self .assertEqual ('blueberry' , fanboy .a_pie )
181
181
182
- prefix = '__ '
182
+ prefix = 'my '
183
183
self .assertEqual ("The Laminator, issue #1" , getattr (fanboy , prefix + '_comic' ))
184
184
185
185
# ------------------------------------------------------------------
@@ -201,17 +201,17 @@ def test_it_modifies_external_attribute_as_expected(self):
201
201
setter = self .ScarySetter ()
202
202
setter .e = "mc hammer"
203
203
204
- self .assertEqual (__ , setter .altered_e )
204
+ self .assertEqual ("mc hammer" , setter .altered_e )
205
205
206
206
def test_it_mangles_some_internal_attributes (self ):
207
207
setter = self .ScarySetter ()
208
208
209
209
try :
210
210
coconuts = setter .num_of_coconuts
211
211
except AttributeError :
212
- self .assertEqual (__ , setter .altered_num_of_coconuts )
212
+ self .assertEqual (9 , setter .altered_num_of_coconuts )
213
213
214
214
def test_in_this_case_private_attributes_remain_unmangled (self ):
215
215
setter = self .ScarySetter ()
216
216
217
- self .assertEqual (__ , setter ._num_of_private_coconuts )
217
+ self .assertEqual (2 , setter ._num_of_private_coconuts )
0 commit comments