summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2007-12-20 03:10:00 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2007-12-20 03:10:00 +0000
commite701faa47435ad2c5dbbb461160994a98e9b79b3 (patch)
tree7f477d2a8375ec4c5db242c5dcc136c7fede3d19
parentc0a3518dd5f0b7278972ac050f881e52415ba103 (diff)
downloadpexpect-e701faa47435ad2c5dbbb461160994a98e9b79b3.tar.gz
Trying to add coverage for interact() methods.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@502 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/Makefile2
-rw-r--r--pexpect/geert29
-rw-r--r--pexpect/pexpect.py77
-rw-r--r--pexpect/tests/README20
-rwxr-xr-xpexpect/tests/echo_wait.py11
-rwxr-xr-x[-rw-r--r--]pexpect/tests/exit1.py0
-rwxr-xr-xpexpect/tests/interact.py4
-rwxr-xr-x[-rw-r--r--]pexpect/tests/sigwinch_report.py0
-rwxr-xr-xpexpect/tests/swapcase_echo.py6
-rwxr-xr-xpexpect/tests/test_command_list_split.py2
-rwxr-xr-xpexpect/tests/test_ctrl_chars.py20
-rwxr-xr-xpexpect/tests/test_expect.py19
-rwxr-xr-xpexpect/tests/test_interact.py40
-rwxr-xr-xpexpect/tests/test_log.py43
-rwxr-xr-xpexpect/tests/test_misc.py35
-rwxr-xr-xpexpect/tests/test_performance.py74
-rwxr-xr-xpexpect/tests/test_run_out_of_pty.py3
-rw-r--r--pexpect/tools/dotfiles.tar.gz (renamed from pexpect/dotfiles.tar.gz)bin101527 -> 101527 bytes
18 files changed, 310 insertions, 75 deletions
diff --git a/pexpect/Makefile b/pexpect/Makefile
index f2b4730..ef0a158 100644
--- a/pexpect/Makefile
+++ b/pexpect/Makefile
@@ -1,7 +1,7 @@
# TODO This stupid Makefile is getty crappier and crappier. Is 'crappier' a word?
SHELL = /bin/sh
-VERSION=2.2beta
+VERSION=2.3
#DOCGENERATOR= happydoc
DOCGENERATOR=pydoc -w
# This is for GNU Make. This does not work on BSD Make.
diff --git a/pexpect/geert b/pexpect/geert
deleted file mode 100644
index c45928a..0000000
--- a/pexpect/geert
+++ /dev/null
@@ -1,29 +0,0 @@
-Hello Noah,
-
-first of all I would like to thank you for pexpect -- it is great and I
-use it all the time.
-
-A while back I also wrote something in the same functional space: kdesu.
-This also contained a small helper in C++ for interfacing with a
-command-line program through a PTY.
-
-When I read the description of the "echo bug" on your page, and saw how
-you wanted to solve this (by issueing a delay), I remembered that there
-is another way to solve this and this is how I implemented it in kdesu.
-You could add a method to pexpect to i) report on the echo status of the
-PTY, and 2) wait for echo to become off. The latter may require a
-polling loop as I think there is no wait to wait for it (but I am not sure).
-
-The SSH problem you describe could then be solved like this:
-
- child.expect ('[pP]assword:')
- child.wait_echo_off()
- child.sendline (my_password)
-
-I think this is guaranteed to be race-free and in general feels a bit
-cleaner that issueing a delay.
-
-Hope this was useful. In any case keep up the great work with pexpect!
-
-Regards,
-Geert Jansen
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index cb4dd20..f6bb12a 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -84,7 +84,7 @@ except ImportError, e:
A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like operating systems.""")
-__version__ = '2.2'
+__version__ = '2.3'
__revision__ = '$Revision: 399 $'
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which',
'split_command_line', '__version__', '__revision__']
@@ -676,9 +676,18 @@ class spawn (object):
True if the echo mode is off. This returns False if the ECHO flag was
not set False before the timeout. This can be used to detect when the
child is waiting for a password. Usually a child application will turn
- off echo mode when it is waiting for the user to enter a password. It
- timeout is None then this method to block forever until ECHO flag is
- False."""
+ off echo mode when it is waiting for the user to enter a password. For
+ example, instead of expecting the "password:" prompt you can wait for
+ the child to set ECHO off::
+
+ p = pexpect.spawn ('ssh user@example.com')
+ p.waitnoecho()
+ p.sendline(mypassword)
+
+ If timeout is None then this method to block forever until ECHO flag is
+ False.
+
+ """
if timeout == -1:
timeout = self.timeout
@@ -708,7 +717,7 @@ class spawn (object):
"""This sets the terminal echo mode on or off. Note that anything the
child sent before the echo will be lost, so you should be sure that
- your input buffer is empty before you setecho. For example, the
+ your input buffer is empty before you call setecho(). For example, the
following will work as expected::
p = pexpect.spawn('cat')
@@ -743,7 +752,7 @@ class spawn (object):
attr[3] = attr[3] & ~termios.ECHO
# I tried TCSADRAIN and TCSAFLUSH, but these were inconsistent
# and blocked on some platforms. TCSADRAIN is probably ideal if it worked.
- termios.tcsetattr(self.child_fd, termios.TCSANOW, new)
+ termios.tcsetattr(self.child_fd, termios.TCSANOW, attr)
def read_nonblocking (self, size = 1, timeout = -1):
@@ -983,10 +992,10 @@ class spawn (object):
###C return (errno == EWOULDBLOCK) ? n : -1;
#fd = sys.stdin.fileno()
#old = termios.tcgetattr(fd) # remember current state
- #new = termios.tcgetattr(fd)
- #new[3] = new[3] | termios.ICANON # ICANON must be set to recognize EOF
+ #attr = termios.tcgetattr(fd)
+ #attr[3] = attr[3] | termios.ICANON # ICANON must be set to recognize EOF
#try: # use try/finally to ensure state gets restored
- # termios.tcsetattr(fd, termios.TCSADRAIN, new)
+ # termios.tcsetattr(fd, termios.TCSADRAIN, attr)
# if hasattr(termios, 'CEOF'):
# os.write (self.child_fd, '%c' % termios.CEOF)
# else:
@@ -1563,15 +1572,15 @@ class searcher_string (object):
Attributes:
- eof_index - index of EOF, or -1
- timeout_index - index of TIMEOUT, or -1
+ eof_index - index of EOF, or -1
+ timeout_index - index of TIMEOUT, or -1
After a successful match by the search() method the following attributes
are available:
- start - index into the buffer, first byte of match
- end - index into the buffer, first byte after match
- match - the matching string itself
+ start - index into the buffer, first byte of match
+ end - index into the buffer, first byte after match
+ match - the matching string itself
"""
def __init__(self, strings):
@@ -1596,10 +1605,14 @@ class searcher_string (object):
"""This returns a human-readable string that represents the state of
the object."""
- # TODO This should really build the string in list order including EOF and TIMEOUT.
- ss = ['searcher_string'] + [ ' %d: "%s"' % ns for ns in self._strings ]
- if self.eof_index >= 0: ss.append(' %d: EOF' % self.eof_index)
- if self.timeout_index >= 0: ss.append(' %d: TIMEOUT' % self.timeout_index)
+ ss = [ (ns[0],' %d: "%s"' % ns) for ns in self._strings ]
+ ss.append((-1,'searcher_string:'))
+ if self.eof_index >= 0:
+ ss.append ((self.eof_index,' %d: EOF' % self.eof_index))
+ if self.timeout_index >= 0:
+ ss.append ((self.timeout_index,' %d: TIMEOUT' % self.timeout_index))
+ ss.sort()
+ ss = zip(*ss)[1]
return '\n'.join(ss)
def search(self, buffer, freshlen, searchwindowsize=None):
@@ -1650,18 +1663,21 @@ class searcher_string (object):
class searcher_re (object):
- """This is regular expression string search helper for the spawn.expect_any() method.
+ """This is regular expression string search helper for the
+ spawn.expect_any() method.
Attributes:
- eof_index - index of EOF, or -1
- timeout_index - index of TIMEOUT, or -1
+ eof_index - index of EOF, or -1
+ timeout_index - index of TIMEOUT, or -1
After a successful match by the search() method the following attributes
+ are available:
+
+ start - index into the buffer, first byte of match
+ end - index into the buffer, first byte after match
+ match - the re.match object returned by a succesful re.search
- start - index into the buffer, first byte of match
- end - index into the buffer, first byte after match
- match - the re.match object returned by a succesful re.search
"""
def __init__(self, patterns):
@@ -1687,10 +1703,14 @@ class searcher_re (object):
"""This returns a human-readable string that represents the state of
the object."""
- # TODO This should really build the string in list order including EOF and TIMEOUT.
- ss = ['searcher_re'] + [ ' %d: "%s"' % (n, str(s.pattern)) for n, s in self._searches ]
- if self.eof_index >= 0: ss.append(' %d: EOF' % self.eof_index)
- if self.timeout_index >= 0: ss.append(' %d: TIMEOUT' % self.timeout_index)
+ ss = [ (n,' %d: re.compile("%s")' % (n,str(s.pattern))) for n,s in self._searches]
+ ss.append((-1,'searcher_re:'))
+ if self.eof_index >= 0:
+ ss.append ((self.eof_index,' %d: EOF' % self.eof_index))
+ if self.timeout_index >= 0:
+ ss.append ((self.timeout_index,' %d: TIMEOUT' % self.timeout_index))
+ ss.sort()
+ ss = zip(*ss)[1]
return '\n'.join(ss)
def search(self, buffer, freshlen, searchwindowsize=None):
@@ -1704,7 +1724,6 @@ class searcher_re (object):
If there is a match this returns the index of that string, and sets
'start', 'end' and 'match'. Otherwise, returns -1."""
- # TODO, I should double-check that this logic follows the old re.search logic.
absurd_match = len(buffer)
first_match = absurd_match
# 'freshlen' doesn't help here -- we cannot predict the
diff --git a/pexpect/tests/README b/pexpect/tests/README
index 91d1fe7..295632b 100644
--- a/pexpect/tests/README
+++ b/pexpect/tests/README
@@ -1,6 +1,18 @@
-Stuff left to test:
- setwinsize()
- getwinsize()
- mix of patterns and EOF in an expected list.
+The best way to run these tests is from the directory above this one. Source
+the test.env environment file. This will make sure that you are using the
+correct pexpect.py file otherwise Python might try to import a different
+version if it is already installed in this environment. Then run the testall.py
+script in the tools/ directory. This script will automatically build a test
+suite from all the test scripts in the tests/ directory. This allows you to add
+new test scripts simply by dropping them in the tests/ directory. You don't
+have to register the test or do anything else to integrate it into the test
+suite.
+
+For example, this is the normal set of commands you would use to run all tests
+in the tests/ directory:
+
+ $ cd /home/user/pexpect_dev/
+ $ . test.env
+ $ ./tools/testall.py
diff --git a/pexpect/tests/echo_wait.py b/pexpect/tests/echo_wait.py
index 2d27991..1c6c233 100755
--- a/pexpect/tests/echo_wait.py
+++ b/pexpect/tests/echo_wait.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
import signal, time, struct, fcntl, termios, os, sys
# a dumb PAM will print the password prompt first then set ECHO
@@ -9,11 +10,11 @@ import signal, time, struct, fcntl, termios, os, sys
print "fake password:"
sys.stdout.flush()
+time.sleep(3)
attr = termios.tcgetattr(sys.stdout)
attr[3] = attr[3] & ~termios.ECHO
-termios.tcsetattr(sys.stdout, termios.TCSANOW, new)
-time.sleep(3)
+termios.tcsetattr(sys.stdout, termios.TCSANOW, attr)
+time.sleep(12)
attr[3] = attr[3] | termios.ECHO
-termios.tcsetattr(sys.stdout, termios.TCSANOW, new)
-
-time.sleep(20)
+termios.tcsetattr(sys.stdout, termios.TCSANOW, attr)
+time.sleep(2)
diff --git a/pexpect/tests/exit1.py b/pexpect/tests/exit1.py
index 68b82e5..68b82e5 100644..100755
--- a/pexpect/tests/exit1.py
+++ b/pexpect/tests/exit1.py
diff --git a/pexpect/tests/interact.py b/pexpect/tests/interact.py
new file mode 100755
index 0000000..923b66b
--- /dev/null
+++ b/pexpect/tests/interact.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+import pexpect
+p = pexpect.spawn('cat')
+p.interact()
diff --git a/pexpect/tests/sigwinch_report.py b/pexpect/tests/sigwinch_report.py
index c7caf23..c7caf23 100644..100755
--- a/pexpect/tests/sigwinch_report.py
+++ b/pexpect/tests/sigwinch_report.py
diff --git a/pexpect/tests/swapcase_echo.py b/pexpect/tests/swapcase_echo.py
new file mode 100755
index 0000000..03ee922
--- /dev/null
+++ b/pexpect/tests/swapcase_echo.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+import sys
+while True:
+ x = raw_input ()
+ print x.swapcase()
+ sys.stdout.flush()
diff --git a/pexpect/tests/test_command_list_split.py b/pexpect/tests/test_command_list_split.py
index dd0c6f7..e3c6a77 100755
--- a/pexpect/tests/test_command_list_split.py
+++ b/pexpect/tests/test_command_list_split.py
@@ -7,6 +7,8 @@ class SplitCommandLineTestCase(PexpectTestCase.PexpectTestCase):
assert len(pexpect.split_command_line(r'')) == 0
assert len(pexpect.split_command_line(r'one')) == 1
assert len(pexpect.split_command_line(r'one two')) == 2
+ assert len(pexpect.split_command_line(r'one two')) == 2
+ assert len(pexpect.split_command_line(r'one two')) == 2
assert len(pexpect.split_command_line(r'one\ one')) == 1
assert len(pexpect.split_command_line('\'one one\'')) == 1
assert len(pexpect.split_command_line(r'one\"one')) == 1
diff --git a/pexpect/tests/test_ctrl_chars.py b/pexpect/tests/test_ctrl_chars.py
index 38e203a..ebc982b 100755
--- a/pexpect/tests/test_ctrl_chars.py
+++ b/pexpect/tests/test_ctrl_chars.py
@@ -13,17 +13,33 @@ class TestCtrlChars(PexpectTestCase.PexpectTestCase):
to a child process."""
child = pexpect.spawn('python getch.py')
- #child.delaybeforesend = 0.1
try:
for i in range(256):
child.send(chr(i))
child.expect ('%d\r\n' % i)
- #print child.after
except Exception, e:
msg = "Did not echo character value: " + str(i) + "\n"
msg = msg + str(e)
self.fail(msg)
+ def test_sendintr (self):
+ try:
+ child = pexpect.spawn('python getch.py')
+ child.sendintr()
+ child.expect ('3\r\n')
+ except Exception, e:
+ msg = "Did not echo character value: 3\n"
+ msg = msg + str(e)
+ self.fail(msg)
+
+ def test_bad_sendcontrol_chars (self):
+
+ """This tests that sendcontrol will return 0 for an unknown char. """
+
+ child = pexpect.spawn('python getch.py')
+ retval = child.sendcontrol('1')
+ assert retval == 0, "sendcontrol() should have returned 0 because there is no such thing as ctrl-1."
+
def test_sendcontrol(self):
"""This tests that we can send all special control codes by name.
diff --git a/pexpect/tests/test_expect.py b/pexpect/tests/test_expect.py
index 3929192..f7744b4 100755
--- a/pexpect/tests/test_expect.py
+++ b/pexpect/tests/test_expect.py
@@ -2,7 +2,7 @@
import pexpect
import unittest
import commands
-import sys
+import sys, time
import PexpectTestCase
#import pdb
@@ -120,7 +120,22 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
start = time.time()
p1.waitnoecho(timeout=10)
end_time = time.time() - start
- assert end_time < 10 and end_time > 2, "waitnoecho did not set ECHO off in the expected time window"
+ assert end_time < 10 and end_time > 2, "waitnoecho did not set ECHO off in the expected window of time."
+
+ # test that we actually timeout and return False if ECHO is never set off.
+ p1 = pexpect.spawn('cat')
+ start = time.time()
+ retval = p1.waitnoecho(timeout=4)
+ end_time = time.time() - start
+ assert end_time > 3, "waitnoecho should have waited longer than 2 seconds. retval should be False, retval=%d"%retval
+ assert retval==False, "retval should be False, retval=%d"%retval
+
+ # This one is mainly here to test default timeout for code coverage.
+ p1 = pexpect.spawn('%s echo_wait.py' % self.PYTHONBIN)
+ start = time.time()
+ p1.waitnoecho()
+ end_time = time.time() - start
+ assert end_time < 10, "waitnoecho did not set ECHO off in the expected window of time."
def test_expect_echo (self):
"""This tests that echo can be turned on and off.
diff --git a/pexpect/tests/test_interact.py b/pexpect/tests/test_interact.py
new file mode 100755
index 0000000..4397ec9
--- /dev/null
+++ b/pexpect/tests/test_interact.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+import pexpect
+import unittest
+import commands
+import sys, os, time, tty
+import PexpectTestCase
+import thread
+
+def start_interact (p):
+ p.interact()
+
+class InteractTestCase (PexpectTestCase.PexpectTestCase):
+
+ 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)
+ p.sendline ('Hello')
+ p.sendline ('there')
+ p.sendline ('Mr. Python')
+ p.expect ('Hello')
+ p.expect ('there')
+ p.expect ('Mr. Python')
+ p.sendeof ()
+ p.expect (pexpect.EOF)
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(InteractTestCase,'test')
+
diff --git a/pexpect/tests/test_log.py b/pexpect/tests/test_log.py
index d2de205..844be13 100755
--- a/pexpect/tests/test_log.py
+++ b/pexpect/tests/test_log.py
@@ -6,6 +6,7 @@ import tempfile
import PexpectTestCase
class TestCaseLog(PexpectTestCase.PexpectTestCase):
+
def test_log (self):
log_message = 'This is a test.'
filename = tempfile.mktemp()
@@ -19,7 +20,47 @@ class TestCaseLog(PexpectTestCase.PexpectTestCase):
lf = lf[:-2]
os.unlink (filename)
assert lf == log_message
- def test_log2 (self):
+
+ def test_log_logfile_read (self):
+ log_message = 'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open (filename, 'w')
+ p = pexpect.spawn('cat')
+ p.logfile_read = mylog
+ p.sendline(log_message)
+ p.sendeof()
+ p.expect (pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ lf = open(filename).read()
+ lf = lf[:-2]
+ os.unlink (filename)
+ lf = lf.replace(chr(4),'')
+ assert lf == 'This is a test.\r\nThis is a test.', "The read log file has bad data. Note logfile_read should only record what we read from child and nothing else.\n" + repr(lf)
+
+ def test_log_logfile_send (self):
+ log_message = 'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open (filename, 'w')
+ p = pexpect.spawn('cat')
+ p.logfile_send = mylog
+ p.sendline(log_message)
+ p.sendeof()
+ p.expect (pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ lf = open(filename).read()
+ lf = lf[:-2]
+ os.unlink (filename)
+ assert lf == log_message, "The send log file has bad data. Note logfile_send should only record what we sent to child and nothing else."
+
+ def test_log_send_and_received (self):
+
+ """The logfile should have the test message three time -- once for the
+ data we sent. Once for the data that cat echos back as characters are
+ typed. And once for the data that cat prints after we send a linefeed
+ (sent by sendline). """
+
log_message = 'This is a test.'
filename = tempfile.mktemp()
mylog = open (filename, 'w')
diff --git a/pexpect/tests/test_misc.py b/pexpect/tests/test_misc.py
index 64a5bb3..65e274d 100755
--- a/pexpect/tests/test_misc.py
+++ b/pexpect/tests/test_misc.py
@@ -4,6 +4,7 @@ import unittest
import PexpectTestCase
import time
import os
+import re
class TestCaseMisc(PexpectTestCase.PexpectTestCase):
@@ -82,6 +83,28 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
except:
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):
+ """This tests that we get a graceful error when passing bad arguments."""
+ try:
+ p = pexpect.spawn(1)
+ except pexpect.ExceptionPexpect, e:
+ pass
+ except:
+ 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:
+ self.fail ("pexpect.spawn('ls', '-la') should have raised a TypeError.")
+ try:
+ p = pexpect.spawn('cat')
+ p.close()
+ p.read_nonblocking(size=1, timeout=3)
+ except ValueError, e:
+ pass
+ except:
+ self.fail ("read_nonblocking on closed spawn object should have raised a ValueError.")
def test_isalive(self):
child = pexpect.spawn('cat')
assert child.isalive(), "child.isalive() did not return True"
@@ -123,7 +146,17 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
assert wp == None, "Executable should not be found. Returned %s" % wp
os.defpath = p
os.environ['PATH'] = ep
-
+ def test_searcher_re (self):
+ ss = pexpect.searcher_re ([re.compile('this'),re.compile('that'),re.compile('and'),re.compile('the'),re.compile('other')])
+ assert ss.__str__() == 'searcher_re:\n 0: re.compile("this")\n 1: re.compile("that")\n 2: re.compile("and")\n 3: re.compile("the")\n 4: re.compile("other")'
+ ss = pexpect.searcher_re ([pexpect.TIMEOUT,re.compile('this'),re.compile('that'),re.compile('and'),pexpect.EOF,re.compile('other')])
+ assert ss.__str__() == 'searcher_re:\n 0: TIMEOUT\n 1: re.compile("this")\n 2: re.compile("that")\n 3: re.compile("and")\n 4: EOF\n 5: re.compile("other")'
+ def test_searcher_string (self):
+ ss = pexpect.searcher_string (['this','that','and','the','other'])
+ assert ss.__str__() == 'searcher_string:\n 0: "this"\n 1: "that"\n 2: "and"\n 3: "the"\n 4: "other"', repr(ss.__str__())
+ ss = pexpect.searcher_string (['this',pexpect.EOF,'that','and','the','other',pexpect.TIMEOUT])
+ assert ss.__str__() == 'searcher_string:\n 0: "this"\n 1: EOF\n 2: "that"\n 3: "and"\n 4: "the"\n 5: "other"\n 6: TIMEOUT'
+
if __name__ == '__main__':
unittest.main()
diff --git a/pexpect/tests/test_performance.py b/pexpect/tests/test_performance.py
new file mode 100755
index 0000000..883b5db
--- /dev/null
+++ b/pexpect/tests/test_performance.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+# $Id$
+
+import unittest, time
+import pexpect
+import PexpectTestCase
+
+# This isn't exactly a unit test, but it fits in nicely with the rest of the tests.
+
+class PerformanceTestCase (PexpectTestCase.PexpectTestCase):
+
+ """Testing the performance of expect, with emphasis on wading through long
+ inputs. """
+
+ def plain_range(self, n):
+ e = pexpect.spawn('python')
+ self.assertEqual(e.expect('>>>'), 0)
+ e.sendline('for n in range(1, %d+1): print n' % n)
+ self.assertEqual(e.expect(r'\.{3}'), 0)
+ e.sendline('')
+ self.assertEqual(e.expect(['inquisition', '%d' % n]), 1)
+
+ def window_range(self, n):
+ e = pexpect.spawn('python')
+ self.assertEqual(e.expect('>>>'), 0)
+ e.sendline('for n in range(1, %d+1): print n' % n)
+ self.assertEqual(e.expect(r'\.{3}'), 0)
+ e.sendline('')
+ self.assertEqual(e.expect(['inquisition', '%d' % n], searchwindowsize=10), 1)
+
+ def exact_range(self, n):
+ e = pexpect.spawn('python')
+ self.assertEqual(e.expect_exact(['>>>']), 0)
+ e.sendline('for n in range(1, %d+1): print n' % n)
+ self.assertEqual(e.expect_exact(['...']), 0)
+ e.sendline('')
+ self.assertEqual(e.expect_exact(['inquisition', '%d' % n],timeout=520), 1)
+
+ def ewin_range(self, n):
+ e = pexpect.spawn('python')
+ self.assertEqual(e.expect_exact(['>>>']), 0)
+ e.sendline('for n in range(1, %d+1): print n' % n)
+ self.assertEqual(e.expect_exact(['...']), 0)
+ e.sendline('')
+ self.assertEqual(e.expect_exact(['inquisition', '%d' % n], searchwindowsize=10), 1)
+
+ def faster_range(self, n):
+ e = pexpect.spawn('python')
+ self.assertEqual(e.expect('>>>'), 0)
+ e.sendline('range(1, %d+1)' % n)
+ self.assertEqual(e.expect(['inquisition', '%d' % n]), 1)
+
+ def test_100000(self):
+ start_time = time.time()
+ self.plain_range (100000)
+ print "100000 calls to plain_range:", (time.time() - start_time)
+ start_time = time.time()
+ self.window_range(100000)
+ print "100000 calls to window_range:", (time.time() - start_time)
+ start_time = time.time()
+ self.exact_range (100000)
+ print "100000 calls to exact_range:", (time.time() - start_time)
+ start_time = time.time()
+ self.ewin_range (100000)
+ print "100000 calls to ewin_range:", (time.time() - start_time)
+ start_time = time.time()
+ self.faster_range(100000)
+ print "100000 calls to faster_range:", (time.time() - start_time)
+
+if __name__ == "__main__":
+ unittest.main()
+
+suite = unittest.makeSuite(PerformanceTestCase,'test')
diff --git a/pexpect/tests/test_run_out_of_pty.py b/pexpect/tests/test_run_out_of_pty.py
index e182e4d..e80cf0e 100755
--- a/pexpect/tests/test_run_out_of_pty.py
+++ b/pexpect/tests/test_run_out_of_pty.py
@@ -6,7 +6,8 @@ import sys
import PexpectTestCase
class ExpectTestCase(PexpectTestCase.PexpectTestCase):
- def off_test_run_out (self):
+ # This takes too long to run and isn't all that interesting of a test.
+ def OFF_test_run_out_of_pty (self):
"""This assumes that the tested platform has < 10000 pty devices.
This test currently does not work under Solaris.
Under Solaris it runs out of file descriptors first and
diff --git a/pexpect/dotfiles.tar.gz b/pexpect/tools/dotfiles.tar.gz
index 914c30d..914c30d 100644
--- a/pexpect/dotfiles.tar.gz
+++ b/pexpect/tools/dotfiles.tar.gz
Binary files differ