One more relative import fix

This commit is contained in:
Dave Halter
2019-03-08 16:01:56 +01:00
parent 1914d10836
commit 5743f54d69
3 changed files with 11 additions and 11 deletions

View File

@@ -67,7 +67,7 @@ class Project(object):
""" """
def py2_comp(path, environment=None, sys_path=None, def py2_comp(path, environment=None, sys_path=None,
smart_sys_path=True, _django=False): smart_sys_path=True, _django=False):
self._path = path self._path = os.path.abspath(path)
if isinstance(environment, SameEnvironment): if isinstance(environment, SameEnvironment):
self._environment = environment self._environment = environment

View File

@@ -217,7 +217,7 @@ def _level_to_base_import_path(project_path, directory, level):
level_import_paths.insert(0, dir_name) level_import_paths.insert(0, dir_name)
d = os.path.dirname(d) d = os.path.dirname(d)
else: else:
return None, d return None, directory
class Importer(object): class Importer(object):

View File

@@ -314,17 +314,14 @@ def test_relative_imports_x(Script):
@cwd_at('test/examples/issue1209/api/whatever/') @cwd_at('test/examples/issue1209/api/whatever/')
def test_relative_imports_without_path(Script): def test_relative_imports_without_path(Script):
script = Script("from . ") project = Project('.', sys_path=[], smart_sys_path=False)
name, import_ = script.completions() script = Script("from . ", _project=project)
assert import_.name == 'import' assert [c.name for c in script.completions()] == ['api_test1', 'import']
assert name.name == 'api_test1'
script = Script("from .. ") script = Script("from .. ", _project=project)
name, import_ = script.completions() assert [c.name for c in script.completions()] == ['import', 'whatever']
assert import_.name == 'whatever'
assert name.name == 'import'
script = Script("from ... ") script = Script("from ... ", _project=project)
assert [c.name for c in script.completions()] == ['api', 'import', 'whatever'] assert [c.name for c in script.completions()] == ['api', 'import', 'whatever']
@@ -347,6 +344,9 @@ def test_relative_import_out_of_file_system(Script):
(5, '/a/b/c', '/a', (None, None)), (5, '/a/b/c', '/a', (None, None)),
(1, '/', '/', ([], '/')), (1, '/', '/', ([], '/')),
(2, '/', '/', (None, None)), (2, '/', '/', (None, None)),
(1, '/a/b', '/a/b/c', (None, '/a/b')),
(2, '/a/b', '/a/b/c', (None, '/a')),
(3, '/a/b', '/a/b/c', (None, '/')),
] ]
) )
def test_level_to_import_path(level, directory, project_path, result): def test_level_to_import_path(level, directory, project_path, result):