[Python-checkins] cpython (merge 3.2 -> 3.3): Add test coverage for os.removedirs (#16775)
andrew.svetlov
python-checkins at python.org
Tue Dec 25 11:22:03 CET 2012
http://hg.python.org/cpython/rev/dbe9413686b3
changeset: 81029:dbe9413686b3
branch: 3.3
parent: 81025:727f26d1806f
parent: 81028:c3acc5ead883
user: Andrew Svetlov <andrew.svetlov at gmail.com>
date: Tue Dec 25 12:20:39 2012 +0200
summary:
Add test coverage for os.removedirs (#16775)
files:
Lib/test/test_os.py | 46 +++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -905,6 +905,50 @@
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 @@
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)
@@ -2078,6 +2123,7 @@
ExtendedAttributeTests,
Win32DeprecatedBytesAPI,
TermsizeTests,
+ RemoveDirsTests,
)
if __name__ == "__main__":
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list