mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
fix static analysis test skips with latest pytest
Latest pytest ensures pytest.skip is being called with a str parameter. However, test_static_analysis passed over the skip parameter which contains a tuple returned from skip_python_version leading to test regression. Unify the version skip reasons for both, static analysis and integration tests by using a shared BaseTestCase parent to avoid code duplication. Furthermore handle test_static_analysis skip_reason extraction orthogonal to test_completion.
This commit is contained in:
committed by
Dave Halter
parent
a0f95fc89f
commit
527ef6fcdd
67
test/run.py
67
test/run.py
@@ -127,6 +127,7 @@ from jedi.api.completion import get_user_context
|
||||
from jedi import parser_utils
|
||||
from jedi.api.environment import get_default_environment, get_system_environment
|
||||
from jedi.inference.gradual.conversion import convert_values
|
||||
from jedi.inference.analysis import Warning
|
||||
|
||||
|
||||
TEST_COMPLETIONS = 0
|
||||
@@ -138,16 +139,8 @@ TEST_USAGES = 3
|
||||
grammar36 = parso.load_grammar(version='3.6')
|
||||
|
||||
|
||||
class IntegrationTestCase(object):
|
||||
def __init__(self, test_type, correct, line_nr, column, start, line,
|
||||
path=None, skip_version_info=None):
|
||||
self.test_type = test_type
|
||||
self.correct = correct
|
||||
self.line_nr = line_nr
|
||||
self.column = column
|
||||
self.start = start
|
||||
self.line = line
|
||||
self.path = path
|
||||
class BaseTestCase(object):
|
||||
def __init__(self, skip_version_info=None):
|
||||
self._skip_version_info = skip_version_info
|
||||
self._skip = None
|
||||
|
||||
@@ -175,6 +168,19 @@ class IntegrationTestCase(object):
|
||||
operator_, min_version[0], min_version[1]
|
||||
)
|
||||
|
||||
|
||||
class IntegrationTestCase(BaseTestCase):
|
||||
def __init__(self, test_type, correct, line_nr, column, start, line,
|
||||
path=None, skip_version_info=None):
|
||||
super(IntegrationTestCase, self).__init__(skip_version_info)
|
||||
self.test_type = test_type
|
||||
self.correct = correct
|
||||
self.line_nr = line_nr
|
||||
self.column = column
|
||||
self.start = start
|
||||
self.line = line
|
||||
self.path = path
|
||||
|
||||
@property
|
||||
def module_name(self):
|
||||
return os.path.splitext(os.path.basename(self.path))[0]
|
||||
@@ -278,6 +284,47 @@ class IntegrationTestCase(object):
|
||||
return compare_cb(self, compare, sorted(wanted))
|
||||
|
||||
|
||||
class StaticAnalysisCase(BaseTestCase):
|
||||
"""
|
||||
Static Analysis cases lie in the static_analysis folder.
|
||||
The tests also start with `#!`, like the goto_definition tests.
|
||||
"""
|
||||
def __init__(self, path):
|
||||
self._path = path
|
||||
self.name = os.path.basename(path)
|
||||
with open(path) as f:
|
||||
self._source = f.read()
|
||||
|
||||
skip_version_info = None
|
||||
for line in self._source.splitlines():
|
||||
skip_version_info = skip_python_version(line) or skip_version_info
|
||||
|
||||
super(StaticAnalysisCase, self).__init__(skip_version_info)
|
||||
|
||||
def collect_comparison(self):
|
||||
cases = []
|
||||
for line_nr, line in enumerate(self._source.splitlines(), 1):
|
||||
match = re.match(r'(\s*)#! (\d+ )?(.*)$', line)
|
||||
if match is not None:
|
||||
column = int(match.group(2) or 0) + len(match.group(1))
|
||||
cases.append((line_nr + 1, column, match.group(3)))
|
||||
return cases
|
||||
|
||||
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]
|
||||
compare_cb(self, analysis, self.collect_comparison())
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (self.__class__.__name__, os.path.basename(self._path))
|
||||
|
||||
|
||||
def skip_python_version(line):
|
||||
# check for python minimal version number
|
||||
match = re.match(r" *# *python *([<>]=?|==) *(\d+(?:\.\d+)?)$", line)
|
||||
|
||||
Reference in New Issue
Block a user