mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #22182: Use e.args to unpack exceptions correctly in distutils.file_util.move_file.
Patch by Claudiu Popa.
This commit is contained in:
parent
59e0802301
commit
6685883c02
3 changed files with 25 additions and 2 deletions
|
@ -2,10 +2,13 @@
|
|||
import unittest
|
||||
import os
|
||||
import shutil
|
||||
import errno
|
||||
from unittest.mock import patch
|
||||
|
||||
from distutils.file_util import move_file
|
||||
from distutils import log
|
||||
from distutils.tests import support
|
||||
from distutils.errors import DistutilsFileError
|
||||
from test.support import run_unittest
|
||||
|
||||
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
|
||||
|
@ -58,6 +61,23 @@ class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
|
|||
wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
|
||||
self.assertEqual(self._logs, wanted)
|
||||
|
||||
@patch('os.rename', side_effect=OSError('wrong', 1))
|
||||
def test_move_file_exception_unpacking_rename(self, _):
|
||||
# see issue 22182
|
||||
with self.assertRaises(DistutilsFileError):
|
||||
with open(self.source, 'w') as fobj:
|
||||
fobj.write('spam eggs')
|
||||
move_file(self.source, self.target, verbose=0)
|
||||
|
||||
@patch('os.rename', side_effect=OSError(errno.EXDEV, 'wrong'))
|
||||
@patch('os.unlink', side_effect=OSError('wrong', 1))
|
||||
def test_move_file_exception_unpacking_unlink(self, rename, unlink):
|
||||
# see issue 22182
|
||||
with self.assertRaises(DistutilsFileError):
|
||||
with open(self.source, 'w') as fobj:
|
||||
fobj.write('spam eggs')
|
||||
move_file(self.source, self.target, verbose=0)
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(FileUtilTestCase)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue