diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-11-01 02:40:52 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-11-01 02:40:52 (GMT) |
commit | 4590c00e89e349d6ec7247d1c4e7e22222e8ae76 (patch) | |
tree | a794eb24a8253773f812ff4f716993844c3a3da7 /Lib/test/test_shutil.py | |
parent | e2d591847c2a2b3f02d9b7bb4242cd92d9297ec9 (diff) | |
download | cpython-4590c00e89e349d6ec7247d1c4e7e22222e8ae76.zip cpython-4590c00e89e349d6ec7247d1c4e7e22222e8ae76.tar.gz cpython-4590c00e89e349d6ec7247d1c4e7e22222e8ae76.tar.bz2 |
test_on_error(): Rewrite so it works on WinXP too. Unsure about 95/98/ME.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r-- | Lib/test/test_shutil.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index d6160c6..32197b3 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1,4 +1,3 @@ - # Copyright (C) 2003 Python Software Foundation import unittest @@ -20,21 +19,28 @@ class TestShutil(unittest.TestCase): def test_on_error(self): self.errorState = 0 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() - # Make TESTFN unwritable. - os.chmod(TESTFN, stat.S_IRUSR) + old_dir_mode = os.stat(TESTFN).st_mode + 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) - # Make TESTFN writable again. - os.chmod(TESTFN, stat.S_IRWXU) + # Make writable again. + os.chmod(TESTFN, old_dir_mode) + os.chmod(self.childpath, old_child_mode) + + # Clean up. 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(arg, self.childpath) self.assertEqual(exc[0], OSError) self.errorState = 1 else: |