summaryrefslogtreecommitdiff
path: root/tests/test_ctrl_chars.py
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2013-09-22 17:19:02 -0700
committerjquast <contact@jeffquast.com>2013-09-22 17:19:02 -0700
commit31c10159917a1bc91e58b78bdd3fde39d4dd666f (patch)
tree640a093e02930e4d647f74cbef80abd5ad074cd7 /tests/test_ctrl_chars.py
parent9f800f2834fbdfb638ebd5ab4429a3a95c86b799 (diff)
downloadpexpect-git-31c10159917a1bc91e58b78bdd3fde39d4dd666f.tar.gz
correctly test control characters
previously any digit passed ('[0-9]+') -- this is no longer the case -- the number expected by ord() is explicitly matched. Also, notice how p.isalive() returns True even if the child process soon exits -- i wonder if isalive() should recieve a "waitfor=-1" timeout parameter, looping if >0 until False? ah well.
Diffstat (limited to 'tests/test_ctrl_chars.py')
-rwxr-xr-xtests/test_ctrl_chars.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/tests/test_ctrl_chars.py b/tests/test_ctrl_chars.py
index d24ed84..fe0f4ff 100755
--- a/tests/test_ctrl_chars.py
+++ b/tests/test_ctrl_chars.py
@@ -21,6 +21,7 @@ PEXPECT LICENSE
import pexpect
import unittest
import PexpectTestCase
+import time
class TestCtrlChars(PexpectTestCase.PexpectTestCase):
@@ -70,35 +71,38 @@ class TestCtrlChars(PexpectTestCase.PexpectTestCase):
'''This tests that we can send all special control codes by name.
'''
-
child = pexpect.spawn('python getch.py')
- #child.delaybeforesend = 0.1
- for i in 'abcdefghijklmnopqrstuvwxyz':
- assert child.sendcontrol(i) == 1
- child.expect ('[0-9]+\r\n')
- #print child.after
+ child.delaybeforesend = 0.1
+ for ctrl in 'abcdefghijklmnopqrstuvwxyz':
+ assert child.sendcontrol(ctrl) == 1
+ child.expect ('^%d\r\n' % (ord(ctrl) - (ord('a') - 1),), timeout=0.1)
- assert child.sendcontrol('@') == 1
- child.expect ('0\r\n')
- #print child.after
+ # escape character
assert child.sendcontrol('[') == 1
child.expect ('27\r\n')
- #print child.after
assert child.sendcontrol('\\') == 1
child.expect ('28\r\n')
- #print child.after
+ # telnet escape character
assert child.sendcontrol(']') == 1
child.expect ('29\r\n')
- #print child.after
assert child.sendcontrol('^') == 1
child.expect ('30\r\n')
- #print child.after
+ # irc protocol uses this to underline ...
assert child.sendcontrol('_') == 1
child.expect ('31\r\n')
- #print child.after
+ # the real "backspace is delete"
assert child.sendcontrol('?') == 1
child.expect ('127\r\n')
- #print child.after
+ # NUL, same as ctrl + ' '
+ assert child.sendcontrol('@') == 1
+ child.expect ('0\r\n')
+ # 0 is sentinel value to getch.py, assert exit:
+ # causes child to exit, but, if immediately tested,
+ # isalive() still returns True unless an artifical timer
+ # is used.
+ time.sleep(1)
+ assert child.isalive() == False, child.isalive()
+ assert child.exitstatus == 0
if __name__ == '__main__':
unittest.main()