summaryrefslogtreecommitdiff
path: root/tests/test_timeout_pattern.py
diff options
context:
space:
mode:
authorNoah Spurrier <noah@squaretrade.com>2012-10-26 11:19:10 -0700
committerNoah Spurrier <noah@squaretrade.com>2012-10-26 11:19:10 -0700
commit7999ca657997e78febfb3fb89cfcc066d50bf788 (patch)
tree7ff33465bb4f8f79b92add505d11d4b731dfe6a7 /tests/test_timeout_pattern.py
parent6b65a76c26d72caf0a5b11725750861bf89f2b75 (diff)
downloadpexpect-git-7999ca657997e78febfb3fb89cfcc066d50bf788.tar.gz
Moved everything up one directory level.
Diffstat (limited to 'tests/test_timeout_pattern.py')
-rwxr-xr-xtests/test_timeout_pattern.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/test_timeout_pattern.py b/tests/test_timeout_pattern.py
new file mode 100755
index 0000000..606b045
--- /dev/null
+++ b/tests/test_timeout_pattern.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+'''
+PEXPECT LICENSE
+
+ This license is approved by the OSI and FSF as GPL-compatible.
+ http://opensource.org/licenses/isc-license.txt
+
+ Copyright (c) 2012, Noah Spurrier <noah@noah.org>
+ PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
+ PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
+ COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+'''
+import pexpect
+import unittest
+import sys, os, time
+import PexpectTestCase
+
+class Exp_TimeoutTestCase(PexpectTestCase.PexpectTestCase):
+ def test_matches_exp_timeout (self):
+ '''This tests that we can raise and catch TIMEOUT.
+ '''
+ try:
+ raise pexpect.TIMEOUT("TIMEOUT match test")
+ except pexpect.TIMEOUT:
+ pass
+ #print "Correctly caught TIMEOUT when raising TIMEOUT."
+ else:
+ self.fail('TIMEOUT not caught by an except TIMEOUT clause.')
+
+ def test_pattern_printout (self):
+ '''Verify that a TIMEOUT returns the proper patterns it is trying to match against.
+ Make sure it is returning the pattern from the correct call.'''
+ try:
+ p = pexpect.spawn('cat')
+ p.sendline('Hello')
+ p.expect('Hello')
+ p.expect('Goodbye',timeout=5)
+ except pexpect.TIMEOUT, expTimeoutInst:
+ assert p.match_index == None
+ else:
+ self.fail("Did not generate a TIMEOUT exception.")
+
+ def test_exp_timeout_notThrown (self):
+ '''Verify that a TIMEOUT is not thrown when we match what we expect.'''
+ try:
+ p = pexpect.spawn('cat')
+ p.sendline('Hello')
+ p.expect('Hello')
+ except pexpect.TIMEOUT:
+ self.fail("TIMEOUT caught when it shouldn't be raised because we match the proper pattern.")
+
+ def test_stacktraceMunging (self):
+ '''Verify that the stack trace returned with a TIMEOUT instance does not contain references to pexpect.'''
+ try:
+ p = pexpect.spawn('cat')
+ p.sendline('Hello')
+ p.expect('Goodbye',timeout=5)
+ except pexpect.TIMEOUT, e:
+ if e.get_trace().count("pexpect.py") != 0:
+ self.fail("The TIMEOUT get_trace() referenced pexpect.py. It should only reference the caller.\n"+e.get_trace())
+
+ def test_correctStackTrace (self):
+ '''Verify that the stack trace returned with a TIMEOUT instance correctly handles function calls.'''
+ def nestedFunction (spawnInstance):
+ spawnInstance.expect("junk", timeout=3)
+
+ try:
+ p = pexpect.spawn('cat')
+ p.sendline('Hello')
+ nestedFunction(p)
+ except pexpect.TIMEOUT, e:
+ if e.get_trace().count("nestedFunction") == 0:
+ self.fail("The TIMEOUT get_trace() did not show the call to the nestedFunction function.\n" + str(e) + "\n" + e.get_trace())
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(Exp_TimeoutTestCase,'test')