cpython: 60240ce64789 (original) (raw)
Mercurial > cpython
changeset 81030:60240ce64789
Add test coverage for os.removedirs (#16775) [#16775]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Tue, 25 Dec 2012 12:21:49 +0200 |
parents | e147d5f3c897(current diff)dbe9413686b3(diff) |
children | 3a86a3f1d89a |
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) @@ -2176,6 +2221,7 @@ def test_main(): Win32DeprecatedBytesAPI, TermsizeTests, OSErrorTests,