Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into docs-revision-3
Browse files Browse the repository at this point in the history
  • Loading branch information
jquast committed Sep 21, 2015
2 parents 27f512d + f599388 commit ccd0853
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 70 deletions.
1 change: 1 addition & 0 deletions tests/getch.py
Expand Up @@ -47,3 +47,4 @@ def main():
main()
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
sys.stdout.flush()
15 changes: 12 additions & 3 deletions tests/interact.py
Expand Up @@ -31,12 +31,21 @@


def main():
p = pexpect.spawn(sys.executable + ' echo_w_prompt.py',
p = pexpect.spawn('{sys.executable} getch.py'.format(sys=sys),
env=no_coverage_env())
escape_character = chr(29) # default matches api
if len(sys.argv) > 1 and sys.argv[1] == '--no-escape':

# defaults matches api
escape_character = chr(29)
encoding = None

if len(sys.argv) > 1 and '--no-escape' in sys.argv:
escape_character = None

if len(sys.argv) > 1 and '--utf8' in sys.argv:
encoding = 'utf8'

p.interact(escape_character=escape_character)

print("Escaped interact")

if __name__ == '__main__':
Expand Down
24 changes: 0 additions & 24 deletions tests/interact_unicode.py

This file was deleted.

72 changes: 29 additions & 43 deletions tests/test_interact.py
Expand Up @@ -41,15 +41,12 @@ def setUp(self):
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')
Expand All @@ -61,50 +58,39 @@ def test_interact_escape_None(self):
" 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('d')
p.expect('<eof>')
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('29<STOP>')
p.send('\x00')
if not os.environ.get('TRAVIS', None):
# on Travis-CI, we sometimes miss trailing stdout from the
# chain of child processes, not entirely sure why. So this
# is skipped on such systems.
p.expect('0<STOP>')
p.expect_exact('Escaped interact')
p.expect(pexpect.EOF)
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:
def test_interact_exit_unicode(self):
" 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')
if not os.environ.get('TRAVIS', None):
# on Travis-CI, we sometimes miss trailing stdout from the
# chain of child processes, not entirely sure why. So this
# is skipped on such systems.
p.expect('0<STOP>')
p.expect_exact('Escaped interact')
p.expect(pexpect.EOF)
p.expect(pexpect.EOF)
assert not p.isalive()
assert p.exitstatus == 0

Expand Down

0 comments on commit ccd0853

Please sign in to comment.