diff options
author | Thomas Kluyver <takowl@gmail.com> | 2013-09-25 18:10:16 -0700 |
---|---|---|
committer | Thomas Kluyver <takowl@gmail.com> | 2013-09-25 18:10:16 -0700 |
commit | 1d218b6cae4a405ec2786a6022feb8e40df2cfa1 (patch) | |
tree | 34532e7854ddbe89dcef3e8b15779a00f3ceb144 | |
parent | a6a7923837e2a9d7129bd69b4ee2bb34cb19f955 (diff) | |
download | pexpect-1d218b6cae4a405ec2786a6022feb8e40df2cfa1.tar.gz |
Fix unicode literals for Python 3.2
-rwxr-xr-x | tests/test_interact.py | 19 | ||||
-rw-r--r-- | tests/test_unicode.py | 52 |
2 files changed, 36 insertions, 35 deletions
diff --git a/tests/test_interact.py b/tests/test_interact.py index 3288b29..022fc63 100755 --- a/tests/test_interact.py +++ b/tests/test_interact.py @@ -20,6 +20,7 @@ PEXPECT LICENSE ''' from __future__ import print_function +from __future__ import unicode_literals import pexpect import unittest @@ -28,7 +29,7 @@ import PexpectTestCase class InteractTestCase (PexpectTestCase.PexpectTestCase): def test_interact (self): - p = pexpect.spawn('%s interact.py' % (self.PYTHONBIN,)) + p = pexpect.spawn(str('%s interact.py' % (self.PYTHONBIN,))) p.sendline (b'Hello') p.sendline (b'there') p.sendline (b'Mr. Python') @@ -42,14 +43,14 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): assert p.exitstatus == 0, (p.exitstatus, p.before) def test_interact_unicode (self): - p = pexpect.spawnu('%s interact_unicode.py' % (self.PYTHONBIN,)) + p = pexpect.spawnu(str('%s interact_unicode.py' % (self.PYTHONBIN,))) try: - p.sendline (u'Hello') - p.sendline (u'theré') - p.sendline (u'Mr. Pyþon') - p.expect (u'Hello') - p.expect (u'theré') - p.expect (u'Mr. Pyþon') + p.sendline ('Hello') + p.sendline ('theré') + p.sendline ('Mr. Pyþon') + p.expect ('Hello') + p.expect ('theré') + p.expect ('Mr. Pyþon') assert p.isalive() p.sendeof () p.expect (pexpect.EOF) @@ -63,5 +64,5 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(InteractTestCase,'test') +suite = unittest.makeSuite(InteractTestCase, 'test') diff --git a/tests/test_unicode.py b/tests/test_unicode.py index 5691664..6b1e5f7 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import with_statement +from __future__ import unicode_literals import platform import tempfile @@ -14,23 +14,23 @@ _CAT_EOF = '^D\x08\x08' class UnicodeTests(PexpectTestCase.PexpectTestCase): def test_expect_basic (self): p = pexpect.spawnu('cat') - p.sendline(u'Hello') - p.sendline(u'there') - p.sendline(u'Mr. þython') # þ is more like th than p, but never mind - p.expect(u'Hello') - p.expect(u'there') - p.expect(u'Mr. þython') + p.sendline('Hello') + p.sendline('there') + p.sendline('Mr. þython') # þ is more like th than p, but never mind + p.expect('Hello') + p.expect('there') + p.expect('Mr. þython') p.sendeof () p.expect (pexpect.EOF) def test_expect_exact_basic (self): p = pexpect.spawnu('cat') - p.sendline(u'Hello') - p.sendline(u'there') - p.sendline(u'Mr. þython') - p.expect_exact(u'Hello') - p.expect_exact(u'there') - p.expect_exact(u'Mr. þython') + p.sendline('Hello') + p.sendline('there') + p.sendline('Mr. þython') + p.expect_exact('Hello') + p.expect_exact('there') + p.expect_exact('Mr. þython') p.sendeof() p.expect_exact (pexpect.EOF) @@ -48,28 +48,28 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): self._expect_echo(p) def _expect_echo (self, p): - p.sendline(u'1234') # Should see this twice (once from tty echo and again from cat). - index = p.expect ([u'1234', u'abcdé', u'wxyz', pexpect.EOF, pexpect.TIMEOUT]) + p.sendline('1234') # Should see this twice (once from tty echo and again from cat). + index = p.expect (['1234', 'abcdé', 'wxyz', pexpect.EOF, pexpect.TIMEOUT]) assert index == 0, (index, p.before) - index = p.expect ([u'1234', u'abcdé', u'wxyz', pexpect.EOF]) + index = p.expect (['1234', 'abcdé', 'wxyz', pexpect.EOF]) assert index == 0, index p.setecho(0) # Turn off tty echo - p.sendline(u'abcdé') # Now, should only see this once. - p.sendline(u'wxyz') # Should also be only once. - index = p.expect ([pexpect.EOF,pexpect.TIMEOUT, u'abcdé', u'wxyz', u'1234']) + p.sendline('abcdé') # Now, should only see this once. + p.sendline('wxyz') # Should also be only once. + index = p.expect ([pexpect.EOF,pexpect.TIMEOUT, 'abcdé', 'wxyz', '1234']) assert index == 2, index - index = p.expect ([pexpect.EOF, u'abcdé', u'wxyz', u'7890']) + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) assert index == 2, index p.setecho(1) # Turn on tty echo - p.sendline (u'7890') # Should see this twice. - index = p.expect ([pexpect.EOF, u'abcdé', u'wxyz', u'7890']) + p.sendline('7890') # Should see this twice. + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) assert index == 3, index - index = p.expect ([pexpect.EOF, u'abcdé', u'wxyz', u'7890']) + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) assert index == 3, index p.sendeof() def test_log_unicode(self): - msg = u"abcΩ÷" + msg = "abcΩ÷" filename_send = tempfile.mktemp() filename_read = tempfile.mktemp() p = pexpect.spawnu('cat') @@ -94,12 +94,12 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): # ensure the 'send' log is correct, with open(filename_send, 'r', encoding='utf-8') as f: - self.assertEqual(f.read(), msg + u'\n\x04') + self.assertEqual(f.read(), msg + '\n\x04') # ensure the 'read' log is correct, with open(filename_read, 'r', encoding='utf-8', newline='') as f: output = f.read().replace(_CAT_EOF, u'') - self.assertEqual(output, (msg + u'\r\n')*2 ) + self.assertEqual(output, (msg + '\r\n')*2 ) def test_spawn_expect_ascii_unicode(self): |