mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Restructure/Refactor has_absolute_import a bit.
This commit is contained in:
@@ -401,7 +401,6 @@ class Module(Scope):
|
|||||||
super(Module, self).__init__(children)
|
super(Module, self).__init__(children)
|
||||||
self._used_names = None
|
self._used_names = None
|
||||||
|
|
||||||
@property
|
|
||||||
def has_explicit_absolute_import(self):
|
def has_explicit_absolute_import(self):
|
||||||
"""
|
"""
|
||||||
Checks if imports in this module are explicitly absolute, i.e. there
|
Checks if imports in this module are explicitly absolute, i.e. there
|
||||||
|
|||||||
@@ -3,34 +3,9 @@ Tests ``from __future__ import absolute_import`` (only important for
|
|||||||
Python 2.X)
|
Python 2.X)
|
||||||
"""
|
"""
|
||||||
import jedi
|
import jedi
|
||||||
from jedi.parser.python import parse
|
|
||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
|
|
||||||
def test_explicit_absolute_imports():
|
|
||||||
"""
|
|
||||||
Detect modules with ``from __future__ import absolute_import``.
|
|
||||||
"""
|
|
||||||
module = parse("from __future__ import absolute_import")
|
|
||||||
assert module.has_explicit_absolute_import
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_explicit_absolute_imports():
|
|
||||||
"""
|
|
||||||
Detect modules without ``from __future__ import absolute_import``.
|
|
||||||
"""
|
|
||||||
assert not parse("1").has_explicit_absolute_import
|
|
||||||
|
|
||||||
|
|
||||||
def test_dont_break_imports_without_namespaces():
|
|
||||||
"""
|
|
||||||
The code checking for ``from __future__ import absolute_import`` shouldn't
|
|
||||||
assume that all imports have non-``None`` namespaces.
|
|
||||||
"""
|
|
||||||
src = "from __future__ import absolute_import\nimport xyzzy"
|
|
||||||
assert parse(src).has_explicit_absolute_import
|
|
||||||
|
|
||||||
|
|
||||||
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
||||||
def test_can_complete_when_shadowing():
|
def test_can_complete_when_shadowing():
|
||||||
script = jedi.Script(path="unittest.py")
|
script = jedi.Script(path="unittest.py")
|
||||||
|
|||||||
29
test/test_parser/test_absolute_import.py
Normal file
29
test/test_parser/test_absolute_import.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
"""
|
||||||
|
Tests ``from __future__ import absolute_import`` (only important for
|
||||||
|
Python 2.X)
|
||||||
|
"""
|
||||||
|
from jedi.parser.python import parse
|
||||||
|
|
||||||
|
|
||||||
|
def test_explicit_absolute_imports():
|
||||||
|
"""
|
||||||
|
Detect modules with ``from __future__ import absolute_import``.
|
||||||
|
"""
|
||||||
|
module = parse("from __future__ import absolute_import")
|
||||||
|
assert module.has_explicit_absolute_import()
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_explicit_absolute_imports():
|
||||||
|
"""
|
||||||
|
Detect modules without ``from __future__ import absolute_import``.
|
||||||
|
"""
|
||||||
|
assert not parse("1").has_explicit_absolute_import()
|
||||||
|
|
||||||
|
|
||||||
|
def test_dont_break_imports_without_namespaces():
|
||||||
|
"""
|
||||||
|
The code checking for ``from __future__ import absolute_import`` shouldn't
|
||||||
|
assume that all imports have non-``None`` namespaces.
|
||||||
|
"""
|
||||||
|
src = "from __future__ import absolute_import\nimport xyzzy"
|
||||||
|
assert parse(src).has_explicit_absolute_import()
|
||||||
Reference in New Issue
Block a user