[Python-checkins] r83719 - in python/branches/py3k: Lib/test/test_rlcompleter.py Lib/test/test_sundry.py Misc/ACKS Misc/NEWS

antoine.pitrou python-checkins at python.org
Wed Aug 4 17:43:16 CEST 2010


Author: antoine.pitrou
Date: Wed Aug  4 17:43:16 2010
New Revision: 83719

Log:
Issue #9496: Provide a test suite for the rlcompleter module.  Patch by
Michele Orrù.



Added:
   python/branches/py3k/Lib/test/test_rlcompleter.py
Modified:
   python/branches/py3k/Lib/test/test_sundry.py
   python/branches/py3k/Misc/ACKS
   python/branches/py3k/Misc/NEWS

Added: python/branches/py3k/Lib/test/test_rlcompleter.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_rlcompleter.py	Wed Aug  4 17:43:16 2010
@@ -0,0 +1,73 @@
+from test import support
+import unittest
+import builtins
+import rlcompleter
+
+class CompleteMe:
+    """ Trivial class used in testing rlcompleter.Completer. """
+    spam = 1
+
+
+class TestRlcompleter(unittest.TestCase):
+    def setUp(self):
+        self.stdcompleter = rlcompleter.Completer()
+        self.completer = rlcompleter.Completer(dict(spam=int,
+                                                    egg=str,
+                                                    CompleteMe=CompleteMe))
+
+        # forces stdcompleter to bind builtins namespace
+        self.stdcompleter.complete('', 0)
+
+    def test_namespace(self):
+        class A(dict):
+            pass
+        class B(list):
+            pass
+
+        self.assertTrue(self.stdcompleter.use_main_ns)
+        self.assertFalse(self.completer.use_main_ns)
+        self.assertFalse(rlcompleter.Completer(A()).use_main_ns)
+        self.assertRaises(TypeError, rlcompleter.Completer, B((1,)))
+
+    def test_global_matches(self):
+        # test with builtins namespace
+        self.assertEqual(self.stdcompleter.global_matches('di'),
+                         [x+'(' for x in dir(builtins) if x.startswith('di')])
+        self.assertEqual(self.stdcompleter.global_matches('st'),
+                         [x+'(' for x in dir(builtins) if x.startswith('st')])
+        self.assertEqual(self.stdcompleter.global_matches('akaksajadhak'), [])
+
+        # test with a customized namespace
+        self.assertEqual(self.completer.global_matches('CompleteM'),
+                         ['CompleteMe('])
+        self.assertEqual(self.completer.global_matches('eg'),
+                         ['egg('])
+        # XXX: see issue5256
+        self.assertEqual(self.completer.global_matches('CompleteM'),
+                         ['CompleteMe('])
+
+    def test_attr_matches(self):
+        # test with builtins namespace
+        self.assertEqual(self.stdcompleter.attr_matches('str.s'),
+                         ['str.{}('.format(x) for x in dir(str)
+                          if x.startswith('s')])
+        self.assertEqual(self.stdcompleter.attr_matches('tuple.foospamegg'), [])
+
+        # test with a customized namespace
+        self.assertEqual(self.completer.attr_matches('CompleteMe.sp'),
+                         ['CompleteMe.spam'])
+        self.assertEqual(self.completer.attr_matches('Completeme.egg'), [])
+
+        CompleteMe.me = CompleteMe
+        self.assertEqual(self.completer.attr_matches('CompleteMe.me.me.sp'),
+                         ['CompleteMe.me.me.spam'])
+        self.assertEqual(self.completer.attr_matches('egg.s'),
+                         ['egg.{}('.format(x) for x in dir(str)
+                          if x.startswith('s')])
+
+def test_main():
+    support.run_unittest(TestRlcompleter)
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k/Lib/test/test_sundry.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sundry.py	(original)
+++ python/branches/py3k/Lib/test/test_sundry.py	Wed Aug  4 17:43:16 2010
@@ -56,7 +56,6 @@
             import os2emxpath
             import pstats
             import py_compile
-            import rlcompleter
             import sndhdr
             import symbol
             import tabnanny

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Wed Aug  4 17:43:16 2010
@@ -591,6 +591,7 @@
 Piet van Oostrum
 Jason Orendorff
 Douglas Orr
+Michele Orrù
 Denis S. Otkidach
 Michael Otteneder
 R. M. Oudkerk

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed Aug  4 17:43:16 2010
@@ -108,6 +108,9 @@
 Tests
 -----
 
+- Issue #9496: Provide a test suite for the rlcompleter module.  Patch by
+  Michele Orrù.
+
 - Issue #8687: provide a test suite for sched.py module.
 
 


More information about the Python-checkins mailing list