forked from VimPlug/jedi
import jedi in tests and not api
This commit is contained in:
@@ -5,10 +5,10 @@ import sys
|
|||||||
import os
|
import os
|
||||||
from os.path import abspath, dirname
|
from os.path import abspath, dirname
|
||||||
|
|
||||||
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/../jedi'))
|
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/../'))
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
||||||
|
|
||||||
import api
|
from jedi import api
|
||||||
import debug
|
import debug
|
||||||
|
|
||||||
test_sum = 0
|
test_sum = 0
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import traceback
|
|||||||
import re
|
import re
|
||||||
import base
|
import base
|
||||||
|
|
||||||
from _compatibility import reduce
|
from jedi._compatibility import reduce
|
||||||
import api
|
import jedi
|
||||||
import refactoring
|
from jedi import refactoring
|
||||||
|
|
||||||
|
|
||||||
def run_test(source, f_name, lines_to_execute):
|
def run_test(source, f_name, lines_to_execute):
|
||||||
@@ -52,7 +52,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
|
|
||||||
path = os.path.abspath(refactoring_test_dir + os.path.sep + f_name)
|
path = os.path.abspath(refactoring_test_dir + os.path.sep + f_name)
|
||||||
try:
|
try:
|
||||||
script = api.Script(source, line_nr, index, path)
|
script = jedi.Script(source, line_nr, index, path)
|
||||||
refactor_func = getattr(refactoring, f_name.replace('.py', ''))
|
refactor_func = getattr(refactoring, f_name.replace('.py', ''))
|
||||||
args = (script, new_name) if new_name else (script,)
|
args = (script, new_name) if new_name else (script,)
|
||||||
refactor_object = refactor_func(*args)
|
refactor_object = refactor_func(*args)
|
||||||
|
|||||||
@@ -7,27 +7,29 @@ import itertools
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from base import TestBase
|
from base import TestBase
|
||||||
from _compatibility import is_py25, utf8, unicode
|
from jedi._compatibility import is_py25, utf8, unicode
|
||||||
import api
|
|
||||||
|
|
||||||
#api.set_debug_function(api.debug.print_to_stdout)
|
import jedi
|
||||||
|
from jedi import api
|
||||||
|
|
||||||
|
#jedi.set_debug_function(jedi.debug.print_to_stdout)
|
||||||
|
|
||||||
|
|
||||||
class TestRegression(TestBase):
|
class TestRegression(TestBase):
|
||||||
def test_star_import_cache_duration(self):
|
def test_star_import_cache_duration(self):
|
||||||
new = 0.01
|
new = 0.01
|
||||||
old, api.settings.star_import_cache_validity = \
|
old, jedi.settings.star_import_cache_validity = \
|
||||||
api.settings.star_import_cache_validity, new
|
jedi.settings.star_import_cache_validity, new
|
||||||
|
|
||||||
cache = api.cache
|
cache = jedi.cache
|
||||||
cache.star_import_cache = {} # first empty...
|
cache.star_import_cache = {} # first empty...
|
||||||
# path needs to be not-None (otherwise caching effects are not visible)
|
# path needs to be not-None (otherwise caching effects are not visible)
|
||||||
api.Script('', 1, 0, '').complete()
|
jedi.Script('', 1, 0, '').complete()
|
||||||
time.sleep(2 * new)
|
time.sleep(2 * new)
|
||||||
api.Script('', 1, 0, '').complete()
|
jedi.Script('', 1, 0, '').complete()
|
||||||
|
|
||||||
# reset values
|
# reset values
|
||||||
api.settings.star_import_cache_validity = old
|
jedi.settings.star_import_cache_validity = old
|
||||||
length = len(cache.star_import_cache)
|
length = len(cache.star_import_cache)
|
||||||
cache.star_import_cache = {}
|
cache.star_import_cache = {}
|
||||||
self.assertEqual(length, 1)
|
self.assertEqual(length, 1)
|
||||||
@@ -72,7 +74,7 @@ class TestRegression(TestBase):
|
|||||||
#print should2, diff_line
|
#print should2, diff_line
|
||||||
assert should2 == diff_line
|
assert should2 == diff_line
|
||||||
|
|
||||||
self.assertRaises(api.NotFoundError, get_def, cls)
|
self.assertRaises(jedi.NotFoundError, get_def, cls)
|
||||||
|
|
||||||
def test_keyword_doc(self):
|
def test_keyword_doc(self):
|
||||||
r = list(self.get_def("or", (1, 1)))
|
r = list(self.get_def("or", (1, 1)))
|
||||||
@@ -212,7 +214,7 @@ class TestRegression(TestBase):
|
|||||||
src2 = 'from .. import setup; setup.ret(1)'
|
src2 = 'from .. import setup; setup.ret(1)'
|
||||||
# .parser to load the module
|
# .parser to load the module
|
||||||
api.modules.Module(os.path.abspath('dynamic.py'), src2).parser
|
api.modules.Module(os.path.abspath('dynamic.py'), src2).parser
|
||||||
script = api.Script(src1, 1, len(src1), '../setup.py')
|
script = jedi.Script(src1, 1, len(src1), '../setup.py')
|
||||||
result = script.get_definition()
|
result = script.get_definition()
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0].description == 'class int'
|
assert result[0].description == 'class int'
|
||||||
@@ -220,8 +222,8 @@ class TestRegression(TestBase):
|
|||||||
def test_named_import(self):
|
def test_named_import(self):
|
||||||
""" named import - jedi-vim issue #8 """
|
""" named import - jedi-vim issue #8 """
|
||||||
s = "import time as dt"
|
s = "import time as dt"
|
||||||
assert len(api.Script(s, 1, 15, '/').get_definition()) == 1
|
assert len(jedi.Script(s, 1, 15, '/').get_definition()) == 1
|
||||||
assert len(api.Script(s, 1, 10, '/').get_definition()) == 1
|
assert len(jedi.Script(s, 1, 10, '/').get_definition()) == 1
|
||||||
|
|
||||||
def test_unicode_script(self):
|
def test_unicode_script(self):
|
||||||
""" normally no unicode objects are being used. (<=2.7) """
|
""" normally no unicode objects are being used. (<=2.7) """
|
||||||
@@ -322,7 +324,7 @@ class TestFeature(TestBase):
|
|||||||
# Run quick_complete
|
# Run quick_complete
|
||||||
quick_completions = api._quick_complete(source)
|
quick_completions = api._quick_complete(source)
|
||||||
# Run real completion
|
# Run real completion
|
||||||
script = api.Script(source, pos[0], pos[1], '')
|
script = jedi.Script(source, pos[0], pos[1], '')
|
||||||
real_completions = script.complete()
|
real_completions = script.complete()
|
||||||
# Compare results
|
# Compare results
|
||||||
quick_values = [(c.full_name, c.line, c.column) for c in quick_completions]
|
quick_values = [(c.full_name, c.line, c.column) for c in quick_completions]
|
||||||
@@ -358,9 +360,9 @@ class TestSpeed(TestBase):
|
|||||||
@_check_speed(0.1)
|
@_check_speed(0.1)
|
||||||
def test_scipy_speed(self):
|
def test_scipy_speed(self):
|
||||||
s = 'import scipy.weave; scipy.weave.inline('
|
s = 'import scipy.weave; scipy.weave.inline('
|
||||||
script = api.Script(s, 1, len(s), '')
|
script = jedi.Script(s, 1, len(s), '')
|
||||||
script.get_in_function_call()
|
script.get_in_function_call()
|
||||||
#print(api.imports.imports_processed)
|
#print(jedi.imports.imports_processed)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
14
test/run.py
14
test/run.py
@@ -6,10 +6,10 @@ import traceback
|
|||||||
|
|
||||||
import base
|
import base
|
||||||
|
|
||||||
from _compatibility import unicode, StringIO, reduce, literal_eval, is_py25
|
from jedi._compatibility import unicode, StringIO, reduce, literal_eval, is_py25
|
||||||
|
|
||||||
import api
|
import jedi
|
||||||
import debug
|
from jedi import debug
|
||||||
|
|
||||||
|
|
||||||
sys.path.pop(0) # pop again, because it might affect the completion
|
sys.path.pop(0) # pop again, because it might affect the completion
|
||||||
@@ -122,7 +122,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
"""
|
"""
|
||||||
def get_defs(correct, correct_start, path):
|
def get_defs(correct, correct_start, path):
|
||||||
def defs(line_nr, indent):
|
def defs(line_nr, indent):
|
||||||
script = api.Script(source, line_nr, indent, path)
|
script = jedi.Script(source, line_nr, indent, path)
|
||||||
return set(script.get_definition())
|
return set(script.get_definition())
|
||||||
|
|
||||||
should_be = set()
|
should_be = set()
|
||||||
@@ -133,7 +133,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
# -1 for the comment, +3 because of the comment start `#? `
|
# -1 for the comment, +3 because of the comment start `#? `
|
||||||
start = index.start()
|
start = index.start()
|
||||||
if base.print_debug:
|
if base.print_debug:
|
||||||
api.set_debug_function(None)
|
jedi.set_debug_function(None)
|
||||||
number += 1
|
number += 1
|
||||||
try:
|
try:
|
||||||
should_be |= defs(line_nr - 1, start + correct_start)
|
should_be |= defs(line_nr - 1, start + correct_start)
|
||||||
@@ -141,7 +141,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
print('could not resolve %s indent %s' % (line_nr - 1, start))
|
print('could not resolve %s indent %s' % (line_nr - 1, start))
|
||||||
raise
|
raise
|
||||||
if base.print_debug:
|
if base.print_debug:
|
||||||
api.set_debug_function(debug.print_to_stdout)
|
jedi.set_debug_function(debug.print_to_stdout)
|
||||||
# because the objects have different ids, `repr` it, then compare it.
|
# because the objects have different ids, `repr` it, then compare it.
|
||||||
should_str = set(r.desc_with_module for r in should_be)
|
should_str = set(r.desc_with_module for r in should_be)
|
||||||
if len(should_str) < number:
|
if len(should_str) < number:
|
||||||
@@ -169,7 +169,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
# get_definition test
|
# get_definition test
|
||||||
path = completion_test_dir + os.path.sep + f_name
|
path = completion_test_dir + os.path.sep + f_name
|
||||||
try:
|
try:
|
||||||
script = api.Script(source, line_nr, index, path)
|
script = jedi.Script(source, line_nr, index, path)
|
||||||
if test_type == '!':
|
if test_type == '!':
|
||||||
fails += run_goto_test(script, correct, line_nr)
|
fails += run_goto_test(script, correct, line_nr)
|
||||||
elif test_type == '<':
|
elif test_type == '<':
|
||||||
|
|||||||
Reference in New Issue
Block a user