mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Making it possible for static analysis tests to be skipped if the python version doesn't match.
This commit is contained in:
@@ -89,11 +89,15 @@ class StaticAnalysisCase(object):
|
||||
The tests also start with `#!`, like the goto_definition tests.
|
||||
"""
|
||||
def __init__(self, path):
|
||||
self.skip = False
|
||||
self._path = path
|
||||
with open(path) as f:
|
||||
self._source = f.read()
|
||||
|
||||
self.skip = False
|
||||
for line in self._source.splitlines():
|
||||
self.skip = self.skip or run.skip_python_version(line)
|
||||
|
||||
|
||||
def collect_comparison(self):
|
||||
cases = []
|
||||
for line_nr, line in enumerate(self._source.splitlines(), 1):
|
||||
|
||||
31
test/run.py
31
test/run.py
@@ -112,6 +112,7 @@ Tests look like this::
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import operator
|
||||
from ast import literal_eval
|
||||
from io import StringIO
|
||||
from functools import reduce
|
||||
@@ -233,6 +234,26 @@ class IntegrationTestCase(object):
|
||||
return compare_cb(self, compare, sorted(wanted))
|
||||
|
||||
|
||||
def skip_python_version(line):
|
||||
comp_map = {
|
||||
'==': 'eq',
|
||||
'<=': 'le',
|
||||
'>=': 'ge',
|
||||
'<': 'gk',
|
||||
'>': 'lt',
|
||||
}
|
||||
# check for python minimal version number
|
||||
match = re.match(r" *# *python *([<>]=?|==) *(\d+(?:\.\d+)?)$", line)
|
||||
if match:
|
||||
minimal_python_version = tuple(
|
||||
map(int, match.group(2).split(".")))
|
||||
operation = getattr(operator, comp_map[match.group(1)])
|
||||
if not operation(sys.version_info, minimal_python_version):
|
||||
return "Minimal python version %s" % match.group(1)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def collect_file_tests(lines, lines_to_execute):
|
||||
makecase = lambda t: IntegrationTestCase(t, correct, line_nr, column,
|
||||
start, line, path=None, skip=skip)
|
||||
@@ -259,15 +280,7 @@ def collect_file_tests(lines, lines_to_execute):
|
||||
yield makecase(TEST_DEFINITIONS)
|
||||
correct = None
|
||||
else:
|
||||
# check for python minimal version number
|
||||
match = re.match(r" *# *python *>= *(\d+(?:\.\d+)?)$", line)
|
||||
if match:
|
||||
minimal_python_version = tuple(
|
||||
map(int, match.group(1).split(".")))
|
||||
if sys.version_info >= minimal_python_version:
|
||||
skip = None
|
||||
else:
|
||||
skip = "Minimal python version %s" % match.groups(1)
|
||||
skip = skip or skip_python_version(line)
|
||||
try:
|
||||
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]*)', line)
|
||||
# test_type is ? for completion and ! for goto_assignments
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Some special cases of Python 2.
|
||||
"""
|
||||
# python <= 2.7
|
||||
|
||||
# print is syntax:
|
||||
print 1
|
||||
|
||||
@@ -40,6 +40,9 @@ def test_completion(case, monkeypatch):
|
||||
|
||||
|
||||
def test_static_analysis(static_analysis_case):
|
||||
if static_analysis_case.skip is not None:
|
||||
pytest.skip(static_analysis_case.skip)
|
||||
else:
|
||||
static_analysis_case.run(assert_static_analysis)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user