class Restructure(Refactoring): key = 'x' confs = {'pattern': dialog.Data('Restructuring pattern: '), 'goal': dialog.Data('Restructuring goal: ')} def _calculate_changes(self, values, task_handle): restructuring = rope.refactor.restructure.Restructure( self.project, values['pattern'], values['goal'], args=values['args'], imports=values['imports']) return restructuring.get_changes(resources=values['resources'], task_handle=task_handle) def _get_optionals(self): return { 'args': dialog.Data('Arguments: ', decode=self._decode_args), 'imports': dialog.Data('Imports: ', decode=self._decode_imports), 'resources': self.resources_option} def _decode_args(self, value): if value: args = {} for raw_check in value.split('\n'): if raw_check: key, value = raw_check.split(':', 1) args[key.strip()] = value.strip() return args def _decode_imports(self, value): if value: return [line.strip() for line in value.split('\n')]
def test_skipping_blanks(self): optionals = {'name1': dialog.Data(), 'name2': dialog.Data()} minibuffer = _MockAskConfig( ['batchset', '\nname1\n value1\n\nname2 value2\n\n', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals({'name1': 'value1\n', 'name2': 'value2'}, result) self.assertEquals('done', action)
def test_batchset_multiple_sets(self): optionals = {'name1': dialog.Data(), 'name2': dialog.Data()} minibuffer = _MockAskConfig( ['batchset', 'name1 value1\nname2 value2', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEqual({'name1': 'value1', 'name2': 'value2'}, result) self.assertEqual('done', action)
def find_occurrences(self): optionals = { 'unsure': dialog.Data('Find uncertain occurrences: ', default='no', values=['yes', 'no']), 'resources': dialog.Data('Files to search: '), 'in_hierarchy': dialog.Data( 'Rename methods in class hierarchy: ', default='no', values=['yes', 'no'])} def get_kwds(values): return {'unsure': values.get('unsure') == 'yes', 'in_hierarchy': values.get('in_hierarchy') == 'yes'} self._base_findit(findit.find_occurrences, optionals, get_kwds)
def _create(self, name, callback, parentname='source'): self._check_project() confs = {'name': dialog.Data(name.title() + ' name: ')} parentname = parentname + 'folder' optionals = {parentname: dialog.Data( parentname.title() + ' Folder: ', default=self.project.address, kind='directory')} action, values = dialog.show_dialog( self._askdata, ['perform', 'cancel'], confs, optionals) if action == 'perform': parent = libutils.path_to_resource( self.project, values.get(parentname, self.project.address)) resource = callback(parent, values['name']) if resource: self.env.find_file(resource.real_path)
def _get_confs(self): args = [] for arg, default in self._get_args(): args.append(arg) signature = '(' + ', '.join(args) + ')' return {'signature': dialog.Data('Change the signature: ', default=signature)}
def find_implementations(self): optionals = {'resources': dialog.Data('Files to search: ')} def get_kwds(values): return {} self._base_findit(findit.find_implementations, optionals, get_kwds)
def test_optional_confs2(self): optionals = {'name': dialog.Data()} minibuffer = _MockAskConfig(['name', 'value', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEqual({'name': 'value'}, result) self.assertEqual('done', action)
def test_trivial_batchset(self): optionals = {'name': dialog.Data()} minibuffer = _MockAskConfig(['batchset', 'name value', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals({'name': 'value'}, result) self.assertEquals('done', action)
def test_asking_normal_configs(self): confs = {'name': dialog.Data()} minibuffer = _MockAskConfig(['value', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], confs) self.assertEquals({'name': 'value'}, result) self.assertEquals('done', action)
def test_optional_confs(self): optionals = {'name': dialog.Data()} minibuffer = _MockAskConfig(['done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals(None, result.get('name', None)) self.assertEquals('done', action)
def test_ignoring_trailing_colon_in_config_names(self): optionals = {'name1': dialog.Data()} minibuffer = _MockAskConfig(['batchset', 'name1: value1\n', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals({'name1': 'value1'}, result) self.assertEquals('done', action)
def test_multiline_sets(self): optionals = {'name': dialog.Data()} minibuffer = _MockAskConfig( ['batchset', 'name\n line1\n line2\n', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals({'name': 'line1\n line2\n'}, result) self.assertEquals('done', action)
def _get_confs(self): if isinstance(self.mover, rope.refactor.move.MoveGlobal): prompt = 'Destination module: ' if isinstance(self.mover, rope.refactor.move.MoveModule): prompt = 'Destination package: ' if isinstance(self.mover, rope.refactor.move.MoveMethod): prompt = 'Destination attribute: ' return {'destination': dialog.Data(prompt)}
def test_skip_initial_asking(self): confs = {'name': dialog.Data()} minibuffer = _MockAskConfig(['name', 'value', 'done']) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], confs=confs, initial_asking=False) self.assertEquals({'name': 'value'}, result) self.assertEquals('done', action)
def test_complex_batchset(self): optionals = { 'name1': dialog.Data(), 'name2': dialog.Data(), 'name3': dialog.Data() } minibuffer = _MockAskConfig([ 'batchset', 'name3\n value3\nname1\n line1\n ' 'line2\n\nname2 value2\n', 'done' ]) action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'], optionals=optionals) self.assertEquals( { 'name1': 'line1\n line2\n', 'name2': 'value2', 'name3': 'value3\n' }, result) self.assertEquals('done', action)
class MethodObject(Refactoring): saveall = False confs = {'classname': dialog.Data('New class name: ', default='_ExtractedClass')} def _create_refactoring(self): self.objecter = rope.refactor.method_object.MethodObject( self.project, self.resource, self.offset) def _calculate_changes(self, values, task_handle): classname = values.get('classname') return self.objecter.get_changes(classname)
def _get_optionals(self): opts = {} opts['docs'] = dialog.Boolean('Search comments and docs: ', True) if self.renamer.is_method(): opts['in_hierarchy'] = dialog.Boolean('Rename methods in ' 'class hierarchy: ') opts['resources'] = self.resources_option opts['unsure'] = dialog.Data('Unsure occurrences: ', decode=self._decode_unsure, values=['ignore', 'match'], default='ignore') return opts
class GenerateClass(Refactoring): key = 'n c' optionals = {'destination': dialog.Data('Destination module: ', None)} def _calculate_changes(self, values, task_handle): destination = values.get('destination') destination = self.project.pycore.find_module( destination) if destination else None self.generator = rope.contrib.generate.GenerateClass( self.project, self.resource, self.offset, goal_resource=destination) return self.generator.get_changes() def _done(self): resource, lineno = self.generator.get_location() self.interface._goto_location(resource, lineno)
def _get_optionals(self): return {"destination module": dialog.Data( prompt="Destination module: " )}
def _get_optionals(self): return { 'args': dialog.Data('Arguments: ', decode=self._decode_args), 'imports': dialog.Data('Imports: ', decode=self._decode_imports), 'resources': self.resources_option }
def resources_option(self): return dialog.Data('Files to apply this refactoring on: ', decode=self._decode_resources)
def _get_confs(self): return {'name': dialog.Data('Extracted %s name: ' % self.kind)}
def _get_confs(self): default = 'create_%s' % self.factory.old_name.lower() return {'factory_name': dialog.Data('Factory name: ', default)}
def _get_confs(self): oldname = str(self.renamer.get_old_name()) return {'new_name': dialog.Data('New name: ', default=oldname)}