summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaz Muraus <tomaz@tomaz.me>2014-11-12 17:30:09 +0800
committerTomaz Muraus <tomaz@tomaz.me>2014-11-12 21:17:29 +0800
commit6d7633366b14575fd7a56e263e253e066c5cd998 (patch)
tree00183cb9109d5ca9e8361482c716b93ae0cfa754
parent2231cabf6caee69b8998f81fefedf8e53b541001 (diff)
downloadeventlet-6d7633366b14575fd7a56e263e253e066c5cd998.tar.gz
Fix __str__ method on the TimeoutExpired exception class. Also fix argument
order in the class constructor so it uses the same order as the actual class from Python 3.3 and above. TimeoutExpired from Python 3.3 takes arguments in the following order: cmd, timeout, output. See https://github.com/python/cpython/blob/master/Lib/subprocess.py#L388
-rw-r--r--eventlet/green/subprocess.py3
-rw-r--r--tests/subprocess_test.py9
2 files changed, 8 insertions, 4 deletions
diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py
index f4d067d..1d7c49a 100644
--- a/eventlet/green/subprocess.py
+++ b/eventlet/green/subprocess.py
@@ -21,8 +21,9 @@ if getattr(subprocess_orig, 'TimeoutExpired', None) is None:
a child process.
"""
- def __init__(self, timeout, cmd, output=None):
+ def __init__(self, cmd, timeout, output=None):
self.cmd = cmd
+ self.timeout = timeout
self.output = output
def __str__(self):
diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py
index 5528bc4..6964a74 100644
--- a/tests/subprocess_test.py
+++ b/tests/subprocess_test.py
@@ -12,13 +12,16 @@ def test_subprocess_wait():
# In Python 3.3 subprocess.Popen.wait() method acquired `timeout`
# argument.
# RHEL backported it to their Python 2.6 package.
- p = subprocess.Popen(
- [sys.executable, "-c", "import time; time.sleep(0.5)"])
+ cmd = [sys.executable, "-c", "import time; time.sleep(0.5)"]
+ p = subprocess.Popen(cmd)
ok = False
t1 = time.time()
try:
p.wait(timeout=0.1)
- except subprocess.TimeoutExpired:
+ except subprocess.TimeoutExpired as e:
+ str(e) # make sure it doesnt throw
+ assert e.cmd == cmd
+ assert e.timeout == 0.1
ok = True
tdiff = time.time() - t1
assert ok, 'did not raise subprocess.TimeoutExpired'