cpython: c3acc5ead883 (original) (raw)
Mercurial > cpython
changeset 81028:c3acc5ead883 3.2
Add test coverage for os.removedirs (#16775) [#16775]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Tue, 25 Dec 2012 12🔞09 +0200 |
parents | d002a2e46383 |
children | dbe9413686b3 2eab4f7b7280 |
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 @@ -634,6 +634,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: @@ -642,6 +686,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) @@ -1310,6 +1355,7 @@ def test_main(): PidTests, LoginTests, LinkTests,