diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-28 13:38:54 -0500 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-28 13:38:54 -0500 |
| commit | 187c90b1d900be6105f3338f92097c93c4a498b4 (patch) | |
| tree | 6be19943cc94a0a9421b5a63632ef363a67c24b3 | |
| parent | a81d709f0d843406d1c60514108db333bb40bb25 (diff) | |
| download | python-coveragepy-187c90b1d900be6105f3338f92097c93c4a498b4.tar.gz | |
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...
| -rw-r--r-- | mock.py | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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)
|
