summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_support.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-20 14:19:20 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-20 14:19:20 (GMT)
commit0e7dbe901ca5e5587d18bdfaceeba244ab5342ca (patch)
tree65913e436685186ae60ca8ace51abf4ebfcf1d17 /Lib/test/test_support.py
parent92b9a1f9114fc83ba4d3dcc760012097c60a11df (diff)
parent6770f8a4877eba56dd9978caf197795dbc3d3ffb (diff)
downloadcpython-0e7dbe901ca5e5587d18bdfaceeba244ab5342ca.zip
cpython-0e7dbe901ca5e5587d18bdfaceeba244ab5342ca.tar.gz
cpython-0e7dbe901ca5e5587d18bdfaceeba244ab5342ca.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.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 269d9bf..553822b 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
@@ -12,9 +13,6 @@ TESTFN = support.TESTFN
class TestSupport(unittest.TestCase):
- def setUp(self):
- support.unlink(TESTFN)
- tearDown = setUp
def test_import_module(self):
support.import_module("ftplib")
@@ -46,15 +44,28 @@ class TestSupport(unittest.TestCase):
support.unlink(TESTFN)
def test_rmtree(self):
- TESTDIRN = os.path.basename(tempfile.mkdtemp(dir='.'))
- self.addCleanup(support.rmtree, TESTDIRN)
- support.rmtree(TESTDIRN)
-
- 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'