summaryrefslogtreecommitdiff
path: root/mock.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-03-13 20:12:05 -0500
committerNed Batchelder <ned@nedbatchelder.com>2010-03-13 20:12:05 -0500
commit78e2e6eb38d229cfcd4d0202f27761cd5bab2495 (patch)
tree93866af62ea60710682aaa5a6e709b55cd29b69b /mock.py
parent543ff12a09952b132abd9aa863d4170c4e2523f4 (diff)
parenta5e4aa218a749f9ea73bccea4cac92bd35387451 (diff)
downloadpython-coveragepy-78e2e6eb38d229cfcd4d0202f27761cd5bab2495.tar.gz
Merged Ben Finney's use-os-path-module fixes (again?)
Diffstat (limited to 'mock.py')
-rw-r--r--mock.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/mock.py b/mock.py
index 795ccc1..364a939 100644
--- a/mock.py
+++ b/mock.py
@@ -199,9 +199,16 @@ class _patch(object):
patching.__exit__()
patched.patchings = [self]
- patched.__name__ = func.__name__
+ try:
+ patched.__name__ = func.__name__
+ except TypeError:
+ pass # older Pythons don't let you change __name__
+ try:
+ firstlineno = func.func_code.co_firstlineno
+ except AttributeError:
+ firstlineno = func.__code__.co_firstlineno
patched.compat_co_firstlineno = getattr(func, "compat_co_firstlineno",
- func.func_code.co_firstlineno)
+ firstlineno)
return patched
@@ -255,7 +262,10 @@ def patch_object(target, attribute, new=DEFAULT, spec=None, create=False):
def patch(target, new=DEFAULT, spec=None, create=False):
try:
- target, attribute = target.rsplit('.', 1)
+ #target, attribute = target.rsplit('.', 1)
+ parts = target.split('.')
+ target = '.'.join(parts[:-1])
+ attribute = parts[-1]
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" % (target,))
target = _importer(target)