Esempio n. 1
0
       from rope.contrib import generate

      args
       project: type=rope.base.project.Project

    Example #4::

      pattern ${pow}(${param1}, ${param2})
      goal ${param1} ** ${param2}
      args pow: name=mod.pow, exact

    Example #5::

      pattern ${inst}.longtask(${p1}, ${p2})
      goal
       ${inst}.subtask1(${p1})
       ${inst}.subtask2(${p2})
      args
       inst: type=mod.A,unsure

"""
restructuring = restructure.Restructure(project, pattern, goal, args)

project.do(restructuring.get_changes())
mod2.read()
u'import mod1\nprint(2 ** 3)\n'

# Cleaning up
# mod1.remove()
# mod2.remove()
project.close()
Esempio n. 2
0
 def test_replacing_sets_with_assignments(self):
     refactoring = restructure.Restructure(self.project, '${a}.set(${b})',
                                           '${a} = ${b}')
     self.mod.write('a.set(1)\nb.set(1)\n')
     self.project.do(refactoring.get_changes())
     self.assertEquals('a = 1\nb = 1\n', self.mod.read())
Esempio n. 3
0
 def test_auto_indentation_when_no_indentation(self):
     self.mod.write('a = 2\n')
     refactoring = restructure.Restructure(self.project, '${a} = 2',
                                           '${a} = 1\n${a} += 1')
     self.project.do(refactoring.get_changes())
     self.assertEquals('a = 1\na += 1\n', self.mod.read())
Esempio n. 4
0
 def test_replacing_patterns_with_any_names(self):
     refactoring = restructure.Restructure(self.project, '${a} = 1',
                                           '${a} = int(1)')
     self.mod.write('a = 1\nb = 1\n')
     self.project.do(refactoring.get_changes())
     self.assertEquals('a = int(1)\nb = int(1)\n', self.mod.read())
Esempio n. 5
0
 def test_replacing_patterns_with_any_names2(self):
     refactoring = restructure.Restructure(self.project, '${x} + ${x}',
                                           '${x} * 2')
     self.mod.write('a = 1 + 1\n')
     self.project.do(refactoring.get_changes())
     self.assertEquals('a = 1 * 2\n', self.mod.read())
Esempio n. 6
0
 def test_statement_after_string_and_column(self):
     mod_text = 'def f(x):\n  if a == "a": raise Exception("test")\n'
     self.mod.write(mod_text)
     refactoring = restructure.Restructure(self.project, '${a}', '${a}')
     self.project.do(refactoring.get_changes())
     self.assertEquals(mod_text, self.mod.read())
Esempio n. 7
0
 def test_trivial_case(self):
     refactoring = restructure.Restructure(self.project, 'a = 1', 'a = 0')
     self.mod.write('b = 1\n')
     self.project.do(refactoring.get_changes())
     self.assertEquals('b = 1\n', self.mod.read())
Esempio n. 8
0
 def test_preventing_stack_overflow_when_matching(self):
     self.mod.write('1\n')
     refactoring = restructure.Restructure(self.project, '${a}', '${a}')
     self.project.do(refactoring.get_changes())
     self.assertEquals('1\n', self.mod.read())
Esempio n. 9
0
 def test_handling_overlapping_matches(self):
     self.mod.write('a = 1\na = 1\na = 1\n')
     refactoring = restructure.Restructure(self.project, 'a = 1\na = 1\n',
                                           'b = 1')
     self.project.do(refactoring.get_changes())
     self.assertEquals('b = 1\na = 1\n', self.mod.read())
Esempio n. 10
0
 def test_handling_containing_matches(self):
     self.mod.write('a = 1 / 2 / 3\n')
     refactoring = restructure.Restructure(self.project, '${a} / ${b}',
                                           '${a} // ${b}')
     self.project.do(refactoring.get_changes())
     self.assertEquals('a = 1 // 2 // 3\n', self.mod.read())