diff options
| author | Ned Deily <nad@acm.org> | 2012-05-11 00:45:49 (GMT) |
|---|---|---|
| committer | Ned Deily <nad@acm.org> | 2012-05-11 00:45:49 (GMT) |
| commit | acdc56d0d0ccea89d219d126c3ca1b9a28456bd5 (patch) | |
| tree | dfd3900dbe714784a2f187bb6887255c9894d514 /Lib/test/test_shutil.py | |
| parent | b79a01f9046ef0659eb9e68811ac0af4af7e16f4 (diff) | |
| download | cpython-acdc56d0d0ccea89d219d126c3ca1b9a28456bd5.zip cpython-acdc56d0d0ccea89d219d126c3ca1b9a28456bd5.tar.gz cpython-acdc56d0d0ccea89d219d126c3ca1b9a28456bd5.tar.bz2 | |
Issue #14662: Prevent shutil failures on OS X when destination does not
support chflag operations. (Patch by Hynek Schlawack)
Diffstat (limited to 'Lib/test/test_shutil.py')
| -rw-r--r-- | Lib/test/test_shutil.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index b4e5415..9bdb724 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -7,6 +7,7 @@ import sys import stat import os import os.path +import errno from os.path import splitdrive from distutils.spawn import find_executable, spawn from shutil import (_make_tarball, _make_zipfile, make_archive, @@ -339,6 +340,35 @@ class TestShutil(unittest.TestCase): shutil.rmtree(TESTFN, ignore_errors=True) shutil.rmtree(TESTFN2, ignore_errors=True) + @unittest.skipUnless(hasattr(os, 'chflags') and + hasattr(errno, 'EOPNOTSUPP') and + hasattr(errno, 'ENOTSUP'), + "requires os.chflags, EOPNOTSUPP & ENOTSUP") + def test_copystat_handles_harmless_chflags_errors(self): + tmpdir = self.mkdtemp() + file1 = os.path.join(tmpdir, 'file1') + file2 = os.path.join(tmpdir, 'file2') + self.write_file(file1, 'xxx') + self.write_file(file2, 'xxx') + + def make_chflags_raiser(err): + ex = OSError() + + def _chflags_raiser(path, flags): + ex.errno = err + raise ex + return _chflags_raiser + old_chflags = os.chflags + try: + for err in errno.EOPNOTSUPP, errno.ENOTSUP: + os.chflags = make_chflags_raiser(err) + shutil.copystat(file1, file2) + # assert others errors break it + os.chflags = make_chflags_raiser(errno.EOPNOTSUPP + errno.ENOTSUP) + self.assertRaises(OSError, shutil.copystat, file1, file2) + finally: + os.chflags = old_chflags + @unittest.skipUnless(zlib, "requires zlib") def test_make_tarball(self): # creating something to tar |
