Kaydet (Commit) 4590c00e authored tarafından Tim Peters's avatar Tim Peters

test_on_error(): Rewrite so it works on WinXP too. Unsure about 95/98/ME.

üst e2d59184
# Copyright (C) 2003 Python Software Foundation # Copyright (C) 2003 Python Software Foundation
import unittest import unittest
...@@ -20,21 +19,28 @@ class TestShutil(unittest.TestCase): ...@@ -20,21 +19,28 @@ class TestShutil(unittest.TestCase):
def test_on_error(self): def test_on_error(self):
self.errorState = 0 self.errorState = 0
os.mkdir(TESTFN) os.mkdir(TESTFN)
f = open(os.path.join(TESTFN, 'a'), 'w') self.childpath = os.path.join(TESTFN, 'a')
f = open(self.childpath, 'w')
f.close() f.close()
# Make TESTFN unwritable. old_dir_mode = os.stat(TESTFN).st_mode
os.chmod(TESTFN, stat.S_IRUSR) old_child_mode = os.stat(self.childpath).st_mode
# Make unwritable.
os.chmod(self.childpath, stat.S_IREAD)
os.chmod(TESTFN, stat.S_IREAD)
shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror) shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
# Make TESTFN writable again. # Make writable again.
os.chmod(TESTFN, stat.S_IRWXU) os.chmod(TESTFN, old_dir_mode)
os.chmod(self.childpath, old_child_mode)
# Clean up.
shutil.rmtree(TESTFN) shutil.rmtree(TESTFN)
def check_args_to_onerror(self, func, arg, exc): def check_args_to_onerror(self, func, arg, exc):
if self.errorState == 0: if self.errorState == 0:
self.assertEqual(func, os.remove) self.assertEqual(func, os.remove)
self.assertEqual(arg, os.path.join(TESTFN, 'a')) self.assertEqual(arg, self.childpath)
self.assertEqual(exc[0], OSError) self.assertEqual(exc[0], OSError)
self.errorState = 1 self.errorState = 1
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment