Skip to content

Commit

Permalink
green.subprocess: keep CalledProcessError identity; Thanks to Linbing…
Browse files Browse the repository at this point in the history
…@github

#413
  • Loading branch information
temoto committed May 15, 2017
1 parent 0ec4df6 commit 79cda12
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ Thanks To
* Yuichi Bando
* Feng
* Aayush Kasurde
* Linbing
8 changes: 8 additions & 0 deletions eventlet/green/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

patcher.inject('subprocess', globals(), *to_patch)
subprocess_orig = patcher.original("subprocess")
subprocess_imported = sys.modules['subprocess']
mswindows = sys.platform == "win32"


Expand All @@ -37,6 +38,8 @@ def __init__(self, cmd, timeout, output=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.
Expand Down Expand Up @@ -133,3 +136,8 @@ def patched_function(function):
__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 changes: 14 additions & 0 deletions tests/isolated/subprocess_exception_identity.py
Original file line number Diff line number Diff line change
@@ -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')
6 changes: 6 additions & 0 deletions tests/subprocess_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 79cda12

Please sign in to comment.