mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Skip tests according to the current environment
This commit is contained in:
55
test/run.py
55
test/run.py
@@ -138,7 +138,7 @@ grammar36 = parso.load_grammar(version='3.6')
|
|||||||
|
|
||||||
class IntegrationTestCase(object):
|
class IntegrationTestCase(object):
|
||||||
def __init__(self, test_type, correct, line_nr, column, start, line,
|
def __init__(self, test_type, correct, line_nr, column, start, line,
|
||||||
path=None, skip=None):
|
path=None, skip_version_info=None):
|
||||||
self.test_type = test_type
|
self.test_type = test_type
|
||||||
self.correct = correct
|
self.correct = correct
|
||||||
self.line_nr = line_nr
|
self.line_nr = line_nr
|
||||||
@@ -146,7 +146,32 @@ class IntegrationTestCase(object):
|
|||||||
self.start = start
|
self.start = start
|
||||||
self.line = line
|
self.line = line
|
||||||
self.path = path
|
self.path = path
|
||||||
self.skip = skip
|
self._skip_version_info = skip_version_info
|
||||||
|
self._skip = None
|
||||||
|
|
||||||
|
def set_skip(self, reason):
|
||||||
|
self._skip = reason
|
||||||
|
|
||||||
|
def get_skip_reason(self, environment):
|
||||||
|
if self._skip is not None:
|
||||||
|
return self._skip
|
||||||
|
|
||||||
|
if self._skip_version_info is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
comp_map = {
|
||||||
|
'==': 'eq',
|
||||||
|
'<=': 'le',
|
||||||
|
'>=': 'ge',
|
||||||
|
'<': 'lt',
|
||||||
|
'>': 'gt',
|
||||||
|
}
|
||||||
|
min_version, operator_ = self._skip_version_info
|
||||||
|
operation = getattr(operator, comp_map[operator_])
|
||||||
|
if not operation(environment.version_info[:2], min_version):
|
||||||
|
return "Python version %s %s.%s" % (
|
||||||
|
operator_, min_version[0], min_version[1]
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module_name(self):
|
def module_name(self):
|
||||||
@@ -249,34 +274,24 @@ class IntegrationTestCase(object):
|
|||||||
|
|
||||||
|
|
||||||
def skip_python_version(line):
|
def skip_python_version(line):
|
||||||
comp_map = {
|
|
||||||
'==': 'eq',
|
|
||||||
'<=': 'le',
|
|
||||||
'>=': 'ge',
|
|
||||||
'<': 'lt',
|
|
||||||
'>': 'gt',
|
|
||||||
}
|
|
||||||
# check for python minimal version number
|
# check for python minimal version number
|
||||||
match = re.match(r" *# *python *([<>]=?|==) *(\d+(?:\.\d+)?)$", line)
|
match = re.match(r" *# *python *([<>]=?|==) *(\d+(?:\.\d+)?)$", line)
|
||||||
if match:
|
if match:
|
||||||
minimal_python_version = tuple(
|
minimal_python_version = tuple(map(int, match.group(2).split(".")))
|
||||||
map(int, match.group(2).split(".")))
|
return minimal_python_version, match.group(1)
|
||||||
operation = getattr(operator, comp_map[match.group(1)])
|
|
||||||
if not operation(sys.version_info, minimal_python_version):
|
|
||||||
return "Minimal python version %s %s" % (match.group(1), match.group(2))
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def collect_file_tests(path, lines, lines_to_execute):
|
def collect_file_tests(path, lines, lines_to_execute):
|
||||||
def makecase(t):
|
def makecase(t):
|
||||||
return IntegrationTestCase(t, correct, line_nr, column,
|
return IntegrationTestCase(t, correct, line_nr, column,
|
||||||
start, line, path=path, skip=skip)
|
start, line, path=path,
|
||||||
|
skip_version_info=skip_version_info)
|
||||||
|
|
||||||
start = None
|
start = None
|
||||||
correct = None
|
correct = None
|
||||||
test_type = None
|
test_type = None
|
||||||
skip = None
|
skip_version_info = None
|
||||||
for line_nr, line in enumerate(lines, 1):
|
for line_nr, line in enumerate(lines, 1):
|
||||||
if correct is not None:
|
if correct is not None:
|
||||||
r = re.match('^(\d+)\s*(.*)$', correct)
|
r = re.match('^(\d+)\s*(.*)$', correct)
|
||||||
@@ -296,7 +311,7 @@ def collect_file_tests(path, lines, lines_to_execute):
|
|||||||
yield makecase(TEST_DEFINITIONS)
|
yield makecase(TEST_DEFINITIONS)
|
||||||
correct = None
|
correct = None
|
||||||
else:
|
else:
|
||||||
skip = skip or skip_python_version(line)
|
skip_version_info = skip_version_info or skip_python_version(line)
|
||||||
try:
|
try:
|
||||||
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]*)', line)
|
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]*)', line)
|
||||||
# test_type is ? for completion and ! for goto_assignments
|
# test_type is ? for completion and ! for goto_assignments
|
||||||
@@ -345,7 +360,7 @@ def collect_dir_tests(base_dir, test_files, check_thirdparty=False):
|
|||||||
lines_to_execute):
|
lines_to_execute):
|
||||||
case.source = source
|
case.source = source
|
||||||
if skip:
|
if skip:
|
||||||
case.skip = skip
|
case.set_skip(skip)
|
||||||
yield case
|
yield case
|
||||||
|
|
||||||
|
|
||||||
@@ -421,7 +436,7 @@ if __name__ == '__main__':
|
|||||||
current = cases[0].path if cases else None
|
current = cases[0].path if cases else None
|
||||||
count = fails = 0
|
count = fails = 0
|
||||||
for c in cases:
|
for c in cases:
|
||||||
if c.skip:
|
if c.get_skip_reason():
|
||||||
continue
|
continue
|
||||||
if current != c.path:
|
if current != c.path:
|
||||||
file_change(current, count, fails)
|
file_change(current, count, fails)
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ unspecified = %s
|
|||||||
|
|
||||||
|
|
||||||
def test_completion(case, monkeypatch, environment, has_typing):
|
def test_completion(case, monkeypatch, environment, has_typing):
|
||||||
if case.skip is not None:
|
skip_reason = case.get_skip_reason(environment)
|
||||||
pytest.skip(case.skip)
|
if skip_reason is not None:
|
||||||
|
pytest.skip(skip_reason)
|
||||||
|
|
||||||
_CONTAINS_TYPING = ('pep0484_typing', 'pep0484_comments', 'pep0526_variables')
|
_CONTAINS_TYPING = ('pep0484_typing', 'pep0484_comments', 'pep0526_variables')
|
||||||
if not has_typing and any(x in case.path for x in _CONTAINS_TYPING):
|
if not has_typing and any(x in case.path for x in _CONTAINS_TYPING):
|
||||||
|
|||||||
Reference in New Issue
Block a user