]> granicus.if.org Git - python/commitdiff
Issue #25660: Fix a unittest and rlcompleter when readline isn't available
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 4 Feb 2016 19:00:26 +0000 (14:00 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 4 Feb 2016 19:00:26 +0000 (14:00 -0500)
Lib/rlcompleter.py
Lib/test/test_rlcompleter.py

index 26f59208bb484ab9b82731b925df81fb7f601b0f..401a62617985ddc0b547aa86577934aa331a09d6 100644 (file)
@@ -75,9 +75,12 @@ class Completer:
 
         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 @@ def get_class_members(klass):
 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
index 2d5d9c1f70b5049cce7fe58fc9b459ba3ffd7ff0..853e77330aa0fe0f4cc7bd64fea516be1d7ead54 100644 (file)
@@ -1,4 +1,5 @@
 import unittest
+import unittest.mock
 import builtins
 import rlcompleter
 
@@ -77,6 +78,7 @@ class TestRlcompleter(unittest.TestCase):
         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')