Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b64cc1

Browse files
committed
Make MiniExpect work on Python 3.x.
1 parent 4cf846d commit 0b64cc1

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

lib/matplotlib/testing/util.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import sys
23

34

45
class MiniExpect:
@@ -33,10 +34,11 @@ def sendline(self, line):
3334
"""
3435
Send a line to the process.
3536
"""
37+
line = line.encode('ascii')
3638
self.check_alive()
3739
stdin = self._process.stdin
3840
stdin.write(line)
39-
stdin.write('\n')
41+
stdin.write(b'\n')
4042
stdin.flush()
4143

4244
def expect(self, s, output=None):
@@ -46,15 +48,22 @@ def expect(self, s, output=None):
4648
*output* (optional) is a writable file object where all of the
4749
content preceding *s* will be written.
4850
"""
49-
self.check_alive()
51+
s = s.encode('ascii')
5052
read = self._process.stdout.read
5153
pos = 0
52-
buf = ''
54+
buf = b''
5355
while True:
56+
self.check_alive()
5457
char = read(1)
5558
if not char:
5659
raise IOError("Unexpected end-of-file")
57-
elif char == s[pos]:
60+
61+
if sys.version_info[0] >= 3:
62+
match = (ord(char) == s[pos])
63+
else:
64+
match = (char == s[pos])
65+
66+
if match:
5867
buf += char
5968
pos += 1
6069
if pos == len(s):
@@ -63,5 +72,5 @@ def expect(self, s, output=None):
6372
if output is not None:
6473
output.write(buf)
6574
output.write(char)
66-
buf = ''
75+
buf = b''
6776
pos = 0

0 commit comments

Comments
 (0)