Commits

Anonymous committed a4e6e09

autoimport: handled removed resources

Comments (0)

Files changed (2)

rope/contrib/autoimport.py

         project.data_files.add_write_hook(self.write)
         # XXX: handle moved and removed
         observer = resourceobserver.ResourceObserver(
-            changed=self._changed, moved=self._moved)
+            changed=self._changed, moved=self._moved, removed=self._removed)
         if observe:
             project.add_observer(observer)
 
             if modname in self.names:
                 del self.names[modname]
             self.update_resource(newresource)
+
+    def _removed(self, resource):
+        if not resource.is_folder():
+            modname = self._module_name(resource)
+            if modname in self.names:
+                del self.names[modname]

ropetest/contrib/autoimporttest.py

         self.mod1.move('mod3.py')
         self.assertEquals(['mod3'], self.importer.get_modules('myvar'))
 
+    def test_removing_files(self):
+        self.mod1.write('myvar = None\n')
+        self.mod1.remove()
+        self.assertEquals([], self.importer.get_modules('myvar'))
+
 
 if __name__ == '__main__':
     unittest.main()