diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2014-12-10 02:51:36 +0200 |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2014-12-10 02:51:36 +0200 |
commit | 5de4a3cfc5d410116ef1b1cd2d3726518f108776 (patch) | |
tree | ccddb0bec6e9d4195ea31d5d75c81ea8b7b22b4e /Lib/test/test_shutil.py | |
parent | 0a2e874eead3238b86f6521ddc66f73061e1f236 (diff) | |
parent | 884afd92f5a194e326df2be8279d4ab160c7b0c9 (diff) | |
download | cpython-git-5de4a3cfc5d410116ef1b1cd2d3726518f108776.tar.gz |
Issue #21775: shutil.copytree(): fix crash when copying to VFAT
An exception handler assumed that that OSError objects always have a
'winerror' attribute. That is not the case, so the exception handler
itself raised AttributeError when run on Linux (and, presumably, any
other non-Windows OS).
Patch by Greg Ward.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r-- | Lib/test/test_shutil.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index b1f5bbeb04..c5545ba3b3 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1,6 +1,7 @@ # Copyright (C) 2003 Python Software Foundation import unittest +import unittest.mock import shutil import tempfile import sys @@ -764,6 +765,20 @@ class TestShutil(unittest.TestCase): self.assertEqual(os.stat(restrictive_subdir).st_mode, os.stat(restrictive_subdir_dst).st_mode) + @unittest.mock.patch('os.chmod') + def test_copytree_winerror(self, mock_patch): + # When copying to VFAT, copystat() raises OSError. On Windows, the + # exception object has a meaningful 'winerror' attribute, but not + # on other operating systems. Do not assume 'winerror' is set. + src_dir = tempfile.mkdtemp() + dst_dir = os.path.join(tempfile.mkdtemp(), 'destination') + self.addCleanup(shutil.rmtree, src_dir) + self.addCleanup(shutil.rmtree, os.path.dirname(dst_dir)) + + mock_patch.side_effect = PermissionError('ka-boom') + with self.assertRaises(shutil.Error): + shutil.copytree(src_dir, dst_dir) + @unittest.skipIf(os.name == 'nt', 'temporarily disabled on Windows') @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): |