diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 90860a8e..8883fae9 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -27,7 +27,6 @@ class Refactoring(object): def diff(self): texts = [] 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: udiff = difflib.unified_diff(old_l, new_l) else: @@ -107,9 +106,7 @@ def extract(script, new_name): positions = [s] + call.execution.arr_el_pos + [exe.end_pos] start_pos = positions[index] 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]] - print text for l in range(start_pos[0], end_pos[0] - 1): text new_lines[start_pos[0]:end_pos[0]-1] diff --git a/test/refactor.py b/test/refactor.py index e1911c55..dbd23a2e 100755 --- a/test/refactor.py +++ b/test/refactor.py @@ -30,18 +30,23 @@ def run_test(source, f_name, lines_to_execute): s = unicode(source) # parse the refactor format r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \ - r'\n# \+\+\+((?:(?!\n# \+\+\+).)*)' + r'\n# \+\+\+((?:(?!\n# ---).)*)' for match in re.finditer(r, s, re.DOTALL | re.MULTILINE): name = match.group(1).strip() first = match.group(2).strip() second = match.group(3).strip() + start_line_test = s[:match.start()].count('\n') + 1 # get the line with the position of the operation - p = re.match(r'((?:(?!#\?).)*)#\? (\d*) ([^\n]*)', first, re.DOTALL) - until_pos = p.group(1) - index = p.group(2) + p = re.match(r'((?:(?!#\?).)*)#\? (\d*) ?([^\n]*)', first, re.DOTALL) + if p is None: + print("Please add a test start.") + continue + until = p.group(1) + index = int(p.group(2)) 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 try: @@ -49,9 +54,27 @@ def run_test(source, f_name, lines_to_execute): refactor_func = getattr(refactoring, f_name.replace('.py', '')) args = (script, new_name) if new_name else (script,) 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(' ' + repr(result)) + print(' ' + repr(second)) + fails += 1 except Exception: print(traceback.format_exc()) print('test @%s: %s' % (line_nr - 1, name)) @@ -76,7 +99,7 @@ def test_dir(refactoring_test_dir): base.summary.append(s) -refactoring_test_dir = '../test/refactor/' +refactoring_test_dir = '../test/refactor' test_files = base.get_test_list() test_dir(refactoring_test_dir) diff --git a/test/refactor/extract.py b/test/refactor/extract.py index a31cbf51..06c076b8 100644 --- a/test/refactor/extract.py +++ b/test/refactor/extract.py @@ -1,4 +1,4 @@ -# --- a +# --- simple def test(): #? 25 a return test(1, (30 + b, c) + 1) @@ -10,8 +10,9 @@ def test(): # --- multiline def test(): + #? 30 x return test(1, (30 + b, c) + 1) # +++ def test(): - a = (30 + b, c) + 1 - return test(a) + x = (30 + b, c) + 1 + return test(x)