summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2007-12-21 01:56:26 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2007-12-21 01:56:26 +0000
commit9dce98f7f2503fe719bfdb0d8db71395d9661502 (patch)
treea231f9a64b091a4a16efad1d80cb2891e8cd36d0
parente701faa47435ad2c5dbbb461160994a98e9b79b3 (diff)
downloadpexpect-9dce98f7f2503fe719bfdb0d8db71395d9661502.tar.gz
Mang... this is hard. And now two tests are failing. Super terrific...
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@503 656d521f-e311-0410-88e0-e7920216d269
-rwxr-xr-xpexpect/tests/test_interact.py25
-rwxr-xr-xpexpect/tests/test_isalive.py27
-rwxr-xr-xpexpect/tests/test_misc.py10
3 files changed, 53 insertions, 9 deletions
diff --git a/pexpect/tests/test_interact.py b/pexpect/tests/test_interact.py
index 4397ec9..a74b9a2 100755
--- a/pexpect/tests/test_interact.py
+++ b/pexpect/tests/test_interact.py
@@ -5,6 +5,7 @@ import commands
import sys, os, time, tty
import PexpectTestCase
import thread
+import threading
def start_interact (p):
p.interact()
@@ -15,12 +16,30 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase):
# I can't believe this actually works...
p = pexpect.spawn('%s swapcase_echo.py' % self.PYTHONBIN)
mode = tty.tcgetattr(p.STDIN_FILENO)
- thread.start_new_thread (start_interact, (p,))
+ t = threading.Thread (target=start_interact, args=(p,))
+ t.start()
+ #thread.start_new_thread (start_interact, (p,))
time.sleep(1)
p.sendline ('Hello')
- time.sleep(2)
- p.close(force = False)
+ time.sleep(1)
+ try:
+ p.expect ('olleH', timeout=5)
+ except Exception, e:
+ p.close(force = False)
+ tty.tcsetattr(p.STDIN_FILENO, tty.TCSAFLUSH, mode)
+ raise e
+ p.close(force = True)
tty.tcsetattr(p.STDIN_FILENO, tty.TCSAFLUSH, mode)
+# def test_interact_thread (self):
+# # I can't believe this actually works...
+# p = pexpect.spawn('%s swapcase_echo.py' % self.PYTHONBIN)
+# mode = tty.tcgetattr(p.STDIN_FILENO)
+# thread.start_new_thread (start_interact, (p,))
+# time.sleep(1)
+# p.sendline ('Hello')
+# time.sleep(2)
+# p.close(force = False)
+# tty.tcsetattr(p.STDIN_FILENO, tty.TCSAFLUSH, mode)
def test_interact (self):
p = pexpect.spawn('%s interact.py' % self.PYTHONBIN)
diff --git a/pexpect/tests/test_isalive.py b/pexpect/tests/test_isalive.py
index 0183687..68b18c7 100755
--- a/pexpect/tests/test_isalive.py
+++ b/pexpect/tests/test_isalive.py
@@ -5,6 +5,29 @@ import sys, os, time
import PexpectTestCase
class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
+
+ def test_expect_wait (self):
+ """This tests that calling wait on a finished process works as expected.
+ """
+ p = pexpect.spawn('sleep 3')
+ if not p.isalive():
+ self.fail ('Child process is not alive. It should be.')
+ time.sleep(1)
+ p.wait()
+ if p.isalive():
+ self.fail ('Child process is not dead. It should be.')
+ p = pexpect.spawn('sleep 3')
+ if not p.isalive():
+ self.fail ('Child process is not alive. It should be.')
+ p.kill(9)
+ time.sleep(1)
+ try:
+ p.wait()
+ except pexpect.ExceptionPexpect, e:
+ pass
+ else:
+ self.fail ('Should have raised ExceptionPython because you can\'t call wait on a dead process.')
+
def test_expect_isalive_dead_after_normal_termination (self):
p = pexpect.spawn('ls')
p.expect(pexpect.EOF)
@@ -40,8 +63,10 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
### Some platforms allow this. Some reset status after call to waitpid.
def test_expect_isalive_consistent_multiple_calls (self):
+
"""This tests that multiple calls to isalive() return same value.
"""
+
p = pexpect.spawn('cat')
if not p.isalive():
self.fail ('Child process is not alive. It should be.')
@@ -53,7 +78,7 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
self.fail ('Child process is not dead. It should be.')
if p.isalive():
self.fail ('Second call. Child process is not dead. It should be.')
-
+
if __name__ == '__main__':
unittest.main()
diff --git a/pexpect/tests/test_misc.py b/pexpect/tests/test_misc.py
index 65e274d..e0e699d 100755
--- a/pexpect/tests/test_misc.py
+++ b/pexpect/tests/test_misc.py
@@ -80,7 +80,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
child.isalive()
except pexpect.ExceptionPexpect, e:
pass
- except:
+ else:
self.fail ("child.isalive() should have raised a pexpect.ExceptionPexpect")
child.terminated = 1 # Force back to valid state so __del__ won't complain
def test_bad_arguments (self):
@@ -89,13 +89,13 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
p = pexpect.spawn(1)
except pexpect.ExceptionPexpect, e:
pass
- except:
+ else:
self.fail ("pexpect.spawn(1) should have raised a pexpect.ExceptionPexpect.")
try:
p = pexpect.spawn('ls', '-la') # should really use pexpect.spawn('ls', ['-ls'])
except TypeError, e:
pass
- except:
+ else:
self.fail ("pexpect.spawn('ls', '-la') should have raised a TypeError.")
try:
p = pexpect.spawn('cat')
@@ -103,7 +103,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
p.read_nonblocking(size=1, timeout=3)
except ValueError, e:
pass
- except:
+ else:
self.fail ("read_nonblocking on closed spawn object should have raised a ValueError.")
def test_isalive(self):
child = pexpect.spawn('cat')
@@ -117,7 +117,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
child.expect({}) # We don't support dicts yet. Should give TypeError
except TypeError, e:
pass
- except:
+ else:
self.fail ("child.expect({}) should have raised a TypeError")
def test_winsize(self):
child = pexpect.spawn('cat')