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
This commit is contained in:
Tomaz Muraus
2014-11-12 17:30:09 +08:00
parent 2231cabf6c
commit 6d7633366b
2 changed files with 8 additions and 4 deletions

View File

@@ -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):

View File

@@ -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'