diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-11-23 23:50:26 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-11-23 23:50:26 (GMT) |
commit | ed92910852ad7a3006bc264ef6cb061868e5a82c (patch) | |
tree | 8b56a31fff59f7fffbdb0f5cb5218025eda534ca /Lib/test | |
parent | bf7b9ede1a7264009f5f35d357112ed3c3c38209 (diff) | |
download | cpython-ed92910852ad7a3006bc264ef6cb061868e5a82c.zip cpython-ed92910852ad7a3006bc264ef6cb061868e5a82c.tar.gz cpython-ed92910852ad7a3006bc264ef6cb061868e5a82c.tar.bz2 |
Issue #25663: Make rlcompleter avoid duplicate global names
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_rlcompleter.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py index 927df34..0b3918b 100644 --- a/Lib/test/test_rlcompleter.py +++ b/Lib/test/test_rlcompleter.py @@ -85,6 +85,27 @@ class TestRlcompleter(unittest.TestCase): self.assertEqual(completer.complete('as', 2), 'assert') self.assertEqual(completer.complete('an', 0), 'and') + def test_duplicate_globals(self): + namespace = { + 'False': None, # Keyword vs builtin vs namespace + 'assert': None, # Keyword vs namespace + 'try': lambda: None, # Keyword vs callable + 'memoryview': None, # Callable builtin vs non-callable + 'Ellipsis': lambda: None, # Non-callable builtin vs callable + } + completer = rlcompleter.Completer(namespace) + self.assertEqual(completer.complete('False', 0), 'False') + self.assertIsNone(completer.complete('False', 1)) # No duplicates + self.assertEqual(completer.complete('assert', 0), 'assert') + self.assertIsNone(completer.complete('assert', 1)) + self.assertEqual(completer.complete('try', 0), 'try') + self.assertIsNone(completer.complete('try', 1)) + # No opening bracket "(" because we overrode the built-in class + self.assertEqual(completer.complete('memoryview', 0), 'memoryview') + self.assertIsNone(completer.complete('memoryview', 1)) + self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis(') + self.assertIsNone(completer.complete('Ellipsis', 1)) + if __name__ == '__main__': unittest.main() |