forked from VimPlug/jedi
Do not change cwd at import time
This commit is contained in:
29
test/base.py
29
test/base.py
@@ -4,13 +4,15 @@ import time
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from os.path import abspath, dirname
|
from os.path import abspath, dirname
|
||||||
|
import functools
|
||||||
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/..'))
|
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
|
||||||
|
|
||||||
|
test_dir = dirname(abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
test_sum = 0
|
test_sum = 0
|
||||||
t_start = time.time()
|
t_start = time.time()
|
||||||
# Sorry I didn't use argparse here. It's because argparse is not in the
|
# Sorry I didn't use argparse here. It's because argparse is not in the
|
||||||
@@ -77,3 +79,24 @@ def print_summary():
|
|||||||
(tests_fail, test_sum, time.time() - t_start))
|
(tests_fail, test_sum, time.time() - t_start))
|
||||||
for s in summary:
|
for s in summary:
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
|
|
||||||
|
def cwd_at(path):
|
||||||
|
"""
|
||||||
|
Decorator to run function at `path`.
|
||||||
|
|
||||||
|
:type path: str
|
||||||
|
:arg path: relative path from repository root (e.g., ``'jedi'``).
|
||||||
|
"""
|
||||||
|
def decorator(func):
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(*args, **kwds):
|
||||||
|
try:
|
||||||
|
oldcwd = os.getcwd()
|
||||||
|
repo_root = os.path.dirname(test_dir)
|
||||||
|
os.chdir(os.path.join(repo_root, path))
|
||||||
|
return func(*args, **kwds)
|
||||||
|
finally:
|
||||||
|
os.chdir(oldcwd)
|
||||||
|
return wrapper
|
||||||
|
return decorator
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ def test_dir(refactoring_test_dir):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
refactoring_test_dir = '../test/refactor'
|
refactoring_test_dir = os.path.join(base.test_dir, 'refactor')
|
||||||
test_files = base.get_test_list()
|
test_files = base.get_test_list()
|
||||||
test_dir(refactoring_test_dir)
|
test_dir(refactoring_test_dir)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import functools
|
|||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from base import TestBase
|
from base import TestBase, cwd_at
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi._compatibility import is_py25, utf8, unicode
|
from jedi._compatibility import is_py25, utf8, unicode
|
||||||
@@ -131,6 +131,7 @@ class TestRegression(TestBase):
|
|||||||
assert self.definition("import sys_blabla", (1, 8)) == []
|
assert self.definition("import sys_blabla", (1, 8)) == []
|
||||||
assert len(self.definition("import sys", (1, 8))) == 1
|
assert len(self.definition("import sys", (1, 8))) == 1
|
||||||
|
|
||||||
|
@cwd_at('jedi')
|
||||||
def test_complete_on_empty_import(self):
|
def test_complete_on_empty_import(self):
|
||||||
# should just list the files in the directory
|
# should just list the files in the directory
|
||||||
assert 10 < len(self.complete("from .", path='')) < 30
|
assert 10 < len(self.complete("from .", path='')) < 30
|
||||||
@@ -234,6 +235,7 @@ class TestRegression(TestBase):
|
|||||||
s = """def foo("""
|
s = """def foo("""
|
||||||
assert self.function_definition(s) is None
|
assert self.function_definition(s) is None
|
||||||
|
|
||||||
|
@cwd_at('jedi')
|
||||||
def test_add_dynamic_mods(self):
|
def test_add_dynamic_mods(self):
|
||||||
api.settings.additional_dynamic_modules = ['dynamic.py']
|
api.settings.additional_dynamic_modules = ['dynamic.py']
|
||||||
# Fictional module that defines a function.
|
# Fictional module that defines a function.
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ if __name__ == '__main__':
|
|||||||
test_files = base.get_test_list()
|
test_files = base.get_test_list()
|
||||||
|
|
||||||
# completion tests:
|
# completion tests:
|
||||||
completion_test_dir = '../test/completion'
|
completion_test_dir = os.path.join(base.test_dir, 'completion')
|
||||||
|
|
||||||
# execute tests
|
# execute tests
|
||||||
test_dir(completion_test_dir)
|
test_dir(completion_test_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user