From 3c4e079ecb90f0dc0b1611d60a5f7478293c2dc5 Mon Sep 17 00:00:00 2001 From: David Halter Date: Tue, 8 Jan 2013 12:15:50 +0100 Subject: [PATCH] import jedi in tests and not api --- test/base.py | 4 ++-- test/refactor.py | 8 ++++---- test/regression.py | 34 ++++++++++++++++++---------------- test/run.py | 14 +++++++------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/test/base.py b/test/base.py index 91a19d11..dbb8d010 100644 --- a/test/base.py +++ b/test/base.py @@ -5,10 +5,10 @@ import sys import os 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') -import api +from jedi import api import debug test_sum = 0 diff --git a/test/refactor.py b/test/refactor.py index b20f4d1a..c6de4e3a 100755 --- a/test/refactor.py +++ b/test/refactor.py @@ -6,9 +6,9 @@ import traceback import re import base -from _compatibility import reduce -import api -import refactoring +from jedi._compatibility import reduce +import jedi +from jedi import refactoring 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) 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', '')) args = (script, new_name) if new_name else (script,) refactor_object = refactor_func(*args) diff --git a/test/regression.py b/test/regression.py index 2b655328..78b6f51c 100755 --- a/test/regression.py +++ b/test/regression.py @@ -7,27 +7,29 @@ import itertools import os from base import TestBase -from _compatibility import is_py25, utf8, unicode -import api +from jedi._compatibility import is_py25, utf8, unicode -#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): def test_star_import_cache_duration(self): new = 0.01 - old, api.settings.star_import_cache_validity = \ - api.settings.star_import_cache_validity, new + old, jedi.settings.star_import_cache_validity = \ + jedi.settings.star_import_cache_validity, new - cache = api.cache + cache = jedi.cache cache.star_import_cache = {} # first empty... # 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) - api.Script('', 1, 0, '').complete() + jedi.Script('', 1, 0, '').complete() # reset values - api.settings.star_import_cache_validity = old + jedi.settings.star_import_cache_validity = old length = len(cache.star_import_cache) cache.star_import_cache = {} self.assertEqual(length, 1) @@ -72,7 +74,7 @@ class TestRegression(TestBase): #print 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): r = list(self.get_def("or", (1, 1))) @@ -212,7 +214,7 @@ class TestRegression(TestBase): src2 = 'from .. import setup; setup.ret(1)' # .parser to load the module 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() assert len(result) == 1 assert result[0].description == 'class int' @@ -220,8 +222,8 @@ class TestRegression(TestBase): def test_named_import(self): """ named import - jedi-vim issue #8 """ s = "import time as dt" - assert len(api.Script(s, 1, 15, '/').get_definition()) == 1 - assert len(api.Script(s, 1, 10, '/').get_definition()) == 1 + assert len(jedi.Script(s, 1, 15, '/').get_definition()) == 1 + assert len(jedi.Script(s, 1, 10, '/').get_definition()) == 1 def test_unicode_script(self): """ normally no unicode objects are being used. (<=2.7) """ @@ -322,7 +324,7 @@ class TestFeature(TestBase): # Run quick_complete quick_completions = api._quick_complete(source) # Run real completion - script = api.Script(source, pos[0], pos[1], '') + script = jedi.Script(source, pos[0], pos[1], '') real_completions = script.complete() # Compare results 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) def test_scipy_speed(self): 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() - #print(api.imports.imports_processed) + #print(jedi.imports.imports_processed) if __name__ == '__main__': unittest.main() diff --git a/test/run.py b/test/run.py index 53879eb4..bcc4223a 100755 --- a/test/run.py +++ b/test/run.py @@ -6,10 +6,10 @@ import traceback 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 debug +import jedi +from jedi import debug 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 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()) 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 `#? ` start = index.start() if base.print_debug: - api.set_debug_function(None) + jedi.set_debug_function(None) number += 1 try: 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)) raise 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. should_str = set(r.desc_with_module for r in should_be) if len(should_str) < number: @@ -169,7 +169,7 @@ def run_test(source, f_name, lines_to_execute): # get_definition test path = completion_test_dir + os.path.sep + f_name try: - script = api.Script(source, line_nr, index, path) + script = jedi.Script(source, line_nr, index, path) if test_type == '!': fails += run_goto_test(script, correct, line_nr) elif test_type == '<':