[Python-checkins] cpython (3.5): Issue #25660: Fix a unittest and rlcompleter when readline isn't available
yury.selivanov
python-checkins at python.org
Thu Feb 4 14:08:30 EST 2016
https://hg.python.org/cpython/rev/980ea968444c
changeset: 100158:980ea968444c
branch: 3.5
parent: 100155:64417e7a1760
user: Yury Selivanov <yselivanov at sprymix.com>
date: Thu Feb 04 14:00:26 2016 -0500
summary:
Issue #25660: Fix a unittest and rlcompleter when readline isn't available
files:
Lib/rlcompleter.py | 12 ++++++++----
Lib/test/test_rlcompleter.py | 2 ++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -75,9 +75,12 @@
if not text.strip():
if state == 0:
- readline.insert_text('\t')
- readline.redisplay()
- return ''
+ if _readline_available:
+ readline.insert_text('\t')
+ readline.redisplay()
+ return ''
+ else:
+ return '\t'
else:
return None
@@ -170,10 +173,11 @@
try:
import readline
except ImportError:
- pass
+ _readline_available = False
else:
readline.set_completer(Completer().complete)
# Release references early at shutdown (the readline module's
# contents are quasi-immortal, and the completer function holds a
# reference to globals).
atexit.register(lambda: readline.set_completer(None))
+ _readline_available = True
diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py
--- a/Lib/test/test_rlcompleter.py
+++ b/Lib/test/test_rlcompleter.py
@@ -1,4 +1,5 @@
import unittest
+import unittest.mock
import builtins
import rlcompleter
@@ -77,6 +78,7 @@
self.assertEqual(completer.complete('f.b', 0), 'f.bar')
self.assertEqual(f.calls, 1)
+ @unittest.mock.patch('rlcompleter._readline_available', False)
def test_complete(self):
completer = rlcompleter.Completer()
self.assertEqual(completer.complete('', 0), '\t')
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list