forked from VimPlug/jedi
Rewrite old refactoring tests a bit to reuse them
This commit is contained in:
@@ -45,6 +45,7 @@ class RefactoringCase(object):
|
|||||||
def _collect_file_tests(code, path, lines_to_execute):
|
def _collect_file_tests(code, path, lines_to_execute):
|
||||||
r = r'^# -{5,} ?([^\n]*)\n((?:(?!\n# \+{5,}).)*\n)' \
|
r = r'^# -{5,} ?([^\n]*)\n((?:(?!\n# \+{5,}).)*\n)' \
|
||||||
r'# \+{5,}\n((?:(?!\n# -{5,}).)*\n)'
|
r'# \+{5,}\n((?:(?!\n# -{5,}).)*\n)'
|
||||||
|
match = None
|
||||||
for match in re.finditer(r, code, re.DOTALL | re.MULTILINE):
|
for match in re.finditer(r, code, re.DOTALL | re.MULTILINE):
|
||||||
name = match.group(1).strip()
|
name = match.group(1).strip()
|
||||||
first = match.group(2)
|
first = match.group(2)
|
||||||
@@ -53,17 +54,24 @@ def _collect_file_tests(code, path, lines_to_execute):
|
|||||||
# get the line with the position of the operation
|
# get the line with the position of the operation
|
||||||
p = re.match(r'((?:(?!#\?).)*)#\? (\d*) ?([^\n]*)', first, re.DOTALL)
|
p = re.match(r'((?:(?!#\?).)*)#\? (\d*) ?([^\n]*)', first, re.DOTALL)
|
||||||
if p is None:
|
if p is None:
|
||||||
print("Please add a test start.")
|
raise Exception("Please add a test start.")
|
||||||
continue
|
continue
|
||||||
until = p.group(1)
|
until = p.group(1)
|
||||||
index = int(p.group(2))
|
index = int(p.group(2))
|
||||||
kwargs = eval(p.group(3))
|
if p.group(3):
|
||||||
|
kwargs = eval(p.group(3))
|
||||||
|
else:
|
||||||
|
kwargs = {}
|
||||||
|
|
||||||
line_nr = until.count('\n') + 2
|
line_nr = until.count('\n') + 2
|
||||||
if lines_to_execute and line_nr - 1 not in lines_to_execute:
|
if lines_to_execute and line_nr - 1 not in lines_to_execute:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield RefactoringCase(name, first, line_nr, index, path, kwargs, second)
|
yield RefactoringCase(name, first, line_nr, index, path, kwargs, second)
|
||||||
|
if match is None:
|
||||||
|
raise Exception("Didn't match any test")
|
||||||
|
if match.end() != len(code):
|
||||||
|
raise Exception("Didn't match until the end of the file in %s" % path)
|
||||||
|
|
||||||
|
|
||||||
def collect_dir_tests(base_dir, test_files):
|
def collect_dir_tests(base_dir, test_files):
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
# --- simple
|
# -------------------------------------------------- simple-1
|
||||||
def test():
|
def test():
|
||||||
#? 35 a
|
#? 35 {'new_name': 'a'}
|
||||||
return test(100, (30 + b, c) + 1)
|
return test(100, (30 + b, c) + 1)
|
||||||
|
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def test():
|
def test():
|
||||||
a = (30 + b, c) + 1
|
a = (30 + b, c) + 1
|
||||||
return test(100, a)
|
return test(100, a)
|
||||||
|
|
||||||
|
|
||||||
# --- simple #2
|
# -------------------------------------------------- simple-2
|
||||||
def test():
|
def test():
|
||||||
#? 25 a
|
#? 25 {'new_name': 'a'}
|
||||||
return test(100, (30 + b, c) + 1)
|
return test(100, (30 + b, c) + 1)
|
||||||
|
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def test():
|
def test():
|
||||||
a = 30 + b
|
a = 30 + b
|
||||||
return test(100, (a, c) + 1)
|
return test(100, (a, c) + 1)
|
||||||
|
|
||||||
|
|
||||||
# --- multiline
|
# -------------------------------------------------- multiline-1
|
||||||
def test():
|
def test():
|
||||||
#? 30 x
|
#? 30 {'new_name': 'a'}
|
||||||
return test(1, (30 + b, c)
|
return test(1, (30 + b, c)
|
||||||
+ 1)
|
+ 1)
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def test():
|
def test():
|
||||||
x = ((30 + b, c)
|
x = ((30 + b, c)
|
||||||
+ 1)
|
+ 1)
|
||||||
@@ -33,12 +33,12 @@ def test():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# --- multiline #2
|
# -------------------------------------------------- multiline-2
|
||||||
def test():
|
def test():
|
||||||
#? 25 x
|
#? 25 {'new_name': 'a'}
|
||||||
return test(1, (30 + b, c)
|
return test(1, (30 + b, c)
|
||||||
+ 1)
|
+ 1)
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def test():
|
def test():
|
||||||
x = 30 + b
|
x = 30 + b
|
||||||
return test(1, (x, c)
|
return test(1, (x, c)
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# --- simple
|
# -------------------------------------------------- simple
|
||||||
def test():
|
def test():
|
||||||
#? 4
|
#? 4
|
||||||
a = (30 + b, c) + 1
|
a = (30 + b, c) + 1
|
||||||
return test(100, a)
|
return test(100, a)
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def test():
|
def test():
|
||||||
return test(100, (30 + b, c) + 1)
|
return test(100, (30 + b, c) + 1)
|
||||||
|
|
||||||
|
|
||||||
# --- simple
|
# -------------------------------------------------- simple
|
||||||
if 1:
|
if 1:
|
||||||
#? 4
|
#? 4
|
||||||
a = 1, 2
|
a = 1, 2
|
||||||
return test(100, a)
|
return test(100, a)
|
||||||
# +++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
if 1:
|
if 1:
|
||||||
return test(100, (1, 2))
|
return test(100, (1, 2))
|
||||||
|
|||||||
Reference in New Issue
Block a user