cpython: dbe9413686b3 (original) (raw)
Mercurial > cpython
changeset 81029:dbe9413686b3 3.3
Add test coverage for os.removedirs (#16775) [#16775]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Tue, 25 Dec 2012 12:20:39 +0200 |
parents | 727f26d1806f(current diff)c3acc5ead883(diff) |
children | 60240ce64789 356af3fc6471 |
files | Lib/test/test_os.py |
diffstat | 1 files changed, 46 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_os.py 46 |
line wrap: on
line diff
--- 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 test_remove_all(self):
dira = os.path.join(support.TESTFN, 'dira')[](#l1.16)
os.mkdir(dira)[](#l1.17)
dirb = os.path.join(dira, 'dirb')[](#l1.18)
os.mkdir(dirb)[](#l1.19)
os.removedirs(dirb)[](#l1.20)
self.assertFalse(os.path.exists(dirb))[](#l1.21)
self.assertFalse(os.path.exists(dira))[](#l1.22)
self.assertFalse(os.path.exists(support.TESTFN))[](#l1.23)
- def test_remove_partial(self):
dira = os.path.join(support.TESTFN, 'dira')[](#l1.26)
os.mkdir(dira)[](#l1.27)
dirb = os.path.join(dira, 'dirb')[](#l1.28)
os.mkdir(dirb)[](#l1.29)
with open(os.path.join(dira, 'file.txt'), 'w') as f:[](#l1.30)
f.write('text')[](#l1.31)
os.removedirs(dirb)[](#l1.32)
self.assertFalse(os.path.exists(dirb))[](#l1.33)
self.assertTrue(os.path.exists(dira))[](#l1.34)
self.assertTrue(os.path.exists(support.TESTFN))[](#l1.35)
- def test_remove_nothing(self):
dira = os.path.join(support.TESTFN, 'dira')[](#l1.38)
os.mkdir(dira)[](#l1.39)
dirb = os.path.join(dira, 'dirb')[](#l1.40)
os.mkdir(dirb)[](#l1.41)
with open(os.path.join(dirb, 'file.txt'), 'w') as f:[](#l1.42)
f.write('text')[](#l1.43)
with self.assertRaises(OSError):[](#l1.44)
os.removedirs(dirb)[](#l1.45)
self.assertTrue(os.path.exists(dirb))[](#l1.46)
self.assertTrue(os.path.exists(dira))[](#l1.47)
self.assertTrue(os.path.exists(support.TESTFN))[](#l1.48)
+ + 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) @@ -2078,6 +2123,7 @@ def test_main(): ExtendedAttributeTests, Win32DeprecatedBytesAPI, TermsizeTests,