mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Use the Script fixture more generally
This commit is contained in:
@@ -4,26 +4,26 @@ import jedi
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
def test_import_empty():
|
||||
def test_import_empty(Script):
|
||||
""" github #340, return the full word. """
|
||||
completion = jedi.Script("import ").completions()[0]
|
||||
completion = Script("import ").completions()[0]
|
||||
definition = completion.follow_definition()[0]
|
||||
assert definition
|
||||
|
||||
|
||||
def check_follow_definition_types(source):
|
||||
def check_follow_definition_types(Script, source):
|
||||
# nested import
|
||||
completions = jedi.Script(source, path='some_path.py').completions()
|
||||
completions = Script(source, path='some_path.py').completions()
|
||||
defs = chain.from_iterable(c.follow_definition() for c in completions)
|
||||
return [d.type for d in defs]
|
||||
|
||||
|
||||
def test_follow_import_incomplete():
|
||||
def test_follow_import_incomplete(Script):
|
||||
"""
|
||||
Completion on incomplete imports should always take the full completion
|
||||
to do any evaluation.
|
||||
"""
|
||||
datetime = check_follow_definition_types("import itertool")
|
||||
datetime = check_follow_definition_types(Script, "import itertool")
|
||||
assert datetime == ['module']
|
||||
|
||||
# empty `from * import` parts
|
||||
@@ -33,30 +33,30 @@ def test_follow_import_incomplete():
|
||||
assert [d.type for d in definitions[0].follow_definition()] == ['class']
|
||||
|
||||
# incomplete `from * import` part
|
||||
datetime = check_follow_definition_types("from datetime import datetim")
|
||||
datetime = check_follow_definition_types(Script, "from datetime import datetim")
|
||||
assert set(datetime) == set(['class', 'instance']) # py33: builtin and pure py version
|
||||
|
||||
# os.path check
|
||||
ospath = check_follow_definition_types("from os.path import abspat")
|
||||
ospath = check_follow_definition_types(Script, "from os.path import abspat")
|
||||
assert ospath == ['function']
|
||||
|
||||
# alias
|
||||
alias = check_follow_definition_types("import io as abcd; abcd")
|
||||
alias = check_follow_definition_types(Script, "import io as abcd; abcd")
|
||||
assert alias == ['module']
|
||||
|
||||
|
||||
@cwd_at('test/completion/import_tree')
|
||||
def test_follow_definition_nested_import():
|
||||
types = check_follow_definition_types("import pkg.mod1; pkg")
|
||||
def test_follow_definition_nested_import(Script):
|
||||
types = check_follow_definition_types(Script, "import pkg.mod1; pkg")
|
||||
assert types == ['module']
|
||||
|
||||
types = check_follow_definition_types("import pkg.mod1; pkg.mod1")
|
||||
types = check_follow_definition_types(Script, "import pkg.mod1; pkg.mod1")
|
||||
assert types == ['module']
|
||||
|
||||
types = check_follow_definition_types("import pkg.mod1; pkg.mod1.a")
|
||||
types = check_follow_definition_types(Script, "import pkg.mod1; pkg.mod1.a")
|
||||
assert types == ['instance']
|
||||
|
||||
|
||||
def test_follow_definition_land_on_import():
|
||||
types = check_follow_definition_types("import datetime; datetim")
|
||||
def test_follow_definition_land_on_import(Script):
|
||||
types = check_follow_definition_types(Script, "import datetime; datetim")
|
||||
assert types == ['module']
|
||||
|
||||
Reference in New Issue
Block a user