forked from VimPlug/jedi
Add a way to specify environments in tox
This commit is contained in:
12
conftest.py
12
conftest.py
@@ -1,9 +1,12 @@
|
||||
import tempfile
|
||||
import shutil
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import jedi
|
||||
from jedi.api.environment import get_default_environment, get_python_environment
|
||||
from jedi._compatibility import py_version
|
||||
|
||||
collect_ignore = [
|
||||
'setup.py',
|
||||
@@ -75,3 +78,12 @@ def clean_jedi_cache(request):
|
||||
def restore():
|
||||
settings.cache_directory = old
|
||||
shutil.rmtree(tmp)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def environment():
|
||||
version = os.environ.get('JEDI_TEST_ENVIRONMENT', str(py_version))
|
||||
if int(version) == py_version:
|
||||
return get_default_environment()
|
||||
|
||||
return get_python_environment('python%s.%s' % tuple(version))
|
||||
|
||||
@@ -94,13 +94,18 @@ def find_python_environments():
|
||||
if version_string == current_version:
|
||||
yield get_default_environment()
|
||||
else:
|
||||
exe = find_executable('python' + version_string)
|
||||
if exe is not None:
|
||||
path = os.path.dirname(os.path.dirname(exe))
|
||||
try:
|
||||
yield Environment(path, exe)
|
||||
except InvalidPythonEnvironment:
|
||||
pass
|
||||
try:
|
||||
yield get_python_environment('python' + version_string)
|
||||
except InvalidPythonEnvironment:
|
||||
pass
|
||||
|
||||
|
||||
def get_python_environment(python_name):
|
||||
exe = find_executable(python_name)
|
||||
if exe is None:
|
||||
raise InvalidPythonEnvironment("This executable doesn't exist.")
|
||||
path = os.path.dirname(os.path.dirname(exe))
|
||||
return Environment(path, exe)
|
||||
|
||||
|
||||
def create_environment(path):
|
||||
|
||||
@@ -110,8 +110,12 @@ class StaticAnalysisCase(object):
|
||||
cases.append((line_nr + 1, column, match.group(3)))
|
||||
return cases
|
||||
|
||||
def run(self, compare_cb):
|
||||
analysis = jedi.Script(self._source, path=self._path)._analysis()
|
||||
def run(self, compare_cb, environment):
|
||||
analysis = jedi.Script(
|
||||
self._source,
|
||||
path=self._path,
|
||||
environment=environment,
|
||||
)._analysis()
|
||||
typ_str = lambda inst: 'warning ' if isinstance(inst, Warning) else ''
|
||||
analysis = [(r.line, r.column, typ_str(r) + r.name)
|
||||
for r in analysis]
|
||||
|
||||
27
test/run.py
27
test/run.py
@@ -161,27 +161,30 @@ class IntegrationTestCase(object):
|
||||
return '<%s: %s:%s %r>' % (self.__class__.__name__, self.path,
|
||||
self.line_nr_test, self.line.rstrip())
|
||||
|
||||
def script(self):
|
||||
return jedi.Script(self.source, self.line_nr, self.column, self.path)
|
||||
def script(self, environment):
|
||||
return jedi.Script(
|
||||
self.source, self.line_nr, self.column, self.path,
|
||||
environment=environment
|
||||
)
|
||||
|
||||
def run(self, compare_cb):
|
||||
def run(self, compare_cb, environment=None):
|
||||
testers = {
|
||||
TEST_COMPLETIONS: self.run_completion,
|
||||
TEST_DEFINITIONS: self.run_goto_definitions,
|
||||
TEST_ASSIGNMENTS: self.run_goto_assignments,
|
||||
TEST_USAGES: self.run_usages,
|
||||
}
|
||||
return testers[self.test_type](compare_cb)
|
||||
return testers[self.test_type](compare_cb, environment)
|
||||
|
||||
def run_completion(self, compare_cb):
|
||||
completions = self.script().completions()
|
||||
def run_completion(self, compare_cb, environment):
|
||||
completions = self.script(environment).completions()
|
||||
#import cProfile; cProfile.run('script.completions()')
|
||||
|
||||
comp_str = set([c.name for c in completions])
|
||||
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
||||
|
||||
def run_goto_definitions(self, compare_cb):
|
||||
script = self.script()
|
||||
def run_goto_definitions(self, compare_cb, environment):
|
||||
script = self.script(environment)
|
||||
evaluator = script._evaluator
|
||||
|
||||
def comparison(definition):
|
||||
@@ -218,13 +221,13 @@ class IntegrationTestCase(object):
|
||||
is_str = set(comparison(r) for r in result)
|
||||
return compare_cb(self, is_str, should)
|
||||
|
||||
def run_goto_assignments(self, compare_cb):
|
||||
result = self.script().goto_assignments()
|
||||
def run_goto_assignments(self, compare_cb, environment):
|
||||
result = self.script(environment).goto_assignments()
|
||||
comp_str = str(sorted(str(r.description) for r in result))
|
||||
return compare_cb(self, comp_str, self.correct)
|
||||
|
||||
def run_usages(self, compare_cb):
|
||||
result = self.script().usages()
|
||||
def run_usages(self, compare_cb, environment):
|
||||
result = self.script(environment).usages()
|
||||
self.correct = self.correct.strip()
|
||||
compare = sorted((r.module_name, r.line, r.column) for r in result)
|
||||
wanted = []
|
||||
|
||||
@@ -31,19 +31,19 @@ unspecified = %s
|
||||
""" % (case, sorted(d - a), sorted(a - d))
|
||||
|
||||
|
||||
def test_completion(case, monkeypatch):
|
||||
def test_completion(case, monkeypatch, environment):
|
||||
if case.skip is not None:
|
||||
pytest.skip(case.skip)
|
||||
repo_root = helpers.root_dir
|
||||
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
||||
case.run(assert_case_equal)
|
||||
case.run(assert_case_equal, environment)
|
||||
|
||||
|
||||
def test_static_analysis(static_analysis_case):
|
||||
def test_static_analysis(static_analysis_case, environment):
|
||||
if static_analysis_case.skip is not None:
|
||||
pytest.skip(static_analysis_case.skip)
|
||||
else:
|
||||
static_analysis_case.run(assert_static_analysis)
|
||||
static_analysis_case.run(assert_static_analysis, environment)
|
||||
|
||||
|
||||
def test_refactor(refactor_case):
|
||||
|
||||
8
tox.ini
8
tox.ini
@@ -13,6 +13,14 @@ setenv =
|
||||
# https://github.com/tomchristie/django-rest-framework/issues/1957
|
||||
# tox corrupts __pycache__, solution from here:
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
# To test Jedi in different versions than the same Python version, set a
|
||||
# different test environment.
|
||||
env27: JEDI_TEST_ENVIRONMENT=27
|
||||
env33: JEDI_TEST_ENVIRONMENT=33
|
||||
env34: JEDI_TEST_ENVIRONMENT=34
|
||||
env35: JEDI_TEST_ENVIRONMENT=35
|
||||
env36: JEDI_TEST_ENVIRONMENT=36
|
||||
env37: JEDI_TEST_ENVIRONMENT=37
|
||||
commands =
|
||||
py.test {posargs:jedi test}
|
||||
[testenv:py26]
|
||||
|
||||
Reference in New Issue
Block a user