summaryrefslogtreecommitdiff
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2004-10-31 12:05:31 +0000
committerJohannes Gijsbers <jlg@dds.nl>2004-10-31 12:05:31 +0000
commitef5ffc4765c0e1616db774b902328ef87a4b2291 (patch)
tree833b19765b3211cd409c80d95a36eb926930360f /Lib/test/test_shutil.py
parent57341c37c910ea0fc31f0576be74e9ad4c49a4cf (diff)
downloadcpython-git-ef5ffc4765c0e1616db774b902328ef87a4b2291.tar.gz
Bug #1048941: shutil.rmtree error handling was always broken
Rewrite rmtree again, this time without os.walk(). Error handling had been broken since Python 2.3, and the os.walk() version inherited this.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index f8367a60c2..d6160c6b40 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1,8 +1,10 @@
+
# Copyright (C) 2003 Python Software Foundation
import unittest
import shutil
import tempfile
+import stat
import os
import os.path
from test import test_support
@@ -13,8 +15,32 @@ class TestShutil(unittest.TestCase):
# filename is guaranteed not to exist
filename = tempfile.mktemp()
self.assertRaises(OSError, shutil.rmtree, filename)
- self.assertEqual(shutil.rmtree(filename, True), None)
- shutil.rmtree(filename, False, lambda func, arg, exc: None)
+
+ if hasattr(os, 'chmod'):
+ def test_on_error(self):
+ self.errorState = 0
+ os.mkdir(TESTFN)
+ f = open(os.path.join(TESTFN, 'a'), 'w')
+ f.close()
+ # Make TESTFN unwritable.
+ os.chmod(TESTFN, stat.S_IRUSR)
+
+ shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
+
+ # Make TESTFN writable again.
+ os.chmod(TESTFN, stat.S_IRWXU)
+ shutil.rmtree(TESTFN)
+
+ def check_args_to_onerror(self, func, arg, exc):
+ if self.errorState == 0:
+ self.assertEqual(func, os.remove)
+ self.assertEqual(arg, os.path.join(TESTFN, 'a'))
+ self.assertEqual(exc[0], OSError)
+ self.errorState = 1
+ else:
+ self.assertEqual(func, os.rmdir)
+ self.assertEqual(arg, TESTFN)
+ self.assertEqual(exc[0], OSError)
def test_rmtree_dont_delete_file(self):
# When called on a file instead of a directory, don't delete it.
@@ -63,7 +89,6 @@ class TestShutil(unittest.TestCase):
except OSError:
pass
-
def test_main():
test_support.run_unittest(TestShutil)