forked from VimPlug/jedi
move script in refactorings to be the default first parameter
This commit is contained in:
@@ -55,10 +55,10 @@ class Script(object):
|
||||
source_encoding='utf-8'):
|
||||
api_classes._clear_caches()
|
||||
debug.reset_time()
|
||||
source = modules.source_to_unicode(source, source_encoding)
|
||||
self.source = modules.source_to_unicode(source, source_encoding)
|
||||
self.pos = line, column
|
||||
self._module = modules.ModuleWithCursor(source_path, source=source,
|
||||
position=self.pos)
|
||||
self._module = modules.ModuleWithCursor(source_path,
|
||||
source=self.source, position=self.pos)
|
||||
self.source_path = source_path
|
||||
debug.speed('init')
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
""" Introduce refactoring """
|
||||
|
||||
import api
|
||||
import modules
|
||||
import difflib
|
||||
import helpers
|
||||
@@ -37,7 +36,7 @@ class Refactoring(object):
|
||||
return '\n'.join(texts)
|
||||
|
||||
|
||||
def rename(new_name, source, *args, **kwargs):
|
||||
def rename(script, new_name):
|
||||
""" The `args` / `kwargs` params are the same as in `api.Script`.
|
||||
:param operation: The refactoring operation to execute.
|
||||
:type operation: str
|
||||
@@ -49,7 +48,6 @@ def rename(new_name, source, *args, **kwargs):
|
||||
if new_lines is not None: # goto next file, save last
|
||||
dct[path] = path, old_lines, new_lines
|
||||
|
||||
script = api.Script(source, *args, **kwargs)
|
||||
old_names = script.related_names()
|
||||
order = sorted(old_names, key=lambda x: (x.module_path, x.start_pos),
|
||||
reverse=True)
|
||||
@@ -80,17 +78,16 @@ def rename(new_name, source, *args, **kwargs):
|
||||
return Refactoring(dct)
|
||||
|
||||
|
||||
def extract(new_name, source, *args, **kwargs):
|
||||
def extract(script, new_name):
|
||||
""" The `args` / `kwargs` params are the same as in `api.Script`.
|
||||
:param operation: The refactoring operation to execute.
|
||||
:type operation: str
|
||||
:type source: str
|
||||
:return: list of changed lines/changed files
|
||||
"""
|
||||
new_lines = modules.source_to_unicode(source).splitlines()
|
||||
new_lines = modules.source_to_unicode(script.source).splitlines()
|
||||
old_lines = new_lines[:]
|
||||
|
||||
script = api.Script(source, *args, **kwargs)
|
||||
user_stmt = script._parser.user_stmt
|
||||
|
||||
# TODO care for multiline extracts
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
import traceback
|
||||
import re
|
||||
@@ -48,7 +49,7 @@ 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
|
||||
print refactor_object.new_files()
|
||||
if second != refactor_object.new_files:
|
||||
print('test @%s: not the same result, %s' % (line_nr - 1, name))
|
||||
except Exception:
|
||||
@@ -78,3 +79,7 @@ def test_dir(refactoring_test_dir):
|
||||
refactoring_test_dir = '../test/refactor/'
|
||||
test_files = base.get_test_list()
|
||||
test_dir(refactoring_test_dir)
|
||||
|
||||
base.print_summary()
|
||||
|
||||
sys.exit(1 if base.tests_fail else 0)
|
||||
|
||||
Reference in New Issue
Block a user