summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pep3151.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-17 18:18:58 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-17 18:18:58 (GMT)
commit9ea8e4c29db12520bdd024357acf354b0653dd04 (patch)
tree69a5b6afd52b695169956b5fdc282f4ff7fa6986 /Lib/test/test_pep3151.py
parentecd02074440b683b28f0946c2a03b499541d1ea8 (diff)
downloadcpython-9ea8e4c29db12520bdd024357acf354b0653dd04.zip
cpython-9ea8e4c29db12520bdd024357acf354b0653dd04.tar.gz
cpython-9ea8e4c29db12520bdd024357acf354b0653dd04.tar.bz2
Instantiate the OS-related exception as soon as we raise it, so that "except"
works properly. PyErr_SetFromErrnoWithFilenameObject() was already fixed by the changeset 793c75177d28. This commit fixes PyErr_SetExcFromWindowsErrWithFilenameObject(), used on Windows.
Diffstat (limited to 'Lib/test/test_pep3151.py')
-rw-r--r--Lib/test/test_pep3151.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_pep3151.py b/Lib/test/test_pep3151.py
index 3c52bc6..e327f42 100644
--- a/Lib/test/test_pep3151.py
+++ b/Lib/test/test_pep3151.py
@@ -80,12 +80,23 @@ class HierarchyTest(unittest.TestCase):
self.assertIs(type(e), SubOSError)
def test_try_except(self):
+ filename = "some_hopefully_non_existing_file"
+
# 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")
+ open(filename)
+ except FileNotFoundError:
+ pass
+ else:
+ self.fail("should have raised a FileNotFoundError")
+
+ # Another test for PyErr_SetExcFromWindowsErrWithFilenameObject()
+ self.assertFalse(os.path.exists(filename))
+ try:
+ os.unlink(filename)
except FileNotFoundError:
pass
else: