From bffc3c8b53d4e7a0f798e342e9007298df292c14 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Mon, 26 Aug 2019 02:12:38 +0000 Subject: [PATCH 1/8] Add DirectoryNotEmptyError subclass of OSError --- Doc/c-api/exceptions.rst | 6 ++++++ Doc/library/exceptions.rst | 8 ++++++++ Include/pyerrors.h | 1 + Lib/test/test_exception_hierarchy.py | 1 + Lib/test/test_exceptions.py | 6 ++++++ Objects/exceptions.c | 5 +++++ PC/python3.def | 1 + 7 files changed, 28 insertions(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 25bb657dca0e16..f1c2b53d490219 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -788,6 +788,7 @@ the variables: single: PyExc_IndexError single: PyExc_InterruptedError single: PyExc_IsADirectoryError + single: PyExc_DirectoryNotEmptyError single: PyExc_KeyError single: PyExc_KeyboardInterrupt single: PyExc_LookupError @@ -866,6 +867,8 @@ the variables: +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_InterruptedError` | :exc:`InterruptedError` | | +-----------------------------------------+---------------------------------+----------+ +| :c:data:`PyExc_DirectoryNotEmptyError` | :exc:`DirectoryNotEmptyError` | | ++--------------------------------------------------------------------------------------+ | :c:data:`PyExc_IsADirectoryError` | :exc:`IsADirectoryError` | | +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_KeyError` | :exc:`KeyError` | | @@ -945,6 +948,9 @@ the variables: .. versionadded:: 3.6 :c:data:`PyExc_ModuleNotFoundError`. +.. versionadded:: 3.9 + :c:data:`PyExc_DirectoryNotEmptyError`. + These are compatibility aliases to :c:data:`PyExc_OSError`: .. index:: diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 52a505e0a0ff8f..8ba032325310f7 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -640,6 +640,14 @@ depending on the system error code. on something which is not a directory. Corresponds to :c:data:`errno` ``ENOTDIR``. + +.. exception:: DirectoryNotEmptyError + + Raised when a directory operation (such as :func:`os.rmdir`) is requested + on a directory which is empty. + Corresponds to :c:data:`errno` ``ENOTEMPTY`` + + .. exception:: PermissionError Raised when trying to run an operation without the adequate access diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 5125a51ec1aa17..94ccb3033f7d3f 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -122,6 +122,7 @@ PyAPI_DATA(PyObject *) PyExc_FileNotFoundError; PyAPI_DATA(PyObject *) PyExc_InterruptedError; PyAPI_DATA(PyObject *) PyExc_IsADirectoryError; PyAPI_DATA(PyObject *) PyExc_NotADirectoryError; +PyAPI_DATA(PyObject *) PyExc_DirectoryNotEmptyError; PyAPI_DATA(PyObject *) PyExc_PermissionError; PyAPI_DATA(PyObject *) PyExc_ProcessLookupError; PyAPI_DATA(PyObject *) PyExc_TimeoutError; diff --git a/Lib/test/test_exception_hierarchy.py b/Lib/test/test_exception_hierarchy.py index 43b4af84039c0c..37fa78b8ad2c59 100644 --- a/Lib/test/test_exception_hierarchy.py +++ b/Lib/test/test_exception_hierarchy.py @@ -63,6 +63,7 @@ def test_select_error(self): +-- InterruptedError EINTR +-- IsADirectoryError EISDIR +-- NotADirectoryError ENOTDIR + +-- DirectoryNotEmptyError ENOTEMPTY +-- PermissionError EACCES, EPERM +-- ProcessLookupError ESRCH +-- TimeoutError ETIMEDOUT diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 4d1aa4bca623f9..a3f1a51b11a1e1 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1170,6 +1170,12 @@ def inner(): self.fail("RecursionError not raised") self.assertEqual(wr(), None) + def test_errno_ENOTEMPTY(self): + with self.assertRaises(OSError) as cm: + test_dir = os.path.dirname(__file__) + os.rmdir(test_dir) + self.assertEqual(cm.exception.errno, errno.ENOTEMPTY, cm.exception) + def test_errno_ENOTDIR(self): # Issue #12802: "not a directory" errors are ENOTDIR even on Windows with self.assertRaises(OSError) as cm: diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 631f5375f73829..3ec8f0f1d5752c 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1271,6 +1271,8 @@ MiddlingExtendsException(PyExc_OSError, FileNotFoundError, OSError, "File not found."); MiddlingExtendsException(PyExc_OSError, IsADirectoryError, OSError, "Operation doesn't work on directories."); +MiddlingExtendsException(PyExc_OSError, DirectoryNotEmptyError, OSError, + "Operation only works on empty directories."); MiddlingExtendsException(PyExc_OSError, NotADirectoryError, OSError, "Operation only works on directories."); MiddlingExtendsException(PyExc_OSError, InterruptedError, OSError, @@ -2575,6 +2577,7 @@ _PyExc_Init(void) PRE_INIT(FileNotFoundError); PRE_INIT(IsADirectoryError); PRE_INIT(NotADirectoryError); + PRE_INIT(DirectoryNotEmptyError); PRE_INIT(InterruptedError); PRE_INIT(PermissionError); PRE_INIT(ProcessLookupError); @@ -2608,6 +2611,7 @@ _PyExc_Init(void) ADD_ERRNO(FileNotFoundError, ENOENT); ADD_ERRNO(IsADirectoryError, EISDIR); ADD_ERRNO(NotADirectoryError, ENOTDIR); + ADD_ERRNO(DirectoryNotEmptyError, ENOTEMPTY); ADD_ERRNO(InterruptedError, EINTR); ADD_ERRNO(PermissionError, EACCES); ADD_ERRNO(PermissionError, EPERM); @@ -2715,6 +2719,7 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod) POST_INIT(FileNotFoundError); POST_INIT(IsADirectoryError); POST_INIT(NotADirectoryError); + POST_INIT(DirectoryNotEmptyError); POST_INIT(InterruptedError); POST_INIT(PermissionError); POST_INIT(ProcessLookupError); diff --git a/PC/python3.def b/PC/python3.def index 1f355bffc9bdd0..e74f355f0941c5 100644 --- a/PC/python3.def +++ b/PC/python3.def @@ -210,6 +210,7 @@ EXPORTS PyExc_IndexError=python39.PyExc_IndexError DATA PyExc_InterruptedError=python39.PyExc_InterruptedError DATA PyExc_IsADirectoryError=python39.PyExc_IsADirectoryError DATA + PyExc_DirectoryNotEmptyError=python39.PyExc_DirectoryNotEmptyError DATA PyExc_KeyError=python39.PyExc_KeyError DATA PyExc_KeyboardInterrupt=python39.PyExc_KeyboardInterrupt DATA PyExc_LookupError=python39.PyExc_LookupError DATA From d87fce730a51bac01b38a314b1fd2553b199fdc4 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Mon, 26 Aug 2019 02:18:17 +0000 Subject: [PATCH 2/8] remove spaces --- Doc/library/exceptions.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 8ba032325310f7..8b1035a144a89c 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -640,14 +640,12 @@ depending on the system error code. on something which is not a directory. Corresponds to :c:data:`errno` ``ENOTDIR``. - .. exception:: DirectoryNotEmptyError Raised when a directory operation (such as :func:`os.rmdir`) is requested on a directory which is empty. Corresponds to :c:data:`errno` ``ENOTEMPTY`` - .. exception:: PermissionError Raised when trying to run an operation without the adequate access From 5c5d9cc477e874ba2e73a0dcd8e2d6b5d996fb1e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 26 Aug 2019 02:23:23 +0000 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst b/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst new file mode 100644 index 00000000000000..46f635ef454391 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst @@ -0,0 +1 @@ +Add `DirectoryNotEmptyError` subclass of `OSError`. \ No newline at end of file From bafafe713d49981c841d9d4f7329a1ff7f1624c2 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com> Date: Thu, 5 Sep 2019 13:34:07 -0300 Subject: [PATCH 4/8] Update Doc/library/exceptions.rst Co-Authored-By: pppery --- Doc/library/exceptions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 8b1035a144a89c..a2c67edf68d97f 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -643,7 +643,7 @@ depending on the system error code. .. exception:: DirectoryNotEmptyError Raised when a directory operation (such as :func:`os.rmdir`) is requested - on a directory which is empty. + on a directory which is not empty. Corresponds to :c:data:`errno` ``ENOTEMPTY`` .. exception:: PermissionError From 842b856bebe05ab603dcb1650aec30f0df2589ce Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Thu, 5 Sep 2019 18:04:38 +0000 Subject: [PATCH 5/8] come clean before merge --- Doc/library/exceptions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 8b1035a144a89c..5faa00d9f7a215 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -637,13 +637,13 @@ depending on the system error code. .. exception:: NotADirectoryError Raised when a directory operation (such as :func:`os.listdir`) is requested - on something which is not a directory. + on something which is a directory. Corresponds to :c:data:`errno` ``ENOTDIR``. .. exception:: DirectoryNotEmptyError Raised when a directory operation (such as :func:`os.rmdir`) is requested - on a directory which is empty. + on a directory which is not empty. Corresponds to :c:data:`errno` ``ENOTEMPTY`` .. exception:: PermissionError From 8df5694bef6c0e98f0e30ca0158c24836c6fb95c Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Thu, 5 Sep 2019 18:23:16 +0000 Subject: [PATCH 6/8] Fix tests test_pickle and test_baseexception --- Doc/c-api/exceptions.rst | 6 +++--- Doc/library/exceptions.rst | 14 +++++++------- Include/pyerrors.h | 2 +- Lib/_compat_pickle.py | 1 + Lib/test/exception_hierarchy.txt | 1 + Lib/test/test_exception_hierarchy.py | 2 +- Lib/test/test_exceptions.py | 11 +++++++++-- Objects/exceptions.c | 12 ++++++------ 8 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index f1c2b53d490219..3c7984f220d723 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -778,6 +778,7 @@ the variables: single: PyExc_ConnectionError single: PyExc_ConnectionRefusedError single: PyExc_ConnectionResetError + single: PyExc_DirectoryNotEmptyError single: PyExc_EOFError single: PyExc_FileExistsError single: PyExc_FileNotFoundError @@ -788,7 +789,6 @@ the variables: single: PyExc_IndexError single: PyExc_InterruptedError single: PyExc_IsADirectoryError - single: PyExc_DirectoryNotEmptyError single: PyExc_KeyError single: PyExc_KeyboardInterrupt single: PyExc_LookupError @@ -849,6 +849,8 @@ the variables: +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_ConnectionResetError` | :exc:`ConnectionResetError` | | +-----------------------------------------+---------------------------------+----------+ +| :c:data:`PyExc_DirectoryNotEmptyError` | :exc:`DirectoryNotEmptyError` | | ++--------------------------------------------------------------------------------------+ | :c:data:`PyExc_EOFError` | :exc:`EOFError` | | +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_FileExistsError` | :exc:`FileExistsError` | | @@ -867,8 +869,6 @@ the variables: +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_InterruptedError` | :exc:`InterruptedError` | | +-----------------------------------------+---------------------------------+----------+ -| :c:data:`PyExc_DirectoryNotEmptyError` | :exc:`DirectoryNotEmptyError` | | -+--------------------------------------------------------------------------------------+ | :c:data:`PyExc_IsADirectoryError` | :exc:`IsADirectoryError` | | +-----------------------------------------+---------------------------------+----------+ | :c:data:`PyExc_KeyError` | :exc:`KeyError` | | diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 5faa00d9f7a215..d70a1e6a111289 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -608,6 +608,12 @@ depending on the system error code. reset by the peer. Corresponds to :c:data:`errno` ``ECONNRESET``. +.. exception:: DirectoryNotEmptyError + + Raised when a directory operation (such as :func:`os.rmdir`) is requested + on a directory which is not empty. + Corresponds to :c:data:`errno` ``ENOTEMPTY`` + .. exception:: FileExistsError Raised when trying to create a file or directory which already exists. @@ -637,15 +643,9 @@ depending on the system error code. .. exception:: NotADirectoryError Raised when a directory operation (such as :func:`os.listdir`) is requested - on something which is a directory. + on something which is not a directory. Corresponds to :c:data:`errno` ``ENOTDIR``. -.. exception:: DirectoryNotEmptyError - - Raised when a directory operation (such as :func:`os.rmdir`) is requested - on a directory which is not empty. - Corresponds to :c:data:`errno` ``ENOTEMPTY`` - .. exception:: PermissionError Raised when trying to run an operation without the adequate access diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 94ccb3033f7d3f..3c1ffe9a839a9b 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -117,12 +117,12 @@ PyAPI_DATA(PyObject *) PyExc_ConnectionError; PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError; PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError; PyAPI_DATA(PyObject *) PyExc_ConnectionResetError; +PyAPI_DATA(PyObject *) PyExc_DirectoryNotEmptyError; PyAPI_DATA(PyObject *) PyExc_FileExistsError; PyAPI_DATA(PyObject *) PyExc_FileNotFoundError; PyAPI_DATA(PyObject *) PyExc_InterruptedError; PyAPI_DATA(PyObject *) PyExc_IsADirectoryError; PyAPI_DATA(PyObject *) PyExc_NotADirectoryError; -PyAPI_DATA(PyObject *) PyExc_DirectoryNotEmptyError; PyAPI_DATA(PyObject *) PyExc_PermissionError; PyAPI_DATA(PyObject *) PyExc_ProcessLookupError; PyAPI_DATA(PyObject *) PyExc_TimeoutError; diff --git a/Lib/_compat_pickle.py b/Lib/_compat_pickle.py index f68496ae639f5f..7b4250cc8a4482 100644 --- a/Lib/_compat_pickle.py +++ b/Lib/_compat_pickle.py @@ -230,6 +230,7 @@ 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', + 'DirectoryNotEmptyError', 'FileExistsError', 'FileNotFoundError', 'InterruptedError', diff --git a/Lib/test/exception_hierarchy.txt b/Lib/test/exception_hierarchy.txt index 763a6c899b48eb..3dba36c37f772b 100644 --- a/Lib/test/exception_hierarchy.txt +++ b/Lib/test/exception_hierarchy.txt @@ -29,6 +29,7 @@ BaseException | | +-- ConnectionAbortedError | | +-- ConnectionRefusedError | | +-- ConnectionResetError + | +-- DirectoryNotEmptyError | +-- FileExistsError | +-- FileNotFoundError | +-- InterruptedError diff --git a/Lib/test/test_exception_hierarchy.py b/Lib/test/test_exception_hierarchy.py index 37fa78b8ad2c59..f4ebc0b2653c80 100644 --- a/Lib/test/test_exception_hierarchy.py +++ b/Lib/test/test_exception_hierarchy.py @@ -58,12 +58,12 @@ def test_select_error(self): +-- ConnectionAbortedError ECONNABORTED +-- ConnectionRefusedError ECONNREFUSED +-- ConnectionResetError ECONNRESET + +-- DirectoryNotEmptyError ENOTEMPTY +-- FileExistsError EEXIST +-- FileNotFoundError ENOENT +-- InterruptedError EINTR +-- IsADirectoryError EISDIR +-- NotADirectoryError ENOTDIR - +-- DirectoryNotEmptyError ENOTEMPTY +-- PermissionError EACCES, EPERM +-- ProcessLookupError ESRCH +-- TimeoutError ETIMEDOUT diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index a3f1a51b11a1e1..e614877f8613da 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -2,6 +2,7 @@ import copy import os +import tempfile import sys import unittest import pickle @@ -1172,8 +1173,14 @@ def inner(): def test_errno_ENOTEMPTY(self): with self.assertRaises(OSError) as cm: - test_dir = os.path.dirname(__file__) - os.rmdir(test_dir) + dirname = tempfile.mkdtemp() + + pkgdir = os.path.join(dirname, "pkgname") + os.mkdir(pkgdir) + with open(os.path.join(pkgdir, '__init__.py'), 'w') as fl: + fl.write('from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n') + + os.rmdir(dirname) self.assertEqual(cm.exception.errno, errno.ENOTEMPTY, cm.exception) def test_errno_ENOTDIR(self): diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 3ec8f0f1d5752c..8f86f6368d6c3a 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -2573,12 +2573,12 @@ _PyExc_Init(void) PRE_INIT(ConnectionAbortedError); PRE_INIT(ConnectionRefusedError); PRE_INIT(ConnectionResetError); + PRE_INIT(DirectoryNotEmptyError); PRE_INIT(FileExistsError); PRE_INIT(FileNotFoundError); + PRE_INIT(InterruptedError); PRE_INIT(IsADirectoryError); PRE_INIT(NotADirectoryError); - PRE_INIT(DirectoryNotEmptyError); - PRE_INIT(InterruptedError); PRE_INIT(PermissionError); PRE_INIT(ProcessLookupError); PRE_INIT(TimeoutError); @@ -2607,12 +2607,12 @@ _PyExc_Init(void) ADD_ERRNO(ConnectionAbortedError, ECONNABORTED); ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED); ADD_ERRNO(ConnectionResetError, ECONNRESET); + ADD_ERRNO(DirectoryNotEmptyError, ENOTEMPTY); ADD_ERRNO(FileExistsError, EEXIST); ADD_ERRNO(FileNotFoundError, ENOENT); + ADD_ERRNO(InterruptedError, EINTR); ADD_ERRNO(IsADirectoryError, EISDIR); ADD_ERRNO(NotADirectoryError, ENOTDIR); - ADD_ERRNO(DirectoryNotEmptyError, ENOTEMPTY); - ADD_ERRNO(InterruptedError, EINTR); ADD_ERRNO(PermissionError, EACCES); ADD_ERRNO(PermissionError, EPERM); ADD_ERRNO(ProcessLookupError, ESRCH); @@ -2715,12 +2715,12 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod) POST_INIT(ConnectionAbortedError); POST_INIT(ConnectionRefusedError); POST_INIT(ConnectionResetError); + POST_INIT(DirectoryNotEmptyError); POST_INIT(FileExistsError); POST_INIT(FileNotFoundError); + POST_INIT(InterruptedError); POST_INIT(IsADirectoryError); POST_INIT(NotADirectoryError); - POST_INIT(DirectoryNotEmptyError); - POST_INIT(InterruptedError); POST_INIT(PermissionError); POST_INIT(ProcessLookupError); POST_INIT(TimeoutError); From 792bd09205c6b72ae4bd496aaab5459426adc091 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com> Date: Thu, 5 Sep 2019 15:25:51 -0300 Subject: [PATCH 7/8] Add Patch by section --- .../Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst b/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst index 46f635ef454391..6b295abc66ee85 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2019-08-26-02-23-20.bpo-32847.A9yGun.rst @@ -1 +1,2 @@ -Add `DirectoryNotEmptyError` subclass of `OSError`. \ No newline at end of file +Add `DirectoryNotEmptyError` subclass of `OSError`. +Patch by Joannah Nanjekye . From fffdd119edf6188d9dfdcb4f32a640cf1c8861c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 12 Sep 2019 11:13:29 +0200 Subject: [PATCH 8/8] Refactor the test and use DirectoryNotEmptyError instead of OSError in the test --- Lib/test/test_exceptions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index e614877f8613da..1988bf30d58993 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1172,14 +1172,14 @@ def inner(): self.assertEqual(wr(), None) def test_errno_ENOTEMPTY(self): - with self.assertRaises(OSError) as cm: - dirname = tempfile.mkdtemp() + dirname = tempfile.mkdtemp() - pkgdir = os.path.join(dirname, "pkgname") - os.mkdir(pkgdir) - with open(os.path.join(pkgdir, '__init__.py'), 'w') as fl: - fl.write('from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n') + pkgdir = os.path.join(dirname, "pkgname") + os.mkdir(pkgdir) + with open(os.path.join(pkgdir, '__init__.py'), 'w') as fl: + fl.write('from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n') + with self.assertRaises(DirectoryNotEmptyError) as cm: os.rmdir(dirname) self.assertEqual(cm.exception.errno, errno.ENOTEMPTY, cm.exception)