diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-25 10:18:09 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-25 10:18:09 (GMT) |
commit | 405faed511dded5749c36defa6c0c1e0cc0d1e6e (patch) | |
tree | e85b88b9f1dd802e4b142fc95d329e582133efce | |
parent | ed30199e7836ff52a101a9ea3a2b31f8455a85a8 (diff) | |
download | cpython-405faed511dded5749c36defa6c0c1e0cc0d1e6e.zip cpython-405faed511dded5749c36defa6c0c1e0cc0d1e6e.tar.gz cpython-405faed511dded5749c36defa6c0c1e0cc0d1e6e.tar.bz2 |
Add test coverage for os.removedirs (#16775)
-rw-r--r-- | 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 index 612c62a..5b67da1 100644 --- 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 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: @@ -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, + RemoveDirsTests, ) if __name__ == "__main__": |