summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-07-08 21:39:08 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-07-08 21:39:08 (GMT)
commitd40e6f70a5edabffcbfff22912163520da3a29e2 (patch)
treeef8d44ca974bf606f3437d2ce9977207b8748174 /Lib/test/test_shutil.py
parent0dd8f7890a3396eaef8c740588c65af9422a65a5 (diff)
downloadcpython-d40e6f70a5edabffcbfff22912163520da3a29e2.zip
cpython-d40e6f70a5edabffcbfff22912163520da3a29e2.tar.gz
cpython-d40e6f70a5edabffcbfff22912163520da3a29e2.tar.bz2
Implement #1578269. Patch by Jason R. Coombs.
Added Windows support for os.symlink when run on Windows 6.0 or greater, aka Vista. Previous Windows versions will raise NotImplementedError when trying to symlink. Includes numerous test updates and additions to test_os, including a symlink_support module because of the fact that privilege escalation is required in order to run the tests to ensure that the user is able to create symlinks. By default, accounts do not have the required privilege, so the escalation code will have to be exposed later (or documented on how to do so). I'll be following up with that work next. Note that the tests use ctypes, which was agreed on during the PyCon language summit.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py57
1 files changed, 29 insertions, 28 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 9f4871b..baa1943 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -271,7 +271,7 @@ class TestShutil(unittest.TestCase):
shutil.rmtree(src_dir)
shutil.rmtree(os.path.dirname(dst_dir))
- @unittest.skipUnless(hasattr(os, 'symlink'), 'requires os.symlink')
+ @support.skip_unless_symlink
def test_dont_copy_file_onto_link_to_itself(self):
# bug 851123.
os.mkdir(TESTFN)
@@ -282,10 +282,11 @@ class TestShutil(unittest.TestCase):
f.write('cheddar')
f.close()
- os.link(src, dst)
- self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
- self.assertEqual(open(src,'r').read(), 'cheddar')
- os.remove(dst)
+ if hasattr(os, "link"):
+ os.link(src, dst)
+ self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
+ self.assertEqual(open(src,'r').read(), 'cheddar')
+ os.remove(dst)
# Using `src` here would mean we end up with a symlink pointing
# to TESTFN/TESTFN/cheese, while it should point at
@@ -300,30 +301,30 @@ class TestShutil(unittest.TestCase):
except OSError:
pass
- @unittest.skipUnless(hasattr(os, 'symlink'), 'requires os.symlink')
- def test_rmtree_on_symlink(self):
- # bug 1669.
- os.mkdir(TESTFN)
- try:
- src = os.path.join(TESTFN, 'cheese')
- dst = os.path.join(TESTFN, 'shop')
- os.mkdir(src)
- os.symlink(src, dst)
- self.assertRaises(OSError, shutil.rmtree, dst)
- finally:
- shutil.rmtree(TESTFN, ignore_errors=True)
-
- @unittest.skipUnless(hasattr(os, 'mkfifo'), 'requires os.mkfifo')
- # Issue #3002: copyfile and copytree block indefinitely on named pipes
- def test_copyfile_named_pipe(self):
- os.mkfifo(TESTFN)
+ @support.skip_unless_symlink
+ def test_rmtree_on_symlink(self):
+ # bug 1669.
+ os.mkdir(TESTFN)
try:
- self.assertRaises(shutil.SpecialFileError,
- shutil.copyfile, TESTFN, TESTFN2)
- self.assertRaises(shutil.SpecialFileError,
- shutil.copyfile, __file__, TESTFN)
+ src = os.path.join(TESTFN, 'cheese')
+ dst = os.path.join(TESTFN, 'shop')
+ os.mkdir(src)
+ os.symlink(src, dst)
+ self.assertRaises(OSError, shutil.rmtree, dst)
finally:
- os.remove(TESTFN)
+ shutil.rmtree(TESTFN, ignore_errors=True)
+
+ if hasattr(os, "mkfifo"):
+ # Issue #3002: copyfile and copytree block indefinitely on named pipes
+ def test_copyfile_named_pipe(self):
+ os.mkfifo(TESTFN)
+ try:
+ self.assertRaises(shutil.SpecialFileError,
+ shutil.copyfile, TESTFN, TESTFN2)
+ self.assertRaises(shutil.SpecialFileError,
+ shutil.copyfile, __file__, TESTFN)
+ finally:
+ os.remove(TESTFN)
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'requires os.mkfifo')
def test_copytree_named_pipe(self):
@@ -361,7 +362,7 @@ class TestShutil(unittest.TestCase):
shutil.copytree(src_dir, dst_dir, copy_function=_copy)
self.assertEquals(len(copied), 2)
- @unittest.skipUnless(hasattr(os, 'symlink'), 'requires os.symlink')
+ @support.skip_unless_symlink
def test_copytree_dangling_symlinks(self):
# a dangling symlink raises an error at the end