summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-12-02 18:29:18 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-12-02 18:29:18 (GMT)
commit52173d4959a1c1e961efab2522e4ba8a22a3c7c6 (patch)
treea89463de7c0db84aa60ef25bc05caf8837e2cc33 /Lib/test/test_os.py
parent02524629f39bb70f4ea00ab8e64d694e08719227 (diff)
downloadcpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.zip
cpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.tar.gz
cpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.tar.bz2
Fix #9333. Expose os.symlink on Windows only when usable.
In order to create symlinks on Windows, SeCreateSymbolicLinkPrivilege is an account privilege that is required to be held by the user. Not only must the privilege be enabled for the account, the activated privileges for the currently running application must be adjusted to enable the requested privilege. Rather than exposing an additional function to be called prior to the user's first os.symlink call, we handle the AdjustTokenPrivileges Windows API call internally and only expose os.symlink when the privilege escalation was successful. Due to the change of only exposing os.symlink when it's available, we can go back to the original test skipping methods of checking via `hasattr`.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index e27dd7a..fc6084b 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 support.can_symlink():
+ if hasattr(os, "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 support.can_symlink():
+ if hasattr(os, "symlink"):
# Walk, following symlinks.
for root, dirs, files in os.walk(walk_path, followlinks=True):
if root == link_path:
@@ -1146,14 +1146,8 @@ class Win32KillTests(unittest.TestCase):
self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
-def skipUnlessWindows6(test):
- if (hasattr(sys, 'getwindowsversion')
- and sys.getwindowsversion().major >= 6):
- return test
- return unittest.skip("Requires Windows Vista or later")(test)
-
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
-@support.skip_unless_symlink
+@unittest.skipUnless(hasattr(os, "symlink"), "Requires symlink implementation")
class Win32SymlinkTests(unittest.TestCase):
filelink = 'filelinktest'
filelink_target = os.path.abspath(__file__)