diff options
author | Brett Cannon <brett@python.org> | 2012-04-12 20:24:54 -0400 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-04-12 20:24:54 -0400 |
commit | 79ec55e980d7b205bbc78d44e0892d0ef37d3abb (patch) | |
tree | 7fca6e94007fd848ec36ba029aee3b1ec2a8785c /Lib/test/test_exceptions.py | |
parent | f50b38a11fa951582b7f1656685201269f265784 (diff) | |
download | cpython-79ec55e980d7b205bbc78d44e0892d0ef37d3abb.tar.gz cpython-79ec55e980d7b205bbc78d44e0892d0ef37d3abb.zip |
Issue #1559549: Add 'name' and 'path' attributes to ImportError.
Currently import does not use these attributes as they are planned
for use by importlib (which will be another commit).
Thanks to Filip GruszczyĆski for the initial patch and Brian Curtin
for refining it.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 42536d3b7ca..39ff85fc190 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -902,8 +902,30 @@ class ExceptionTests(unittest.TestCase): self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception) +class ImportErrorTests(unittest.TestCase): + + def test_attributes(self): + # Setting 'name' and 'path' should not be a problem. + exc = ImportError('test') + self.assertIsNone(exc.name) + self.assertIsNone(exc.path) + + exc = ImportError('test', name='somemodule') + self.assertEqual(exc.name, 'somemodule') + self.assertIsNone(exc.path) + + exc = ImportError('test', path='somepath') + self.assertEqual(exc.path, 'somepath') + self.assertIsNone(exc.name) + + exc = ImportError('test', path='somepath', name='somename') + self.assertEqual(exc.name, 'somename') + self.assertEqual(exc.path, 'somepath') + + + def test_main(): - run_unittest(ExceptionTests) + run_unittest(ExceptionTests, ImportErrorTests) if __name__ == '__main__': unittest.main() |