summaryrefslogtreecommitdiff
path: root/tests/test_interact.py
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2015-09-20 16:42:12 -0700
committerJeff Quast <contact@jeffquast.com>2015-09-20 16:44:56 -0700
commitdd5cb38f555bf5861e0af33eae8f83a2a6e1e71c (patch)
tree7d4cd15a47ee670eb1e34d6a8dfaf273cd26a4a3 /tests/test_interact.py
parent55b1648932513a16e675ee8534e981a603c08712 (diff)
downloadpexpect-git-dd5cb38f555bf5861e0af33eae8f83a2a6e1e71c.tar.gz
interact tests: prefer getch over echo_w_prompt
this ensures more reliable clean exit, as is necessary in negative test for interact(escape_character=None)
Diffstat (limited to 'tests/test_interact.py')
-rwxr-xr-xtests/test_interact.py61
1 files changed, 20 insertions, 41 deletions
diff --git a/tests/test_interact.py b/tests/test_interact.py
index 6b60f8f..63fc075 100755
--- a/tests/test_interact.py
+++ b/tests/test_interact.py
@@ -41,15 +41,12 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase):
else:
env['PYTHONPATH'] = self.project_dir
- self.interact_py = ' '.join((sys.executable,
- 'interact.py',))
- self.interact_ucs_py = ' '.join((sys.executable,
- 'interact_unicode.py',))
+ self.interact_py = ('{sys.executable} interact.py'.format(sys=sys))
def test_interact_escape(self):
" Ensure `escape_character' value exits interactive mode. "
p = pexpect.spawn(self.interact_py, timeout=5, env=self.env)
- p.expect('<in >')
+ p.expect('READY')
p.sendcontrol(']') # chr(29), the default `escape_character'
# value of pexpect.interact().
p.expect_exact('Escaped interact')
@@ -61,49 +58,31 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase):
" Return only after Termination when `escape_character=None'. "
p = pexpect.spawn('{self.interact_py} --no-escape'.format(self=self),
timeout=5, env=self.env)
- p.expect('<in >')
+ p.expect('READY')
p.sendcontrol(']')
- p.sendline('')
- p.expect('<out>\x1d')
- p.sendcontrol('c')
+ p.expect('29<STOP>')
+ p.send('\x00')
+ p.expect('0<STOP>')
p.expect_exact('Escaped interact')
p.expect(pexpect.EOF)
assert not p.isalive()
assert p.exitstatus == 0
- def test_interact_spawn_eof(self):
- " Ensure subprocess receives EOF and exit. "
- p = pexpect.spawn(self.interact_py, timeout=5, env=self.env)
- p.expect('<in >')
- p.sendline(b'alpha')
- p.sendline(b'beta')
- p.expect(b'<out>alpha')
- p.expect(b'<out>beta')
- p.sendeof()
- # strangely, on travis-ci, sendeof() terminates the subprocess,
- # it doesn't receive ^D, just immediately throws EOF.
- idx = p.expect_exact(['<eof>', pexpect.EOF])
- if idx == 0:
- p.expect_exact('Escaped interact')
- p.expect(pexpect.EOF)
- assert not p.isalive()
- assert p.exitstatus == 0
-
def test_interact_spawnu_eof(self):
- " Ensure subprocess receives unicode, EOF, and exit. "
- p = pexpect.spawnu(self.interact_ucs_py, timeout=5, env=self.env)
- p.expect('<in >')
- p.sendline('ɑlpha')
- p.sendline('Βeta')
- p.expect('<out>ɑlpha')
- p.expect('<out>Βeta')
- p.sendeof()
- # strangely, on travis-ci, sendeof() terminates the subprocess,
- # it doesn't receive ^D, just immediately throws EOF.
- idx = p.expect_exact(['<eof>', pexpect.EOF])
- if idx == 0:
- p.expect_exact('Escaped interact')
- p.expect(pexpect.EOF)
+ " Ensure subprocess receives utf8. "
+ p = pexpect.spawnu('{self.interact_py} --utf8'.format(self=self),
+ timeout=5, env=self.env)
+ p.expect('READY')
+ p.send('ɑ') # >>> map(ord, u'ɑ'.encode('utf8'))
+ p.expect('201<STOP>') # [201, 145]
+ p.expect('145<STOP>')
+ p.send('Β') # >>> map(ord, u'Β'.encode('utf8'))
+ p.expect('206<STOP>') # [206, 146]
+ p.expect('146<STOP>')
+ p.send('\x00')
+ p.expect('0<STOP>')
+ p.expect_exact('Escaped interact')
+ p.expect(pexpect.EOF)
assert not p.isalive()
assert p.exitstatus == 0