forked from VimPlug/jedi
finished testing script for refactoring
This commit is contained in:
@@ -27,7 +27,6 @@ class Refactoring(object):
|
|||||||
def diff(self):
|
def diff(self):
|
||||||
texts = []
|
texts = []
|
||||||
for old_path, (new_path, old_l, new_l) in self.change_dct.items():
|
for old_path, (new_path, old_l, new_l) in self.change_dct.items():
|
||||||
print old_path, new_path, old_l, new_l
|
|
||||||
if old_path:
|
if old_path:
|
||||||
udiff = difflib.unified_diff(old_l, new_l)
|
udiff = difflib.unified_diff(old_l, new_l)
|
||||||
else:
|
else:
|
||||||
@@ -107,9 +106,7 @@ def extract(script, new_name):
|
|||||||
positions = [s] + call.execution.arr_el_pos + [exe.end_pos]
|
positions = [s] + call.execution.arr_el_pos + [exe.end_pos]
|
||||||
start_pos = positions[index]
|
start_pos = positions[index]
|
||||||
end_pos = positions[index + 1][0], positions[index + 1][1] - 1
|
end_pos = positions[index + 1][0], positions[index + 1][1] - 1
|
||||||
print start_pos, end_pos
|
|
||||||
text = new_lines[start_pos[0] - 1][start_pos[1]:end_pos[1]]
|
text = new_lines[start_pos[0] - 1][start_pos[1]:end_pos[1]]
|
||||||
print text
|
|
||||||
for l in range(start_pos[0], end_pos[0] - 1):
|
for l in range(start_pos[0], end_pos[0] - 1):
|
||||||
text
|
text
|
||||||
new_lines[start_pos[0]:end_pos[0]-1]
|
new_lines[start_pos[0]:end_pos[0]-1]
|
||||||
|
|||||||
@@ -30,18 +30,23 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
s = unicode(source)
|
s = unicode(source)
|
||||||
# parse the refactor format
|
# parse the refactor format
|
||||||
r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \
|
r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \
|
||||||
r'\n# \+\+\+((?:(?!\n# \+\+\+).)*)'
|
r'\n# \+\+\+((?:(?!\n# ---).)*)'
|
||||||
for match in re.finditer(r, s, re.DOTALL | re.MULTILINE):
|
for match in re.finditer(r, s, re.DOTALL | re.MULTILINE):
|
||||||
name = match.group(1).strip()
|
name = match.group(1).strip()
|
||||||
first = match.group(2).strip()
|
first = match.group(2).strip()
|
||||||
second = match.group(3).strip()
|
second = match.group(3).strip()
|
||||||
|
start_line_test = s[:match.start()].count('\n') + 1
|
||||||
|
|
||||||
# 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)
|
||||||
until_pos = p.group(1)
|
if p is None:
|
||||||
index = p.group(2)
|
print("Please add a test start.")
|
||||||
|
continue
|
||||||
|
until = p.group(1)
|
||||||
|
index = int(p.group(2))
|
||||||
new_name = p.group(3)
|
new_name = p.group(3)
|
||||||
line_nr = until_pos.count('\n')
|
|
||||||
|
line_nr = start_line_test + until.count('\n') + 2
|
||||||
|
|
||||||
path = refactoring_test_dir + os.path.sep + f_name
|
path = refactoring_test_dir + os.path.sep + f_name
|
||||||
try:
|
try:
|
||||||
@@ -49,9 +54,27 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
refactor_func = getattr(refactoring, f_name.replace('.py', ''))
|
refactor_func = getattr(refactoring, f_name.replace('.py', ''))
|
||||||
args = (script, new_name) if new_name else (script,)
|
args = (script, new_name) if new_name else (script,)
|
||||||
refactor_object = refactor_func(*args)
|
refactor_object = refactor_func(*args)
|
||||||
print refactor_object.new_files()
|
|
||||||
if second != refactor_object.new_files:
|
# try to get the right excerpt of the newfile
|
||||||
|
f = refactor_object.new_files()[path]
|
||||||
|
lines = f.splitlines()[start_line_test:]
|
||||||
|
|
||||||
|
end = start_line_test + len(lines)
|
||||||
|
pop_start = None
|
||||||
|
for i, l in enumerate(lines):
|
||||||
|
if l.startswith('# +++'):
|
||||||
|
end = i
|
||||||
|
break
|
||||||
|
elif '#? ' in l:
|
||||||
|
pop_start = i
|
||||||
|
lines.pop(pop_start)
|
||||||
|
result = '\n'.join(lines[:end - 1]).strip()
|
||||||
|
|
||||||
|
if second != result:
|
||||||
print('test @%s: not the same result, %s' % (line_nr - 1, name))
|
print('test @%s: not the same result, %s' % (line_nr - 1, name))
|
||||||
|
print(' ' + repr(result))
|
||||||
|
print(' ' + repr(second))
|
||||||
|
fails += 1
|
||||||
except Exception:
|
except Exception:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
print('test @%s: %s' % (line_nr - 1, name))
|
print('test @%s: %s' % (line_nr - 1, name))
|
||||||
@@ -76,7 +99,7 @@ def test_dir(refactoring_test_dir):
|
|||||||
base.summary.append(s)
|
base.summary.append(s)
|
||||||
|
|
||||||
|
|
||||||
refactoring_test_dir = '../test/refactor/'
|
refactoring_test_dir = '../test/refactor'
|
||||||
test_files = base.get_test_list()
|
test_files = base.get_test_list()
|
||||||
test_dir(refactoring_test_dir)
|
test_dir(refactoring_test_dir)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# --- a
|
# --- simple
|
||||||
def test():
|
def test():
|
||||||
#? 25 a
|
#? 25 a
|
||||||
return test(1, (30 + b, c) + 1)
|
return test(1, (30 + b, c) + 1)
|
||||||
@@ -10,8 +10,9 @@ def test():
|
|||||||
|
|
||||||
# --- multiline
|
# --- multiline
|
||||||
def test():
|
def test():
|
||||||
|
#? 30 x
|
||||||
return test(1, (30 + b, c) + 1)
|
return test(1, (30 + b, c) + 1)
|
||||||
# +++
|
# +++
|
||||||
def test():
|
def test():
|
||||||
a = (30 + b, c) + 1
|
x = (30 + b, c) + 1
|
||||||
return test(a)
|
return test(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user