[Python-checkins] r57238 - in sandbox/trunk/import_in_py: _importlib.py tests/test_fs_loader.py
brett.cannon
python-checkins at python.org
Tue Aug 21 05:38:06 CEST 2007
Author: brett.cannon
Date: Tue Aug 21 05:38:02 2007
New Revision: 57238
Modified:
sandbox/trunk/import_in_py/_importlib.py
sandbox/trunk/import_in_py/tests/test_fs_loader.py
Log:
Tests get_source for the source loader.
Modified: sandbox/trunk/import_in_py/_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/_importlib.py (original)
+++ sandbox/trunk/import_in_py/_importlib.py Tue Aug 21 05:38:02 2007
@@ -445,8 +445,12 @@
"""
try:
return open(self._source_path, 'U').read()
- except AttributeError:
- return None
+ except (IOError, AttributeError):
+ if (hasattr(self, '_bytecode_path') and
+ _path_exists(self._bytecode_path)):
+ return None
+ else:
+ raise ImportError('no source or bytecode available')
@check_name
def get_bytecode(self, name):
Modified: sandbox/trunk/import_in_py/tests/test_fs_loader.py
==============================================================================
--- sandbox/trunk/import_in_py/tests/test_fs_loader.py (original)
+++ sandbox/trunk/import_in_py/tests/test_fs_loader.py Tue Aug 21 05:38:02 2007
@@ -281,9 +281,19 @@
"""Test the optional extensions from PEP 302."""
+ def setUp(self):
+ TestPyPycPackages.setUp(self, faked_names=False)
+
def test_get_source(self):
- # XXX Needed if used by handle_py?
- raise NotImplementedError
+ # Return the source when available, None if there is at least bytecode,
+ # and raise ImportError if there is no change of loading the module.
+ loader = importlib._PyFileLoader(self.module_name, self.py_path, False)
+ source = loader.get_source(self.module_name)
+ self.assertEqual(source, self.source)
+ os.unlink(self.py_path)
+ self.assert_(loader.get_source(self.module_name) is None)
+ os.unlink(self.pyc_path)
+ self.assertRaises(ImportError, loader.get_source, self.module_name)
def test_get_data(self):
raise NotImplementedError
More information about the Python-checkins
mailing list