diff options
author | Sergey Shepelev <temotor@gmail.com> | 2013-06-10 13:21:38 +0400 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2013-06-13 12:12:19 +0400 |
commit | 25812fca81113e23973dcc6dcef61f8abece77aa (patch) | |
tree | 4bf289001668f82d7762d41d36f21e83ac3cbe6f /tests | |
parent | e11157a442accc322d752889d84ddfce7b7fec93 (diff) | |
download | eventlet-25812fca81113e23973dcc6dcef61f8abece77aa.tar.gz |
tests: subprocess.communicate block on Python 2.7
https://github.com/eventlet/eventlet/pull/24
+ PEP8 fix tabs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/subprocess_test.py | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py index b323ffa..9e94549 100644 --- a/tests/subprocess_test.py +++ b/tests/subprocess_test.py @@ -1,6 +1,7 @@ import eventlet from eventlet.green import subprocess import eventlet.patcher +from nose.plugins.skip import SkipTest import os import sys import time @@ -8,18 +9,37 @@ original_subprocess = eventlet.patcher.original('subprocess') def test_subprocess_wait(): - # https://bitbucket.org/eventlet/eventlet/issue/89 - # 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)"]) - ok = False - t1 = time.time() - try: - p.wait(timeout=0.1) - except subprocess.TimeoutExpired: - ok = True - tdiff = time.time() - t1 - assert ok == True, 'did not raise subprocess.TimeoutExpired' - assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time' + # https://bitbucket.org/eventlet/eventlet/issue/89 + # 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)"]) + ok = False + t1 = time.time() + try: + p.wait(timeout=0.1) + except subprocess.TimeoutExpired: + ok = True + tdiff = time.time() - t1 + assert ok == True, 'did not raise subprocess.TimeoutExpired' + assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time' + + +def test_communicate_with_poll(): + # https://github.com/eventlet/eventlet/pull/24 + # `eventlet.green.subprocess.Popen.communicate()` was broken + # in Python 2.7 because the usage of the `select` module was moved from + # `_communicate` into two other methods `_communicate_with_select` + # and `_communicate_with_poll`. Link to 2.7's implementation: + # http://hg.python.org/cpython/file/2145593d108d/Lib/subprocess.py#l1255 + if getattr(original_subprocess.Popen, '_communicate_with_poll', None) is None: + raise SkipTest('original subprocess.Popen does not have _communicate_with_poll') + + p = subprocess.Popen( + [sys.executable, '-c', 'import time; time.sleep(0.5)'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + t1 = time.time() + eventlet.with_timeout(0.1, p.communicate, timeout_value=True) + tdiff = time.time() - t1 + assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time' |