Add a way to specify environments in tox

This commit is contained in:
Dave Halter
2017-12-19 19:02:57 +01:00
parent 6780eba157
commit a9ebd92c20
6 changed files with 57 additions and 25 deletions

View File

@@ -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]

View File

@@ -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 = []

View File

@@ -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):