diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2010-12-05 02:04:16 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2010-12-05 02:04:16 (GMT) |
commit | 2668145dbdd11cc3eef44f0b14adfafb93f9fe0b (patch) | |
tree | 6ef523bd53edccf53734cd3fc1d109f15daba403 /Lib | |
parent | c269ae87c1ee66b5ddde3132a4c7fa3c01870079 (diff) | |
download | cpython-2668145dbdd11cc3eef44f0b14adfafb93f9fe0b.zip cpython-2668145dbdd11cc3eef44f0b14adfafb93f9fe0b.tar.gz cpython-2668145dbdd11cc3eef44f0b14adfafb93f9fe0b.tar.bz2 |
Now can reproduce the error on AMD64 Windows Server 2008
even where os.symlink is not supported.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_shutil.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index a5497e5..ee35595 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -271,25 +271,33 @@ class TestShutil(unittest.TestCase): shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir)) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # bug 851123. os.mkdir(TESTFN) src = os.path.join(TESTFN, 'cheese') dst = os.path.join(TESTFN, 'shop') try: - f = open(src, 'w') - f.write('cheddar') - f.close() - - if hasattr(os, "link"): - os.link(src, dst) - self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - with open(src, 'r') as f: - self.assertEqual(f.read(), 'cheddar') - os.remove(dst) + with open(src, 'w') as f: + f.write('cheddar') + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) + @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 # to TESTFN/TESTFN/cheese, while it should point at # TESTFN/cheese. @@ -299,10 +307,7 @@ class TestShutil(unittest.TestCase): self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: - try: - shutil.rmtree(TESTFN) - except OSError: - pass + shutil.rmtree(TESTFN, ignore_errors=True) @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") |