forked from VimPlug/jedi
Make sure that tests for refactoring are redirected
This commit is contained in:
@@ -11,15 +11,14 @@ import re
|
||||
|
||||
from functools import reduce
|
||||
import jedi
|
||||
from jedi import refactoring
|
||||
|
||||
|
||||
class RefactoringCase(object):
|
||||
|
||||
def __init__(self, name, source, line_nr, index, path,
|
||||
def __init__(self, name, code, line_nr, index, path,
|
||||
new_name, start_line_test, desired):
|
||||
self.name = name
|
||||
self.source = source
|
||||
self.code = code
|
||||
self.line_nr = line_nr
|
||||
self.index = index
|
||||
self.path = path
|
||||
@@ -27,10 +26,14 @@ class RefactoringCase(object):
|
||||
self.start_line_test = start_line_test
|
||||
self.desired = desired
|
||||
|
||||
def refactor(self):
|
||||
script = jedi.Script(self.source, self.line_nr, self.index, self.path)
|
||||
@property
|
||||
def refactor_type(self):
|
||||
f_name = os.path.basename(self.path)
|
||||
refactor_func = getattr(refactoring, f_name.replace('.py', ''))
|
||||
return f_name.replace('.py', '')
|
||||
|
||||
def refactor(self):
|
||||
script = jedi.Script(self.code, self.line_nr, self.index, self.path)
|
||||
refactor_func = getattr(script, self.refactor_type)
|
||||
args = (self.new_name,) if self.new_name else ()
|
||||
return refactor_func(script, *args)
|
||||
|
||||
@@ -61,14 +64,14 @@ class RefactoringCase(object):
|
||||
self.name, self.line_nr - 1)
|
||||
|
||||
|
||||
def collect_file_tests(source, path, lines_to_execute):
|
||||
def collect_file_tests(code, path, lines_to_execute):
|
||||
r = r'^# --- ?([^\n]*)\n((?:(?!\n# \+\+\+).)*)' \
|
||||
r'\n# \+\+\+((?:(?!\n# ---).)*)'
|
||||
for match in re.finditer(r, source, re.DOTALL | re.MULTILINE):
|
||||
for match in re.finditer(r, code, re.DOTALL | re.MULTILINE):
|
||||
name = match.group(1).strip()
|
||||
first = match.group(2).strip()
|
||||
second = match.group(3).strip()
|
||||
start_line_test = source[:match.start()].count('\n') + 1
|
||||
start_line_test = code[:match.start()].count('\n') + 1
|
||||
|
||||
# get the line with the position of the operation
|
||||
p = re.match(r'((?:(?!#\?).)*)#\? (\d*) ?([^\n]*)', first, re.DOTALL)
|
||||
@@ -83,7 +86,7 @@ def collect_file_tests(source, path, lines_to_execute):
|
||||
if lines_to_execute and line_nr - 1 not in lines_to_execute:
|
||||
continue
|
||||
|
||||
yield RefactoringCase(name, source, line_nr, index, path,
|
||||
yield RefactoringCase(name, code, line_nr, index, path,
|
||||
new_name, start_line_test, second)
|
||||
|
||||
|
||||
@@ -94,6 +97,6 @@ def collect_dir_tests(base_dir, test_files):
|
||||
if f_name.endswith(".py") and (not test_files or files_to_execute):
|
||||
path = os.path.join(base_dir, f_name)
|
||||
with open(path) as f:
|
||||
source = f.read()
|
||||
for case in collect_file_tests(source, path, lines_to_execute):
|
||||
code = f.read()
|
||||
for case in collect_file_tests(code, path, lines_to_execute):
|
||||
yield case
|
||||
|
||||
Reference in New Issue
Block a user