File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 34
34
from pyrepl .unix_console import UnixConsole , _error
35
35
try :
36
36
unicode
37
+ PY3 = False
37
38
except NameError :
39
+ PY3 = True
38
40
unicode = str
39
41
unichr = chr
40
42
basestring = bytes , str
@@ -207,8 +209,9 @@ def raw_input(self, prompt=''):
207
209
reader .ps1 = prompt
208
210
209
211
ret = reader .readline (startup_hook = self .startup_hook )
210
- if sys . version_info < ( 3 , ) :
212
+ if not PY3 :
211
213
return ret
214
+
212
215
# Unicode/str is required for Python 3 (3.5.2).
213
216
# Ref: https://bitbucket.org/pypy/pyrepl/issues/20/#comment-30647029
214
217
return unicode (ret , ENCODING )
@@ -247,6 +250,9 @@ def get_completer_delims(self):
247
250
248
251
def _histline (self , line ):
249
252
line = line .rstrip ('\n ' )
253
+ if PY3 :
254
+ return line
255
+
250
256
try :
251
257
return unicode (line , ENCODING )
252
258
except UnicodeDecodeError : # bah, silently fall back...
Original file line number Diff line number Diff line change 1
- from pyrepl .readline import _ReadlineWrapper
2
1
import os
3
2
import pty
4
3
import sys
5
4
5
+ import pytest
6
+ from pyrepl .readline import _ReadlineWrapper
7
+
8
+
9
+ @pytest .fixture
10
+ def readline_wrapper ():
11
+ master , slave = pty .openpty ()
12
+ return _ReadlineWrapper (slave , slave )
13
+
14
+
6
15
if sys .version_info < (3 , ):
7
16
bytes_type = str
8
17
unicode_type = unicode # noqa: F821
@@ -43,3 +52,17 @@ def test_raw_input():
43
52
else :
44
53
assert result == 'input'
45
54
assert isinstance (result , unicode_type )
55
+
56
+
57
+ def test_read_history_file (readline_wrapper , tmp_path ):
58
+ histfile = tmp_path / "history"
59
+ histfile .touch ()
60
+
61
+ assert readline_wrapper .reader is None
62
+
63
+ readline_wrapper .read_history_file (str (histfile ))
64
+ assert readline_wrapper .reader .history == []
65
+
66
+ histfile .write_bytes (b"foo\n bar\n " )
67
+ readline_wrapper .read_history_file (str (histfile ))
68
+ assert readline_wrapper .reader .history == ["foo" , "bar" ]
You can’t perform that action at this time.
0 commit comments