summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-03-14 21:56:54 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2012-03-14 21:56:54 (GMT)
commitd7c65e28078f9fdc0ce9255605f5c54059b2e893 (patch)
tree65ac77ef2812f603a017fa7c15ce885ac047807c /Lib/unittest
parent30162be9e463df2f9d50dcab14932999e2b5b5fe (diff)
downloadcpython-d7c65e28078f9fdc0ce9255605f5c54059b2e893.zip
cpython-d7c65e28078f9fdc0ce9255605f5c54059b2e893.tar.gz
cpython-d7c65e28078f9fdc0ce9255605f5c54059b2e893.tar.bz2
Removed XXX from unittest.mock docstring and switch to a nicer try...except...finally
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py43
1 files changed, 19 insertions, 24 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index f014c51..e6b103d 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -619,9 +619,7 @@ class NonCallableMock(Base):
def __dir__(self):
- """Filter the output of `dir(mock)` to only useful members.
- XXXX
- """
+ """Filter the output of `dir(mock)` to only useful members."""
extras = self._mock_methods or []
from_type = dir(type(self))
from_dict = list(self.__dict__)
@@ -1057,31 +1055,28 @@ class _patch(object):
@wraps(func)
def patched(*args, **keywargs):
- # could use with statement here
extra_args = []
entered_patchers = []
- # could use try..except...finally here
try:
- try:
- for patching in patched.patchings:
- arg = patching.__enter__()
- entered_patchers.append(patching)
- if patching.attribute_name is not None:
- keywargs.update(arg)
- elif patching.new is DEFAULT:
- extra_args.append(arg)
-
- args += tuple(extra_args)
- return func(*args, **keywargs)
- except:
- if (patching not in entered_patchers and
- _is_started(patching)):
- # the patcher may have been started, but an exception
- # raised whilst entering one of its additional_patchers
- entered_patchers.append(patching)
- # re-raise the exception
- raise
+ for patching in patched.patchings:
+ arg = patching.__enter__()
+ entered_patchers.append(patching)
+ if patching.attribute_name is not None:
+ keywargs.update(arg)
+ elif patching.new is DEFAULT:
+ extra_args.append(arg)
+
+ args += tuple(extra_args)
+ return func(*args, **keywargs)
+ except:
+ if (patching not in entered_patchers and
+ _is_started(patching)):
+ # the patcher may have been started, but an exception
+ # raised whilst entering one of its additional_patchers
+ entered_patchers.append(patching)
+ # re-raise the exception
+ raise
finally:
for patching in reversed(entered_patchers):
patching.__exit__()