|
2 | 2 | import unittest |
3 | 3 | import os |
4 | 4 | import shutil |
| 5 | +import errno |
| 6 | +from unittest.mock import patch |
5 | 7 |
|
6 | 8 | from distutils.file_util import move_file |
7 | 9 | from distutils import log |
8 | 10 | from distutils.tests import support |
| 11 | +from distutils.errors import DistutilsFileError |
9 | 12 | from test.support import run_unittest |
10 | 13 |
|
11 | 14 | class FileUtilTestCase(support.TempdirManager, unittest.TestCase): |
@@ -58,6 +61,23 @@ def test_move_file_verbosity(self): |
58 | 61 | wanted = ['moving %s -> %s' % (self.source, self.target_dir)] |
59 | 62 | self.assertEqual(self._logs, wanted) |
60 | 63 |
|
| 64 | + @patch('os.rename', side_effect=OSError('wrong', 1)) |
| 65 | + def test_move_file_exception_unpacking_rename(self, _): |
| 66 | + # see issue 22182 |
| 67 | + with self.assertRaises(DistutilsFileError): |
| 68 | + with open(self.source, 'w') as fobj: |
| 69 | + fobj.write('spam eggs') |
| 70 | + move_file(self.source, self.target, verbose=0) |
| 71 | + |
| 72 | + @patch('os.rename', side_effect=OSError(errno.EXDEV, 'wrong')) |
| 73 | + @patch('os.unlink', side_effect=OSError('wrong', 1)) |
| 74 | + def test_move_file_exception_unpacking_unlink(self, rename, unlink): |
| 75 | + # see issue 22182 |
| 76 | + with self.assertRaises(DistutilsFileError): |
| 77 | + with open(self.source, 'w') as fobj: |
| 78 | + fobj.write('spam eggs') |
| 79 | + move_file(self.source, self.target, verbose=0) |
| 80 | + |
61 | 81 |
|
62 | 82 | def test_suite(): |
63 | 83 | return unittest.makeSuite(FileUtilTestCase) |
|
0 commit comments