Build in version-dependency in integration tests

If a line is encountered with the comment  or , then the tests are skipped if the current python version is less than the requested one. All tests until the end of the file, or a new comment specifying a compatibe python version are skipped
This commit is contained in:
Claude
2015-12-13 21:42:45 +01:00
parent 5a8c46d509
commit c02668a443

View File

@@ -111,6 +111,7 @@ Tests look like this::
""" """
import os import os
import re import re
import sys
from ast import literal_eval from ast import literal_eval
from io import StringIO from io import StringIO
from functools import reduce from functools import reduce
@@ -127,7 +128,7 @@ TEST_USAGES = 3
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): path=None, skip=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
@@ -135,7 +136,7 @@ class IntegrationTestCase(object):
self.start = start self.start = start
self.line = line self.line = line
self.path = path self.path = path
self.skip = None self.skip = skip
@property @property
def module_name(self): def module_name(self):
@@ -234,10 +235,11 @@ class IntegrationTestCase(object):
def collect_file_tests(lines, lines_to_execute): def collect_file_tests(lines, lines_to_execute):
makecase = lambda t: IntegrationTestCase(t, correct, line_nr, column, makecase = lambda t: IntegrationTestCase(t, correct, line_nr, column,
start, line) start, line, path=None, skip=skip)
start = None start = None
correct = None correct = None
test_type = None test_type = None
skip = 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)
@@ -257,6 +259,15 @@ def collect_file_tests(lines, lines_to_execute):
yield makecase(TEST_DEFINITIONS) yield makecase(TEST_DEFINITIONS)
correct = None correct = None
else: 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)
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