diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-12-28 14:31:47 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-12-28 14:31:47 (GMT) |
commit | 3b4499c5c7718a2aca8558b857dfe02cc4a80cd9 (patch) | |
tree | e952e750f0913c99ca1d4b021736476baab55408 /Lib/test | |
parent | baab9d0bf6d1627aa292a7639878ae9ba46fc2ca (diff) | |
download | cpython-3b4499c5c7718a2aca8558b857dfe02cc4a80cd9.zip cpython-3b4499c5c7718a2aca8558b857dfe02cc4a80cd9.tar.gz cpython-3b4499c5c7718a2aca8558b857dfe02cc4a80cd9.tar.bz2 |
Fix #9333. The symlink function is always available now, raising OSError
when the user doesn't hold the symbolic link privilege rather than hiding it.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support.py | 22 | ||||
-rw-r--r-- | Lib/test/test_glob.py | 7 | ||||
-rw-r--r-- | Lib/test/test_httpservers.py | 2 | ||||
-rw-r--r-- | Lib/test/test_os.py | 6 | ||||
-rw-r--r-- | Lib/test/test_platform.py | 3 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 2 | ||||
-rw-r--r-- | Lib/test/test_shutil.py | 12 | ||||
-rw-r--r-- | Lib/test/test_sysconfig.py | 5 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 6 |
9 files changed, 38 insertions, 27 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 27efd37..142a87e 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -43,7 +43,7 @@ __all__ = [ "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754", - "TestHandler", "Matcher"] + "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink"] class Error(Exception): @@ -1412,3 +1412,23 @@ class Matcher(object): else: result = dv.find(v) >= 0 return result + + +_can_symlink = None +def can_symlink(): + global _can_symlink + if _can_symlink is not None: + return _can_symlink + try: + os.symlink(TESTFN, TESTFN + "can_symlink") + can = True + except OSError: + can = False + _can_symlink = can + return can + +def skip_unless_symlink(test): + """Skip decorator for tests that require functional symlink""" + ok = can_symlink() + msg = "Requires functional symlink implementation" + return test if ok else unittest.skip(msg)(test) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index f1e1c03..1560a6b 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -1,5 +1,5 @@ import unittest -from test.support import run_unittest, TESTFN +from test.support import run_unittest, TESTFN, skip_unless_symlink, can_symlink import glob import os import shutil @@ -25,7 +25,7 @@ class GlobTests(unittest.TestCase): self.mktemp('ZZZ') self.mktemp('a', 'bcd', 'EF') self.mktemp('a', 'bcd', 'efg', 'ha') - if hasattr(os, "symlink"): + if can_symlink(): os.symlink(self.norm('broken'), self.norm('sym1')) os.symlink(self.norm('broken'), self.norm('sym2')) @@ -98,8 +98,7 @@ class GlobTests(unittest.TestCase): # either of these results are reasonable self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @skip_unless_symlink def test_glob_broken_symlinks(self): eq = self.assertSequencesEqual_noorder eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2')]) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 19d3d17..e42038a 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -304,7 +304,7 @@ class CGIHTTPServerTestCase(BaseTestCase): # The shebang line should be pure ASCII: use symlink if possible. # See issue #7668. - if hasattr(os, "symlink"): + if support.can_symlink(): self.pythonexe = os.path.join(self.parent_dir, 'python') os.symlink(sys.executable, self.pythonexe) else: diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 9cfd7b8..497d809 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -541,7 +541,7 @@ class WalkTests(unittest.TestCase): f = open(path, "w") f.write("I'm " + path + " and proud of it. Blame test_os.\n") f.close() - if hasattr(os, "symlink"): + if support.can_symlink(): os.symlink(os.path.abspath(t2_path), link_path) sub2_tree = (sub2_path, ["link"], ["tmp3"]) else: @@ -585,7 +585,7 @@ class WalkTests(unittest.TestCase): self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"])) self.assertEqual(all[2 - 2 * flipped], sub2_tree) - if hasattr(os, "symlink"): + if support.can_symlink(): # Walk, following symlinks. for root, dirs, files in os.walk(walk_path, followlinks=True): if root == link_path: @@ -1149,7 +1149,7 @@ class Win32KillTests(unittest.TestCase): @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") -@unittest.skipUnless(hasattr(os, "symlink"), "Requires symlink implementation") +@support.skip_unless_symlink class Win32SymlinkTests(unittest.TestCase): filelink = 'filelinktest' filelink_target = os.path.abspath(__file__) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 7264c57..7dd7eef 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -10,8 +10,7 @@ class PlatformTest(unittest.TestCase): def test_architecture(self): res = platform.architecture() - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_architecture_via_symlink(self): # issue3762 # On Windows, the EXE needs to know where pythonXY.dll is at so we have # to add the directory to the path. diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 4042595..f045b0b 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -155,7 +155,7 @@ class PosixPathTest(unittest.TestCase): f.write(b"foo") f.close() self.assertIs(posixpath.islink(support.TESTFN + "1"), False) - if hasattr(os, "symlink"): + if support.can_symlink(): os.symlink(support.TESTFN + "1", support.TESTFN + "2") self.assertIs(posixpath.islink(support.TESTFN + "2"), True) os.remove(support.TESTFN + "1") diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index d9e9678..30d9e07 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -291,8 +291,7 @@ class TestShutil(unittest.TestCase): finally: shutil.rmtree(TESTFN, ignore_errors=True) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_dont_copy_file_onto_symlink_to_itself(self): # bug 851123. os.mkdir(TESTFN) @@ -312,8 +311,7 @@ class TestShutil(unittest.TestCase): finally: shutil.rmtree(TESTFN, ignore_errors=True) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_rmtree_on_symlink(self): # bug 1669. os.mkdir(TESTFN) @@ -338,8 +336,7 @@ class TestShutil(unittest.TestCase): finally: os.remove(TESTFN) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_copytree_named_pipe(self): os.mkdir(TESTFN) try: @@ -375,8 +372,7 @@ class TestShutil(unittest.TestCase): shutil.copytree(src_dir, dst_dir, copy_function=_copy) self.assertEqual(len(copied), 2) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_copytree_dangling_symlinks(self): # a dangling symlink raises an error at the end diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index d532ddf..193b5f0 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -12,7 +12,7 @@ import shutil from copy import copy, deepcopy from test.support import (run_unittest, TESTFN, unlink, get_attribute, - captured_stdout) + captured_stdout, skip_unless_symlink) import sysconfig from sysconfig import (get_paths, get_platform, get_config_vars, @@ -245,8 +245,7 @@ class TestSysConfig(unittest.TestCase): 'posix_home', 'posix_prefix', 'posix_user') self.assertEqual(get_scheme_names(), wanted) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @skip_unless_symlink def test_symlink(self): # On Windows, the EXE needs to know where pythonXY.dll is at so we have # to add the directory to the path. diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 9d84464..ff02c69 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -322,8 +322,7 @@ class MiscReadTest(CommonReadTest): @unittest.skipUnless(hasattr(os, "link"), "Missing hardlink implementation") - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") @@ -841,8 +840,7 @@ class WriteTest(WriteTestBase): os.remove(target) os.remove(link) - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") + @support.skip_unless_symlink def test_symlink_size(self): path = os.path.join(TEMPDIR, "symlink") os.symlink("link_target", path) |