diff options
author | Ned Deily <nad@acm.org> | 2012-05-11 00:05:19 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2012-05-11 00:05:19 (GMT) |
commit | baf75713c76ee9b1c3213429d05c3a12adb447af (patch) | |
tree | a268824145e2dc07b36369ca76f4aeafaa0cbe48 /Lib/test/test_shutil.py | |
parent | 569d0875741df1ab196531fb4098b5e5e640aa61 (diff) | |
download | cpython-baf75713c76ee9b1c3213429d05c3a12adb447af.zip cpython-baf75713c76ee9b1c3213429d05c3a12adb447af.tar.gz cpython-baf75713c76ee9b1c3213429d05c3a12adb447af.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 | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 6c9515e..4700a49 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -282,6 +282,35 @@ class TestShutil(unittest.TestCase): self.assertTrue(abs(os.stat(src).st_mtime - os.stat(dst).st_mtime) < 00000.1) + @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') + write_file(file1, 'xxx') + 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 + @support.skip_unless_symlink def test_copy_symlinks(self): tmp_dir = self.mkdtemp() |