blob: bcae72f1daca5a5b40561f61005a813bd9438c4f [file] [log] [blame]
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00001# Copyright (C) 2003 Python Software Foundation
2
3import unittest
4import shutil
5import tempfile
Brett Cannon1c3fa182004-06-19 21:11:35 +00006import os
7import os.path
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00008from test import test_support
9
10class TestShutil(unittest.TestCase):
11 def test_rmtree_errors(self):
12 # filename is guaranteed not to exist
13 filename = tempfile.mktemp()
14 self.assertRaises(OSError, shutil.rmtree, filename)
15 self.assertEqual(shutil.rmtree(filename, True), None)
Guido van Rossum8cec3ab2004-07-14 00:48:58 +000016 shutil.rmtree(filename, False, lambda func, arg, exc: None)
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000017
Brett Cannon1c3fa182004-06-19 21:11:35 +000018 def test_dont_move_dir_in_itself(self):
19 src_dir = tempfile.mkdtemp()
20 try:
21 dst = os.path.join(src_dir, 'foo')
22 self.assertRaises(shutil.Error, shutil.move, src_dir, dst)
23 finally:
24 try:
25 os.rmdir(src_dir)
26 except:
27 pass
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000028
Brett Cannon1c3fa182004-06-19 21:11:35 +000029
30
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000031def test_main():
Walter Dörwald21d3a322003-05-01 17:45:56 +000032 test_support.run_unittest(TestShutil)
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000033
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000034if __name__ == '__main__':
Walter Dörwald21d3a322003-05-01 17:45:56 +000035 test_main()