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 3434from pyrepl .unix_console import UnixConsole , _error
3535try :
3636 unicode
37+ PY3 = False
3738except NameError :
39+ PY3 = True
3840 unicode = str
3941 unichr = chr
4042 basestring = bytes , str
@@ -207,8 +209,9 @@ def raw_input(self, prompt=''):
207209 reader .ps1 = prompt
208210
209211 ret = reader .readline (startup_hook = self .startup_hook )
210- if sys . version_info < ( 3 , ) :
212+ if not PY3 :
211213 return ret
214+
212215 # Unicode/str is required for Python 3 (3.5.2).
213216 # Ref: https://bitbucket.org/pypy/pyrepl/issues/20/#comment-30647029
214217 return unicode (ret , ENCODING )
@@ -247,6 +250,9 @@ def get_completer_delims(self):
247250
248251 def _histline (self , line ):
249252 line = line .rstrip ('\n ' )
253+ if PY3 :
254+ return line
255+
250256 try :
251257 return unicode (line , ENCODING )
252258 except UnicodeDecodeError : # bah, silently fall back...
Original file line number Diff line number Diff line change 1- from pyrepl .readline import _ReadlineWrapper
21import os
32import pty
43import sys
54
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+
615if sys .version_info < (3 , ):
716 bytes_type = str
817 unicode_type = unicode # noqa: F821
@@ -43,3 +52,17 @@ def test_raw_input():
4352 else :
4453 assert result == 'input'
4554 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