mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
shutil.move() will raise an exception when trying to move a directory into
itself. Closes bug #919012 . Thanks Johannes Gijsbers.
This commit is contained in:
parent
b46ed71d70
commit
1c3fa18be7
4 changed files with 24 additions and 2 deletions
|
@ -3,6 +3,8 @@
|
|||
import unittest
|
||||
import shutil
|
||||
import tempfile
|
||||
import os
|
||||
import os.path
|
||||
from test import test_support
|
||||
|
||||
class TestShutil(unittest.TestCase):
|
||||
|
@ -12,11 +14,21 @@ class TestShutil(unittest.TestCase):
|
|||
self.assertRaises(OSError, shutil.rmtree, filename)
|
||||
self.assertEqual(shutil.rmtree(filename, True), None)
|
||||
|
||||
def test_dont_move_dir_in_itself(self):
|
||||
src_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
dst = os.path.join(src_dir, 'foo')
|
||||
self.assertRaises(shutil.Error, shutil.move, src_dir, dst)
|
||||
finally:
|
||||
try:
|
||||
os.rmdir(src_dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(TestShutil)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue