Commits

Ali Gholami Rudi  committed 208b35b

autoimport: added AutoImport.get_modules()

  • Participants
  • Parent commits 1dad47f

Comments (0)

Files changed (2)

File rope/contrib/autoimport.py

                     result.append((global_name, module))
         return result
 
+    def get_modules(self, name):
+        result = []
+        for module in self.names:
+            if name in self.names[module]:
+                result.append(module)
+        return result
+
     def update_resource(self, resource):
         try:
             pymodule = self.project.pycore.resource_to_pyobject(resource)

File ropetest/contrib/autoimporttest.py

         self.importer.update_resource(self.mod1)
         self.assertEquals([], self.importer.import_assist('pkg'))
 
+    def test_get_modules(self):
+        self.mod1.write('myvar = None\n')
+        self.importer.update_resource(self.mod1)
+        self.assertEquals(['mod1'], self.importer.get_modules('myvar'))
+
+    def test_get_modules_inside_packages(self):
+        self.mod1.write('myvar = None\n')
+        self.mod2.write('myvar = None\n')
+        self.importer.update_resource(self.mod1)
+        self.importer.update_resource(self.mod2)
+        self.assertEquals(set(['mod1', 'pkg.mod2']),
+                          set(self.importer.get_modules('myvar')))
+
 
 if __name__ == '__main__':
     unittest.main()