"""Overridden in subclass using tty"""
return False
+ # For 'with spawn(...) as child:'
+ def __enter__(self):
+ return self
+
+ def __exit__(self, etype, evalue, tb):
+ # We rely on subclasses to implement close(). If they don't, it's not
+ # clear what a context manager should do.
+ self.close()
+
class SpawnBaseUnicode(SpawnBase):
if PY3:
string_type = str
with self.assertRaises(pexpect.EOF):
child.expect('the unexpected')
+ def test_with(self):
+ "spawn can be used as a context manager"
+ with pexpect.spawn(sys.executable + ' echo_w_prompt.py') as p:
+ p.expect('<in >')
+ p.sendline(b'alpha')
+ p.expect(b'<out>alpha')
+ assert p.isalive()
+
+ assert not p.isalive()
+
def test_terminate(self):
" test force terminate always succeeds (SIGKILL). "
child = pexpect.spawn('cat')