[pypy-svn] pypy default: (fenrir) fix test_rlcompleter

fijal commits-noreply at bitbucket.org
Tue Jan 25 10:05:03 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r41290:ad10e9d0ac0e
Date: 2011-01-25 10:44 +0200
http://bitbucket.org/pypy/pypy/changeset/ad10e9d0ac0e/

Log:	(fenrir) fix test_rlcompleter

diff --git a/lib-python/modified-2.7.0/test/test_rlcompleter.py b/lib-python/modified-2.7.0/test/test_rlcompleter.py
new file mode 100644
--- /dev/null
+++ b/lib-python/modified-2.7.0/test/test_rlcompleter.py
@@ -0,0 +1,73 @@
+from test import test_support as support
+import unittest
+import __builtin__ as builtins
+import rlcompleter
+
+class CompleteMe(object):
+    """ 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(sorted(self.stdcompleter.global_matches('di')),
+                         [x+'(' for x in dir(builtins) if x.startswith('di')])
+        self.assertEqual(sorted(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()


More information about the Pypy-commit mailing list