From 60434a7985071687ec2eac8513068d551f9eca25 Mon Sep 17 00:00:00 2001 From: jquast Date: Sun, 22 Sep 2013 07:53:27 -0700 Subject: add unicode test and force str() type in python3 sendline('xyz') in python3 will send unicode, what is expected of the spawn interface is raw bytes. The proper procedure should be to use sendline(b'xyz'). The interact() method of spawnu() is also tested to ensure unicode is accepted (hamsterface!) --- tests/test_interact.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'tests/test_interact.py') diff --git a/tests/test_interact.py b/tests/test_interact.py index d9a86cb..9882a2d 100755 --- a/tests/test_interact.py +++ b/tests/test_interact.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- ''' PEXPECT LICENSE @@ -20,7 +21,7 @@ PEXPECT LICENSE ''' import pexpect import unittest -import sys, os, time, tty +import time, tty import PexpectTestCase import threading @@ -66,14 +67,32 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): def test_interact (self): p = pexpect.spawn('%s interact.py' % self.PYTHONBIN) - p.sendline ('Hello') - p.sendline ('there') - p.sendline ('Mr. Python') - p.expect ('Hello') - p.expect ('there') - p.expect ('Mr. Python') + p.sendline (b'Hello') + p.sendline (b'there') + p.sendline (b'Mr. Python') + p.expect (b'Hello') + p.expect (b'there') + p.expect (b'Mr. Python') + assert p.isalive() == True, p.isalive() p.sendeof () p.expect (pexpect.EOF) + assert p.isalive() == False, p.isalive() + assert p.exitstatus == 0, (p.exitstatus, p.before) + + def test_interact_unicode (self): + p = pexpect.spawnu('%s interact.py' % self.PYTHONBIN) + p.sendline (u'Hello') + p.sendline (u'theré') + p.sendline (u'Mr. Python🐹') + p.expect (u'Hello') + p.expect (u'theré') + p.expect (u'Mr. Python🐹') + assert p.isalive() == True, p.isalive() + p.sendeof () + p.expect (pexpect.EOF) + assert p.isalive() == False, p.isalive() + assert p.exitstatus == 0, (p.exitstatus, p.before) + if __name__ == '__main__': unittest.main() -- cgit v1.2.1