summaryrefslogtreecommitdiff
path: root/tests/test_interact.py
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2013-09-22 07:53:27 -0700
committerjquast <contact@jeffquast.com>2013-09-22 07:53:27 -0700
commit60434a7985071687ec2eac8513068d551f9eca25 (patch)
treefc15932ea9c64cac633ddb8bd46862d3c423fab0 /tests/test_interact.py
parent53f27279361d2c8b202b7cfcd609cb5fb5710404 (diff)
downloadpexpect-git-60434a7985071687ec2eac8513068d551f9eca25.tar.gz
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!)
Diffstat (limited to 'tests/test_interact.py')
-rwxr-xr-xtests/test_interact.py33
1 files changed, 26 insertions, 7 deletions
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()