Commits

Ali Gholami Rudi  committed a028998

Fixed fixing syntax errors when using code_assist with an unchanged resource

  • Participants
  • Parent commits 1cc3bef

Comments (0)

Files changed (3)

File rope/base/codeanalyze.py

 import re
+import token
 import tokenize
-import token
 
+import rope.base.exceptions
+import rope.base.pynames
 import rope.base.pyobjects
-import rope.base.pynames
-from rope.base import pyobjects, pynames
-import rope.base.exceptions
-from rope.base import ast, builtins, evaluate
+from rope.base import pyobjects, evaluate
 
 
 class WordRangeFinder(object):

File rope/contrib/codeassist.py

     fixed.
 
     """
-    if resource and resource.exists() and code == resource.read():
-        return pycore.resource_to_pyobject(resource)
     commenter = None
+    errors = []
     tries = 0
     while True:
         try:
                         raise
                 commenter.comment(e.lineno)
                 code = '\n'.join(commenter.lines)
+                errors.append('  * line %s: %s ... fixed' % (e.lineno,
+                                                             e.message))
             else:
-                raise
+                errors.append('  * line %s: %s ... raised!' % (e.lineno,
+                                                               e.message))
+                new_message = ('Syntax errors in file %s:\n' % e.filename) \
+                               + '\n'.join(errors)
+                raise exceptions.ModuleSyntaxError(e.filename, e.lineno,
+                                                   new_message)
 
 
 def _get_line_indents(line):

File ropetest/contrib/codeassisttest.py

         testutils.remove_project(self.project)
         super(self.__class__, self).tearDown()
 
-    def _assist(self, code, resource=None):
-        return code_assist(self.project, code, len(code), resource)
+    def _assist(self, code, resource=None, **kwds):
+        return code_assist(self.project, code, len(code), resource, **kwds)
 
     def assert_completion_in_result(self, name, kind, result):
         for proposal in result:
             self.project, mod1, mod1.read().index('a_func'), unsure=True)
         self.assertEquals(2, len(result))
 
+    def test_fixing_errors_with_maxfixes_in_resources(self):
+        mod = testutils.create_module(self.project, 'mod')
+        code = 'def f():\n    sldj sldj\ndef g():\n    ran'
+        mod.write(code)
+        result = self._assist(code, maxfixes=2, resource=mod)
+        self.assertTrue(len(result) > 0)
+
 
 class TemplateTest(unittest.TestCase):