summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-25 10:21:49 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-25 10:21:49 (GMT)
commit914ab8420e069499ad8a2d9b3f1ad584bd26a813 (patch)
tree992729dd084446067b3c97c7303ea845e7e16951 /Lib
parent750909e61823d896f84d44ae25ae6f08a46d387f (diff)
parent34dcdee1770b0bfc9798280d378388056bf7d559 (diff)
downloadcpython-914ab8420e069499ad8a2d9b3f1ad584bd26a813.zip
cpython-914ab8420e069499ad8a2d9b3f1ad584bd26a813.tar.gz
cpython-914ab8420e069499ad8a2d9b3f1ad584bd26a813.tar.bz2
Add test coverage for os.removedirs (#16775)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index cc9bd4e..d479461 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -905,6 +905,50 @@ class MakedirTests(unittest.TestCase):
os.removedirs(path)
+
+class RemoveDirsTests(unittest.TestCase):
+ def setUp(self):
+ os.makedirs(support.TESTFN)
+
+ def tearDown(self):
+ support.rmtree(support.TESTFN)
+
+ def test_remove_all(self):
+ dira = os.path.join(support.TESTFN, 'dira')
+ os.mkdir(dira)
+ dirb = os.path.join(dira, 'dirb')
+ os.mkdir(dirb)
+ os.removedirs(dirb)
+ self.assertFalse(os.path.exists(dirb))
+ self.assertFalse(os.path.exists(dira))
+ self.assertFalse(os.path.exists(support.TESTFN))
+
+ def test_remove_partial(self):
+ dira = os.path.join(support.TESTFN, 'dira')
+ os.mkdir(dira)
+ dirb = os.path.join(dira, 'dirb')
+ os.mkdir(dirb)
+ with open(os.path.join(dira, 'file.txt'), 'w') as f:
+ f.write('text')
+ os.removedirs(dirb)
+ self.assertFalse(os.path.exists(dirb))
+ self.assertTrue(os.path.exists(dira))
+ self.assertTrue(os.path.exists(support.TESTFN))
+
+ def test_remove_nothing(self):
+ dira = os.path.join(support.TESTFN, 'dira')
+ os.mkdir(dira)
+ dirb = os.path.join(dira, 'dirb')
+ os.mkdir(dirb)
+ with open(os.path.join(dirb, 'file.txt'), 'w') as f:
+ f.write('text')
+ with self.assertRaises(OSError):
+ os.removedirs(dirb)
+ self.assertTrue(os.path.exists(dirb))
+ self.assertTrue(os.path.exists(dira))
+ self.assertTrue(os.path.exists(support.TESTFN))
+
+
class DevNullTests(unittest.TestCase):
def test_devnull(self):
with open(os.devnull, 'wb') as f:
@@ -913,6 +957,7 @@ class DevNullTests(unittest.TestCase):
with open(os.devnull, 'rb') as f:
self.assertEqual(f.read(), b'')
+
class URandomTests(unittest.TestCase):
def test_urandom_length(self):
self.assertEqual(len(os.urandom(0)), 0)
@@ -2176,6 +2221,7 @@ def test_main():
Win32DeprecatedBytesAPI,
TermsizeTests,
OSErrorTests,
+ RemoveDirsTests,
)
if __name__ == "__main__":