Commit 2668145d authored by Hirokazu Yamamoto's avatar Hirokazu Yamamoto

Now can reproduce the error on AMD64 Windows Server 2008

even where os.symlink is not supported.
parent c269ae87
...@@ -271,25 +271,33 @@ class TestShutil(unittest.TestCase): ...@@ -271,25 +271,33 @@ class TestShutil(unittest.TestCase):
shutil.rmtree(src_dir) shutil.rmtree(src_dir)
shutil.rmtree(os.path.dirname(dst_dir)) shutil.rmtree(os.path.dirname(dst_dir))
@unittest.skipUnless(hasattr(os, "symlink"), @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
"Missing symlink implementation")
def test_dont_copy_file_onto_link_to_itself(self): def test_dont_copy_file_onto_link_to_itself(self):
# bug 851123. # bug 851123.
os.mkdir(TESTFN) os.mkdir(TESTFN)
src = os.path.join(TESTFN, 'cheese') src = os.path.join(TESTFN, 'cheese')
dst = os.path.join(TESTFN, 'shop') dst = os.path.join(TESTFN, 'shop')
try: try:
f = open(src, 'w') with open(src, 'w') as f:
f.write('cheddar') f.write('cheddar')
f.close() os.link(src, dst)
self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
if hasattr(os, "link"): with open(src, 'r') as f:
os.link(src, dst) self.assertEqual(f.read(), 'cheddar')
self.assertRaises(shutil.Error, shutil.copyfile, src, dst) os.remove(dst)
with open(src, 'r') as f: finally:
self.assertEqual(f.read(), 'cheddar') shutil.rmtree(TESTFN, ignore_errors=True)
os.remove(dst)
@unittest.skipUnless(hasattr(os, "symlink"),
"Missing symlink implementation")
def test_dont_copy_file_onto_symlink_to_itself(self):
# bug 851123.
os.mkdir(TESTFN)
src = os.path.join(TESTFN, 'cheese')
dst = os.path.join(TESTFN, 'shop')
try:
with open(src, 'w') as f:
f.write('cheddar')
# Using `src` here would mean we end up with a symlink pointing # Using `src` here would mean we end up with a symlink pointing
# to TESTFN/TESTFN/cheese, while it should point at # to TESTFN/TESTFN/cheese, while it should point at
# TESTFN/cheese. # TESTFN/cheese.
...@@ -299,10 +307,7 @@ class TestShutil(unittest.TestCase): ...@@ -299,10 +307,7 @@ class TestShutil(unittest.TestCase):
self.assertEqual(f.read(), 'cheddar') self.assertEqual(f.read(), 'cheddar')
os.remove(dst) os.remove(dst)
finally: finally:
try: shutil.rmtree(TESTFN, ignore_errors=True)
shutil.rmtree(TESTFN)
except OSError:
pass
@unittest.skipUnless(hasattr(os, "symlink"), @unittest.skipUnless(hasattr(os, "symlink"),
"Missing symlink implementation") "Missing symlink implementation")
......
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