update docstr and do not swallow other errno
This commit is contained in:
parent
589eb2dc9c
commit
2956319c39
2 changed files with 4 additions and 10 deletions
|
|
@ -492,8 +492,8 @@ def ensuredir(directory):
|
|||
|
||||
:returns: str: normalized directory path
|
||||
|
||||
:raises OSError: If directory is not a dir or it is root(/) or equivalent
|
||||
but doesn't exist(should not happen).
|
||||
:raises OSError: If argument already exists and is not a directory, or
|
||||
error occurs from underlying `os.mkdir`.
|
||||
"""
|
||||
directory = os.path.normpath(directory)
|
||||
if os.path.exists(directory):
|
||||
|
|
@ -512,8 +512,8 @@ def ensuredir(directory):
|
|||
os.mkdir(directory)
|
||||
except OSError as e:
|
||||
# do not thrown when dir already exists (could happen in a race)
|
||||
if e.errno == errno.EEXIST and not os.path.isdir(directory):
|
||||
#something else must have gone wrong
|
||||
if not os.path.isdir(directory):
|
||||
# something else must have gone wrong
|
||||
raise
|
||||
return directory
|
||||
|
||||
|
|
|
|||
|
|
@ -44,12 +44,6 @@ class TestEnsureDir(unittest.TestCase):
|
|||
ensuredir('path')
|
||||
mock_mkdir.assert_called_once_with('path')
|
||||
|
||||
mock_mkdir.reset_mock()
|
||||
mock_mkdir.side_effect = OSError(errno.EEXIST + 1, 'ignored error')
|
||||
mock_isdir.return_value = False
|
||||
ensuredir('path')
|
||||
mock_mkdir.assert_called_once_with('path')
|
||||
|
||||
@mock.patch('os.mkdir')
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('os.path.isdir')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue