Skip to content

Commit 444fd0e

Browse files
committed
Some tweaks to mock.py to get patching to work on 2.3 and 3.1, though 2.3 is kind of useless for this...
1 parent 1ee6e0a commit 444fd0e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mock.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,16 @@ def patched(*args, **keywargs):
199199
patching.__exit__()
200200

201201
patched.patchings = [self]
202-
patched.__name__ = func.__name__
202+
try:
203+
patched.__name__ = func.__name__
204+
except TypeError:
205+
pass # older Pythons don't let you change __name__
206+
try:
207+
firstlineno = func.func_code.co_firstlineno
208+
except AttributeError:
209+
firstlineno = func.__code__.co_firstlineno
203210
patched.compat_co_firstlineno = getattr(func, "compat_co_firstlineno",
204-
func.func_code.co_firstlineno)
211+
firstlineno)
205212
return patched
206213

207214

@@ -255,7 +262,10 @@ def patch_object(target, attribute, new=DEFAULT, spec=None, create=False):
255262

256263
def patch(target, new=DEFAULT, spec=None, create=False):
257264
try:
258-
target, attribute = target.rsplit('.', 1)
265+
#target, attribute = target.rsplit('.', 1)
266+
parts = target.split('.')
267+
target = '.'.join(parts[:-1])
268+
attribute = parts[-1]
259269
except (TypeError, ValueError):
260270
raise TypeError("Need a valid target to patch. You supplied: %r" % (target,))
261271
target = _importer(target)

0 commit comments

Comments
 (0)