Anonymous avatar Anonymous committed 909a669

choosing which files to apply a restructuring on

Comments (0)

Files changed (4)

docs/dev/issues.txt

 * better tests in `patchedasttest`
 * import actions with more that one phase and filtering problems
 * handle long imports should work on filtered imports unconditionally?
-* adding restructuring scope; local scope, module, all files?
 * changing `codeanalyze.WordFinder` to use asts?
 * assignment to parameters in inline method
 * extracting subexpressions; look at `extracttest` for more info
 ===========
 
 
+- Choosing which files to apply a restructuring on : January 9, 2008
+
+
+- Allowing customizable restructuring wildcards : January 7, 2008
+
+
 > Public Release 0.7.4 : January 3, 2008
 
 

rope/refactor/restructure.py

         self.wildcards = wildcards
         self.template = similarfinder.CodeTemplate(self.goal)
 
-    def get_changes(self, checks=None, imports=None,
+    def get_changes(self, checks=None, imports=None, resources=None,
                     task_handle=taskhandle.NullTaskHandle()):
-        """Get the changes needed by this restructuring"""
+        """Get the changes needed by this restructuring
+
+        `resources` can be a list of `rope.base.resources.File`\s to
+        apply the restructuring on.  If `None`, the restructuring will
+        be applied to all python files.
+
+        """
         if checks is not None:
             warnings.warn(
                 'The use of checks parameter is deprecated; '
             self.imports = imports
         changes = change.ChangeSet('Restructuring <%s> to <%s>' %
                                    (self.pattern, self.goal))
-        files = self.pycore.get_python_files()
+        if resources is not None:
+            files = [resource for resource in resources
+                     if self.pycore.is_python_file(resource)]
+        else:
+            files = self.pycore.get_python_files()
         job_set = task_handle.create_jobset('Collecting Changes', len(files))
         for resource in files:
             job_set.started_job('Working on <%s>' % resource.path)
                                                                self.args)))
             result = computer.get_changed()
             if result is not None:
-                imported_source = self._add_imports(resource, result, self.imports)
+                imported_source = self._add_imports(resource, result,
+                                                    self.imports)
                 changes.add_change(change.ChangeContents(resource,
                                                          imported_source))
             job_set.finished_job()

ropetest/refactor/restructuretest.py

 
     def test_preventing_stack_overflow_when_matching(self):
         self.mod.write('1\n')
-        refactoring = restructure.Restructure(
-            self.project, '${a}', '${a}')
+        refactoring = restructure.Restructure(self.project, '${a}', '${a}')
         self.project.do(refactoring.get_changes())
         self.assertEquals('1\n', self.mod.read())
 
+    def test_performing_a_restructuring_to_all_modules(self):
+        mod2 = testutils.create_module(self.project, 'mod2')
+        self.mod.write('a = 1\n')
+        mod2.write('b = 1\n')
+        refactoring = restructure.Restructure(self.project, '1', '2 / 1')
+        self.project.do(refactoring.get_changes())
+        self.assertEquals('a = 2 / 1\n', self.mod.read())
+        self.assertEquals('b = 2 / 1\n', mod2.read())
+
+    def test_performing_a_restructuring_to_selected_modules(self):
+        mod2 = testutils.create_module(self.project, 'mod2')
+        self.mod.write('a = 1\n')
+        mod2.write('b = 1\n')
+        refactoring = restructure.Restructure(self.project, '1', '2 / 1')
+        self.project.do(refactoring.get_changes(resources=[mod2]))
+        self.assertEquals('a = 1\n', self.mod.read())
+        self.assertEquals('b = 2 / 1\n', mod2.read())
+
 
 if __name__ == '__main__':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.