Commit b8ad4ac0 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 76101 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76101 | antoine.pitrou | 2009-11-04 01:50:26 +0100 (mer., 04 nov. 2009) | 3 lines

  Make test_shutil clean up after itself
........
parent 1b5d4e2f
......@@ -103,7 +103,7 @@ class TestShutil(unittest.TestCase):
if os.path.exists(path):
os.remove(path)
for path in (src_dir,
os.path.abspath(os.path.join(dst_dir, os.path.pardir))
os.path.dirname(dst_dir)
):
if os.path.exists(path):
shutil.rmtree(path)
......@@ -125,6 +125,7 @@ class TestShutil(unittest.TestCase):
join = os.path.join
exists = os.path.exists
src_dir = tempfile.mkdtemp()
try:
dst_dir = join(tempfile.mkdtemp(), 'destination')
write_data(join(src_dir, 'test.txt'), '123')
write_data(join(src_dir, 'test.tmp'), '123')
......@@ -137,15 +138,14 @@ class TestShutil(unittest.TestCase):
write_data(join(src_dir, 'test_dir2', 'subdir', 'test.txt'), '456')
write_data(join(src_dir, 'test_dir2', 'subdir2', 'test.py'), '456')
# testing glob-like patterns
try:
patterns = shutil.ignore_patterns('*.tmp', 'test_dir2')
shutil.copytree(src_dir, dst_dir, ignore=patterns)
# checking the result: some elements should not be copied
self.assert_(exists(join(dst_dir, 'test.txt')))
self.assert_(not exists(join(dst_dir, 'test.tmp')))
self.assert_(not exists(join(dst_dir, 'test_dir2')))
self.assertTrue(exists(join(dst_dir, 'test.txt')))
self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
self.assertTrue(not exists(join(dst_dir, 'test_dir2')))
finally:
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
......@@ -153,9 +153,9 @@ class TestShutil(unittest.TestCase):
patterns = shutil.ignore_patterns('*.tmp', 'subdir*')
shutil.copytree(src_dir, dst_dir, ignore=patterns)
# checking the result: some elements should not be copied
self.assert_(not exists(join(dst_dir, 'test.tmp')))
self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir')))
self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
finally:
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
......@@ -177,13 +177,16 @@ class TestShutil(unittest.TestCase):
shutil.copytree(src_dir, dst_dir, ignore=_filter)
# checking the result: some elements should not be copied
self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir2',
self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2',
'test.py')))
self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir')))
self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
finally:
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
finally:
shutil.rmtree(src_dir)
shutil.rmtree(os.path.dirname(dst_dir))
if hasattr(os, "symlink"):
def test_dont_copy_file_onto_link_to_itself(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment