diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-12 17:39:57 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-12 17:39:57 (GMT) |
commit | 5d6fbe82078fe67437755bccfa504dbbcf909a74 (patch) | |
tree | 25a147fb6ca753fc0dd7ecc55543f2cce708b313 /Lib/test/test_pep3151.py | |
parent | 1e4fe702f60b1bf8ed2e3ddca0ea634d83cca89b (diff) | |
download | cpython-5d6fbe82078fe67437755bccfa504dbbcf909a74.zip cpython-5d6fbe82078fe67437755bccfa504dbbcf909a74.tar.gz cpython-5d6fbe82078fe67437755bccfa504dbbcf909a74.tar.bz2 |
Instantiate the OS-related exception as soon as we raise it, so that
"except" works properly.
Diffstat (limited to 'Lib/test/test_pep3151.py')
-rw-r--r-- | Lib/test/test_pep3151.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_pep3151.py b/Lib/test/test_pep3151.py index 9d92425..3c52bc6 100644 --- a/Lib/test/test_pep3151.py +++ b/Lib/test/test_pep3151.py @@ -79,6 +79,18 @@ class HierarchyTest(unittest.TestCase): e = SubOSError(EEXIST, "Bad file descriptor") self.assertIs(type(e), SubOSError) + def test_try_except(self): + # This checks that try .. except checks the concrete exception + # (FileNotFoundError) and not the base type specified when + # PyErr_SetFromErrnoWithFilenameObject was called. + # (it is therefore deliberate that it doesn't use assertRaises) + try: + open("some_hopefully_non_existing_file") + except FileNotFoundError: + pass + else: + self.fail("should have raised a FileNotFoundError") + class AttributesTest(unittest.TestCase): |