@@ -63,10 +63,7 @@ def _get_signature_object(func, as_instance, eat_self):
63
63
"""
64
64
if isinstance (func , type ) and not as_instance :
65
65
# If it's a type and should be modelled as a type, use __init__.
66
- try :
67
- func = func .__init__
68
- except AttributeError :
69
- return None
66
+ func = func .__init__
70
67
# Skip the `self` argument in __init__
71
68
eat_self = True
72
69
elif not isinstance (func , FunctionTypes ):
@@ -147,8 +144,6 @@ def _set_signature(mock, original, instance=False):
147
144
# creates a function with signature (*args, **kwargs) that delegates to a
148
145
# mock. It still does signature checking by calling a lambda with the same
149
146
# signature as the original.
150
- if not _callable (original ):
151
- return
152
147
153
148
skipfirst = isinstance (original , type )
154
149
result = _get_signature_object (original , instance , skipfirst )
@@ -175,10 +170,6 @@ def checksig(*args, **kwargs):
175
170
def _setup_func (funcopy , mock , sig ):
176
171
funcopy .mock = mock
177
172
178
- # can't use isinstance with mocks
179
- if not _is_instance_mock (mock ):
180
- return
181
-
182
173
def assert_called_with (* args , ** kwargs ):
183
174
return mock .assert_called_with (* args , ** kwargs )
184
175
def assert_called (* args , ** kwargs ):
@@ -263,12 +254,6 @@ def __reduce__(self):
263
254
_deleted = sentinel .DELETED
264
255
265
256
266
- def _copy (value ):
267
- if type (value ) in (dict , list , tuple , set ):
268
- return type (value )(value )
269
- return value
270
-
271
-
272
257
_allowed_names = {
273
258
'return_value' , '_mock_return_value' , 'side_effect' ,
274
259
'_mock_side_effect' , '_mock_parent' , '_mock_new_parent' ,
@@ -351,8 +336,6 @@ def _check_and_set_parent(parent, value, name, new_name):
351
336
class _MockIter (object ):
352
337
def __init__ (self , obj ):
353
338
self .obj = iter (obj )
354
- def __iter__ (self ):
355
- return self
356
339
def __next__ (self ):
357
340
return next (self .obj )
358
341
@@ -452,7 +435,7 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
452
435
if isinstance (spec , type ):
453
436
_spec_class = spec
454
437
else :
455
- _spec_class = _get_class (spec )
438
+ _spec_class = type (spec )
456
439
res = _get_signature_object (spec ,
457
440
_spec_as_instance , _eat_self )
458
441
_spec_signature = res and res [1 ]
@@ -624,7 +607,7 @@ def _extract_mock_name(self):
624
607
dot = '.'
625
608
if _name_list == ['()' ]:
626
609
dot = ''
627
- seen = set ()
610
+
628
611
while _parent is not None :
629
612
last = _parent
630
613
@@ -635,11 +618,6 @@ def _extract_mock_name(self):
635
618
636
619
_parent = _parent ._mock_new_parent
637
620
638
- # use ids here so as not to call __hash__ on the mocks
639
- if id (_parent ) in seen :
640
- break
641
- seen .add (id (_parent ))
642
-
643
621
_name_list = list (reversed (_name_list ))
644
622
_first = last ._mock_name or 'mock'
645
623
if len (_name_list ) > 1 :
@@ -753,8 +731,6 @@ def _format_mock_failure_message(self, args, kwargs):
753
731
message = 'expected call not found.\n Expected: %s\n Actual: %s'
754
732
expected_string = self ._format_mock_call_signature (args , kwargs )
755
733
call_args = self .call_args
756
- if len (call_args ) == 3 :
757
- call_args = call_args [1 :]
758
734
actual_string = self ._format_mock_call_signature (* call_args )
759
735
return message % (expected_string , actual_string )
760
736
@@ -992,8 +968,6 @@ def _mock_call(_mock_self, *args, **kwargs):
992
968
self .call_args = _call
993
969
self .call_args_list .append (_call )
994
970
995
- seen = set ()
996
-
997
971
# initial stuff for method_calls:
998
972
do_method_calls = self ._mock_parent is not None
999
973
method_call_name = self ._mock_name
@@ -1029,13 +1003,6 @@ def _mock_call(_mock_self, *args, **kwargs):
1029
1003
# follow the parental chain:
1030
1004
_new_parent = _new_parent ._mock_new_parent
1031
1005
1032
- # check we're not in an infinite loop:
1033
- # ( use ids here so as not to call __hash__ on the mocks)
1034
- _new_parent_id = id (_new_parent )
1035
- if _new_parent_id in seen :
1036
- break
1037
- seen .add (_new_parent_id )
1038
-
1039
1006
effect = self .side_effect
1040
1007
if effect is not None :
1041
1008
if _is_exception (effect ):
@@ -1858,12 +1825,7 @@ def _set_return_value(mock, method, name):
1858
1825
1859
1826
return_calulator = _calculate_return_value .get (name )
1860
1827
if return_calulator is not None :
1861
- try :
1862
- return_value = return_calulator (mock )
1863
- except AttributeError :
1864
- # XXXX why do we return AttributeError here?
1865
- # set it as a side_effect instead?
1866
- return_value = AttributeError (name )
1828
+ return_value = return_calulator (mock )
1867
1829
method .return_value = return_value
1868
1830
return
1869
1831
@@ -1943,10 +1905,6 @@ def __init__(self, name, parent):
1943
1905
self .name = name
1944
1906
self .parent = parent
1945
1907
1946
- def __call__ (self , * args , ** kwargs ):
1947
- m = self .create_mock ()
1948
- return m (* args , ** kwargs )
1949
-
1950
1908
def create_mock (self ):
1951
1909
entry = self .name
1952
1910
parent = self .parent
@@ -2330,19 +2288,10 @@ def _must_skip(spec, entry, is_type):
2330
2288
else :
2331
2289
return False
2332
2290
2333
- # shouldn't get here unless function is a dynamically provided attribute
2334
- # XXXX untested behaviour
2291
+ # function is a dynamically provided attribute
2335
2292
return is_type
2336
2293
2337
2294
2338
- def _get_class (obj ):
2339
- try :
2340
- return obj .__class__
2341
- except AttributeError :
2342
- # it is possible for objects to have no __class__
2343
- return type (obj )
2344
-
2345
-
2346
2295
class _SpecState (object ):
2347
2296
2348
2297
def __init__ (self , spec , spec_set = False , parent = None ,
0 commit comments