summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-05-12 17:02:01 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-05-12 17:02:01 (GMT)
commit424246fbf3953ccdb3b34961db007a453873a3ea (patch)
tree64fc5c2f67d12ae1ca24201d0569748f7df9352b /Lib/test/support.py
parent4d688e3275d5a10e2321571392cdc31945bb8a89 (diff)
downloadcpython-424246fbf3953ccdb3b34961db007a453873a3ea.zip
cpython-424246fbf3953ccdb3b34961db007a453873a3ea.tar.gz
cpython-424246fbf3953ccdb3b34961db007a453873a3ea.tar.bz2
Issue #14082: shutil.copy2() now copies extended attributes, if possible.
Patch by Hynek Schlawack.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 48e8332..c92fa00 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -1696,6 +1696,35 @@ def skip_unless_symlink(test):
msg = "Requires functional symlink implementation"
return test if ok else unittest.skip(msg)(test)
+_can_xattr = None
+def can_xattr():
+ global _can_xattr
+ if _can_xattr is not None:
+ return _can_xattr
+ if not hasattr(os, "setxattr"):
+ can = False
+ else:
+ try:
+ with open(TESTFN, "wb") as fp:
+ try:
+ os.fsetxattr(fp.fileno(), b"user.test", b"")
+ # Kernels < 2.6.39 don't respect setxattr flags.
+ kernel_version = platform.release()
+ m = re.match("2.6.(\d{1,2})", kernel_version)
+ can = m is None or int(m.group(1)) >= 39
+ except OSError:
+ can = False
+ finally:
+ unlink(TESTFN)
+ _can_xattr = can
+ return can
+
+def skip_unless_xattr(test):
+ """Skip decorator for tests that require functional extended attributes"""
+ ok = can_xattr()
+ msg = "no non-broken extended attribute support"
+ return test if ok else unittest.skip(msg)(test)
+
def patch(test_instance, object_to_patch, attr_name, new_value):
"""Override 'object_to_patch'.'attr_name' with 'new_value'.