diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 14:16:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 14:16:06 (GMT) |
commit | 6770f8a4877eba56dd9978caf197795dbc3d3ffb (patch) | |
tree | f3dc4cf48d19a2e5d40a421e7c89fdb9c659b574 /Lib/test/test_support.py | |
parent | f675a37ed3d033bd62af470540cfe50d9767a529 (diff) | |
download | cpython-6770f8a4877eba56dd9978caf197795dbc3d3ffb.zip cpython-6770f8a4877eba56dd9978caf197795dbc3d3ffb.tar.gz cpython-6770f8a4877eba56dd9978caf197795dbc3d3ffb.tar.bz2 |
Issue #28666: Now test.support.rmtree is able to remove unwritable or
unreadable directories.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 2c00417..30f9f10 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -1,5 +1,6 @@ import importlib import shutil +import stat import sys import os import unittest @@ -9,14 +10,9 @@ import errno from test import support TESTFN = support.TESTFN -TESTDIRN = os.path.basename(tempfile.mkdtemp(dir='.')) class TestSupport(unittest.TestCase): - def setUp(self): - support.unlink(TESTFN) - support.rmtree(TESTDIRN) - tearDown = setUp def test_import_module(self): support.import_module("ftplib") @@ -48,11 +44,28 @@ class TestSupport(unittest.TestCase): support.unlink(TESTFN) def test_rmtree(self): - os.mkdir(TESTDIRN) - os.mkdir(os.path.join(TESTDIRN, TESTDIRN)) - support.rmtree(TESTDIRN) - self.assertFalse(os.path.exists(TESTDIRN)) - support.rmtree(TESTDIRN) + dirpath = support.TESTFN + 'd' + subdirpath = os.path.join(dirpath, 'subdir') + os.mkdir(dirpath) + os.mkdir(subdirpath) + support.rmtree(dirpath) + self.assertFalse(os.path.exists(dirpath)) + with support.swap_attr(support, 'verbose', 0): + support.rmtree(dirpath) + + os.mkdir(dirpath) + os.mkdir(subdirpath) + os.chmod(dirpath, stat.S_IRUSR|stat.S_IXUSR) + with support.swap_attr(support, 'verbose', 0): + support.rmtree(dirpath) + self.assertFalse(os.path.exists(dirpath)) + + os.mkdir(dirpath) + os.mkdir(subdirpath) + os.chmod(dirpath, 0) + with support.swap_attr(support, 'verbose', 0): + support.rmtree(dirpath) + self.assertFalse(os.path.exists(dirpath)) def test_forget(self): mod_filename = TESTFN + '.py' |