summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-12-10 08:15:23 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-12-10 08:15:23 (GMT)
commitae9a9e9a2d57ec91e7637ae19001ac167bae9038 (patch)
tree713e4e5264fa48dbd9aa7e437723149fdcd8dafb /Lib/test/test_shutil.py
parente53e44f3bb95bed675035d69a7605f6878159e2c (diff)
parentb550110f6485913bf4f5037df11c88158e788993 (diff)
downloadcpython-ae9a9e9a2d57ec91e7637ae19001ac167bae9038.zip
cpython-ae9a9e9a2d57ec91e7637ae19001ac167bae9038.tar.gz
cpython-ae9a9e9a2d57ec91e7637ae19001ac167bae9038.tar.bz2
#15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree
It caused rmtree to not ignore certain errors when ignore_errors was set. Patch by Alessandro Moura and Serhiy Storchaka.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index c3997dc..ad66631 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -127,6 +127,15 @@ class TestShutil(unittest.TestCase):
os.symlink(dir_, link)
self.assertRaises(OSError, shutil.rmtree, link)
self.assertTrue(os.path.exists(dir_))
+ self.assertTrue(os.path.lexists(link))
+ errors = []
+ def onerror(*args):
+ errors.append(args)
+ shutil.rmtree(link, onerror=onerror)
+ self.assertEqual(len(errors), 1)
+ self.assertIs(errors[0][0], os.path.islink)
+ self.assertEqual(errors[0][1], link)
+ self.assertIsInstance(errors[0][2][1], OSError)
@support.skip_unless_symlink
def test_rmtree_works_on_symlinks(self):
@@ -153,7 +162,34 @@ class TestShutil(unittest.TestCase):
def test_rmtree_errors(self):
# filename is guaranteed not to exist
filename = tempfile.mktemp()
- self.assertRaises(OSError, shutil.rmtree, filename)
+ self.assertRaises(FileNotFoundError, shutil.rmtree, filename)
+ # test that ignore_errors option is honored
+ shutil.rmtree(filename, ignore_errors=True)
+
+ # existing file
+ tmpdir = self.mkdtemp()
+ write_file((tmpdir, "tstfile"), "")
+ filename = os.path.join(tmpdir, "tstfile")
+ with self.assertRaises(NotADirectoryError) as cm:
+ shutil.rmtree(filename)
+ self.assertEqual(cm.exception.filename, filename)
+ self.assertTrue(os.path.exists(filename))
+ # test that ignore_errors option is honored
+ shutil.rmtree(filename, ignore_errors=True)
+ self.assertTrue(os.path.exists(filename))
+ errors = []
+ def onerror(*args):
+ errors.append(args)
+ shutil.rmtree(filename, onerror=onerror)
+ self.assertEqual(len(errors), 2)
+ self.assertIs(errors[0][0], os.listdir)
+ self.assertEqual(errors[0][1], filename)
+ self.assertIsInstance(errors[0][2][1], NotADirectoryError)
+ self.assertEqual(errors[0][2][1].filename, filename)
+ self.assertIs(errors[1][0], os.rmdir)
+ self.assertEqual(errors[1][1], filename)
+ self.assertIsInstance(errors[1][2][1], NotADirectoryError)
+ self.assertEqual(errors[1][2][1].filename, filename)
# See bug #1071513 for why we don't run this on cygwin
# and bug #1076467 for why we don't run this as root.