summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.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/support.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/support.py')
-rw-r--r--Lib/test/support.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 08105df..83d7ba8 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -17,6 +17,7 @@ import unittest
import importlib
import collections
import re
+import subprocess
import imp
import time
try:
@@ -38,8 +39,7 @@ __all__ = [
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
"reap_children", "cpython_only", "check_impl_detail", "get_attribute",
- "swap_item", "swap_attr",
- ]
+ "swap_item", "swap_attr", "can_symlink", "skip_unless_symlink"]
class Error(Exception):
@@ -1169,6 +1169,27 @@ def reap_children():
except:
break
+try:
+ from .symlink_support import enable_symlink_privilege
+except:
+ enable_symlink_privilege = lambda: True
+
+def can_symlink():
+ """It's no longer sufficient to test for the presence of symlink in the
+ os module - on Windows XP and earlier, os.symlink exists but a
+ NotImplementedError is thrown.
+ """
+ has_symlink = hasattr(os, 'symlink')
+ is_old_windows = sys.platform == "win32" and sys.getwindowsversion().major < 6
+ has_privilege = False if is_old_windows else enable_symlink_privilege()
+ return has_symlink and (not is_old_windows) and has_privilege
+
+def skip_unless_symlink(test):
+ """Skip decorator for tests that require functional symlink"""
+ selector = can_symlink()
+ msg = "Requires functional symlink implementation"
+ return [unittest.skip(msg)(test), test][selector]
+
@contextlib.contextmanager
def swap_attr(obj, attr, new_val):
"""Temporary swap out an attribute with a new object.