green.subprocess: keep CalledProcessError identity; Thanks to Linbing@github
https://github.com/eventlet/eventlet/issues/413
This commit is contained in:
parent
09e166bfbd
commit
5859479208
@ -18,6 +18,7 @@ if sys.version_info > (3, 4):
|
||||
|
||||
patcher.inject('subprocess', globals(), *to_patch)
|
||||
subprocess_orig = patcher.original("subprocess")
|
||||
subprocess_imported = sys.modules['subprocess']
|
||||
mswindows = sys.platform == "win32"
|
||||
|
||||
|
||||
@ -37,6 +38,8 @@ if getattr(subprocess_orig, 'TimeoutExpired', None) is None:
|
||||
def __str__(self):
|
||||
return ("Command '%s' timed out after %s seconds" %
|
||||
(self.cmd, self.timeout))
|
||||
else:
|
||||
TimeoutExpired = subprocess_imported.TimeoutExpired
|
||||
|
||||
|
||||
# This is the meat of this module, the green version of Popen.
|
||||
@ -133,3 +136,8 @@ if hasattr(subprocess_orig, 'check_output'):
|
||||
__patched__.append('check_output')
|
||||
check_output = patched_function(subprocess_orig.check_output)
|
||||
del patched_function
|
||||
|
||||
# Keep exceptions identity.
|
||||
# https://github.com/eventlet/eventlet/issues/413
|
||||
CalledProcessError = subprocess_imported.CalledProcessError
|
||||
del subprocess_imported
|
||||
|
14
tests/isolated/subprocess_exception_identity.py
Normal file
14
tests/isolated/subprocess_exception_identity.py
Normal file
@ -0,0 +1,14 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import subprocess as original
|
||||
from eventlet.green import subprocess as green
|
||||
|
||||
cases = (
|
||||
'CalledProcessError',
|
||||
'TimeoutExpired',
|
||||
)
|
||||
for c in cases:
|
||||
if hasattr(original, c):
|
||||
assert getattr(green, c) is getattr(original, c), c
|
||||
print('pass')
|
@ -93,3 +93,9 @@ def test_check_call_without_timeout_works():
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
|
||||
def test_exception_identity():
|
||||
# https://github.com/eventlet/eventlet/issues/413
|
||||
# green module must keep exceptions classes as stdlib version
|
||||
tests.run_isolated('subprocess_exception_identity.py')
|
||||
|
Loading…
Reference in New Issue
Block a user