mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
move test bases to test/base.py
This commit is contained in:
38
test/base.py
Normal file
38
test/base.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from os.path import abspath, dirname
|
||||||
|
|
||||||
|
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/../jedi'))
|
||||||
|
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
||||||
|
|
||||||
|
import api
|
||||||
|
|
||||||
|
#api.set_debug_function(api.debug.print_to_stdout)
|
||||||
|
|
||||||
|
|
||||||
|
class TestBase(unittest.TestCase):
|
||||||
|
def get_script(self, src, pos, path=None):
|
||||||
|
if pos is None:
|
||||||
|
lines = src.splitlines()
|
||||||
|
pos = len(lines), len(lines[-1])
|
||||||
|
return api.Script(src, pos[0], pos[1], path)
|
||||||
|
|
||||||
|
def get_def(self, src, pos=None):
|
||||||
|
script = self.get_script(src, pos)
|
||||||
|
return script.get_definition()
|
||||||
|
|
||||||
|
def complete(self, src, pos=None, path=None):
|
||||||
|
script = self.get_script(src, pos, path)
|
||||||
|
return script.complete()
|
||||||
|
|
||||||
|
def goto(self, src, pos=None):
|
||||||
|
script = self.get_script(src, pos)
|
||||||
|
return script.goto()
|
||||||
|
|
||||||
|
def get_in_function_call(self, src, pos=None):
|
||||||
|
script = self.get_script(src, pos)
|
||||||
|
return script.get_in_function_call()
|
||||||
|
|
||||||
|
|
||||||
@@ -1,47 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from os.path import abspath, dirname
|
|
||||||
import time
|
import time
|
||||||
import functools
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
|
import os
|
||||||
|
|
||||||
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/../jedi'))
|
from base import TestBase
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
|
||||||
|
|
||||||
from _compatibility import is_py25, utf8, unicode
|
from _compatibility import is_py25, utf8, unicode
|
||||||
import api
|
import api
|
||||||
|
|
||||||
#api.set_debug_function(api.debug.print_to_stdout)
|
class TestRegression(TestBase):
|
||||||
|
|
||||||
|
|
||||||
class Base(unittest.TestCase):
|
|
||||||
def get_script(self, src, pos, path=None):
|
|
||||||
if pos is None:
|
|
||||||
lines = src.splitlines()
|
|
||||||
pos = len(lines), len(lines[-1])
|
|
||||||
return api.Script(src, pos[0], pos[1], path)
|
|
||||||
|
|
||||||
def get_def(self, src, pos=None):
|
|
||||||
script = self.get_script(src, pos)
|
|
||||||
return script.get_definition()
|
|
||||||
|
|
||||||
def complete(self, src, pos=None, path=None):
|
|
||||||
script = self.get_script(src, pos, path)
|
|
||||||
return script.complete()
|
|
||||||
|
|
||||||
def goto(self, src, pos=None):
|
|
||||||
script = self.get_script(src, pos)
|
|
||||||
return script.goto()
|
|
||||||
|
|
||||||
def get_in_function_call(self, src, pos=None):
|
|
||||||
script = self.get_script(src, pos)
|
|
||||||
return script.get_in_function_call()
|
|
||||||
|
|
||||||
|
|
||||||
class TestRegression(Base):
|
|
||||||
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, api.settings.star_import_cache_validity = \
|
||||||
@@ -317,7 +286,7 @@ class TestRegression(Base):
|
|||||||
self.assertEqual(c[0].complete, 'or')
|
self.assertEqual(c[0].complete, 'or')
|
||||||
|
|
||||||
|
|
||||||
class TestFeature(Base):
|
class TestFeature(TestBase):
|
||||||
def test_full_name(self):
|
def test_full_name(self):
|
||||||
""" feature request #61"""
|
""" feature request #61"""
|
||||||
assert self.complete('import os; os.path.join')[0].full_name \
|
assert self.complete('import os; os.path.join')[0].full_name \
|
||||||
@@ -358,7 +327,7 @@ class TestFeature(Base):
|
|||||||
self.assertEqual(quick_values, real_values)
|
self.assertEqual(quick_values, real_values)
|
||||||
|
|
||||||
|
|
||||||
class TestSpeed(Base):
|
class TestSpeed(TestBase):
|
||||||
def _check_speed(time_per_run, number=4, run_warm=True):
|
def _check_speed(time_per_run, number=4, run_warm=True):
|
||||||
""" Speed checks should typically be very tolerant. Some machines are
|
""" Speed checks should typically be very tolerant. Some machines are
|
||||||
faster than others, but the tests should still pass. These tests are
|
faster than others, but the tests should still pass. These tests are
|
||||||
|
|||||||
Reference in New Issue
Block a user