diff options
author | Sergey Shepelev <temotor@gmail.com> | 2017-05-14 13:31:47 +0300 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2017-05-15 05:50:42 +0300 |
commit | 79cda12ba73c2fdbf7ebc01fed3fa15c6cb4c058 (patch) | |
tree | fe395816c7fdc33b7f66676ee8cfd42c9f9a2752 | |
parent | 0ec4df6cbe1771493d112c3f893b8ac1d89b5dbf (diff) | |
download | eventlet-subprocess-413.tar.gz |
green.subprocess: keep CalledProcessError identity; Thanks to Linbing@githubsubprocess-413
https://github.com/eventlet/eventlet/issues/413
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | eventlet/green/subprocess.py | 8 | ||||
-rw-r--r-- | tests/isolated/subprocess_exception_identity.py | 14 | ||||
-rw-r--r-- | tests/subprocess_test.py | 6 |
4 files changed, 29 insertions, 0 deletions
@@ -150,3 +150,4 @@ Thanks To * Yuichi Bando * Feng * Aayush Kasurde +* Linbing diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py index d639cd5..66d1d91 100644 --- a/eventlet/green/subprocess.py +++ b/eventlet/green/subprocess.py @@ -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 diff --git a/tests/isolated/subprocess_exception_identity.py b/tests/isolated/subprocess_exception_identity.py new file mode 100644 index 0000000..24fdadd --- /dev/null +++ b/tests/isolated/subprocess_exception_identity.py @@ -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') diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py index d18c623..9040919 100644 --- a/tests/subprocess_test.py +++ b/tests/subprocess_test.py @@ -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') |