mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-24 06:11:32 +08:00
first import tests for repl completion, #280
This commit is contained in:
@@ -77,8 +77,8 @@ def setup_readline(namespace=__main__.__dict__):
|
|||||||
path, dot, like = interpreter._get_completion_parts()
|
path, dot, like = interpreter._get_completion_parts()
|
||||||
# Shouldn't be an import statement and just a simple path
|
# Shouldn't be an import statement and just a simple path
|
||||||
# with dots.
|
# with dots.
|
||||||
if not re.match('^\s*(import|from) ', text) \
|
is_import = re.match('^\s*(import|from) ', text)
|
||||||
and (not path or re.match('^[\w][\w\d.]*$', path)):
|
if not is_import and (not path or re.match('^[\w][\w\d.]*$', path)):
|
||||||
paths = path.split('.') if path else []
|
paths = path.split('.') if path else []
|
||||||
namespaces = (namespace, builtins.__dict__)
|
namespaces = (namespace, builtins.__dict__)
|
||||||
for p in paths:
|
for p in paths:
|
||||||
@@ -96,7 +96,9 @@ def setup_readline(namespace=__main__.__dict__):
|
|||||||
self.matches.append(path + dot + name)
|
self.matches.append(path + dot + name)
|
||||||
else:
|
else:
|
||||||
completions = interpreter.completions()
|
completions = interpreter.completions()
|
||||||
self.matches = [path + dot + c.name_with_symbols
|
|
||||||
|
before = text[:len(text) - len(like)]
|
||||||
|
self.matches = [before + c.name_with_symbols
|
||||||
for c in completions]
|
for c in completions]
|
||||||
try:
|
try:
|
||||||
return self.matches[state]
|
return self.matches[state]
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class TestSetupReadline():
|
|||||||
del self.namespace['os']
|
del self.namespace['os']
|
||||||
|
|
||||||
def test_import(self):
|
def test_import(self):
|
||||||
assert self.completions('import keyword') == ['keyword']
|
s = 'from os.path import a'
|
||||||
|
assert set(self.completions(s)) == set([s + 'ltsep', s + 'bspath'])
|
||||||
|
|
||||||
def test_colorama(self):
|
def test_colorama(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user