Anonymous avatar Anonymous committed bb6f8da

pycore: builtin modules that don't exist

Comments (0)

Files changed (2)

rope/base/builtins.py

         super(BuiltinModule, self).__init__()
         self.name = name
         self.attributes = None
-        self.module = __import__(name)
+        try:
+            self.module = __import__(name)
+        except:
+            self.module = None
         self._calculate_attributes()
 
     def _calculate_attributes(self):
+        if self.module is None:
+            self.attributes = {}
+            return
         attributes = {}
         for name in dir(self.module):
             obj = getattr(self.module, name)
         return self.attributes
 
     def get_doc(self):
-        return self.module.__doc__
+        if self.module:
+            return self.module.__doc__
 
     def get_name(self):
         return self.name

ropetest/pycoretest.py

 
     def setUp(self):
         super(BuiltinModulesTest, self).setUp()
-        self.project = testutils.sample_project(extension_modules=['time'])
+        self.project = testutils.sample_project(
+            extension_modules=['time', 'invalid_module'])
         self.pycore = self.project.get_pycore()
         self.mod = testutils.create_module(self.project, 'mod')
 
         pymod = self.pycore.resource_to_pyobject(self.mod)
         self.assertTrue('rename' not in pymod['os'].get_object())
 
+    def test_ignored_extensions(self):
+        self.mod.write('import os')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertTrue('rename' not in pymod['os'].get_object())
+
+    def test_nonexistent_modules(self):
+        self.mod.write('import invalid_module')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        pymod['invalid_module'].get_object()
+
 
 def suite():
     result = unittest.TestSuite()
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.