From 31c10159917a1bc91e58b78bdd3fde39d4dd666f Mon Sep 17 00:00:00 2001 From: jquast Date: Sun, 22 Sep 2013 17:19:02 -0700 Subject: 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. --- tests/test_ctrl_chars.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'tests') 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() -- cgit v1.2.1