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