[Python-checkins] cpython: #14885: Make support.skip_unless_xattr check also tempfile

hynek.schlawack python-checkins at python.org
Wed May 23 11:55:30 CEST 2012


http://hg.python.org/cpython/rev/ab94ed2a8012
changeset:   77113:ab94ed2a8012
user:        Hynek Schlawack <hs at ox.cx>
date:        Wed May 23 11:22:44 2012 +0200
summary:
  #14885: Make support.skip_unless_xattr check also tempfile

There is a rare edge case where the filesystem used by the tempfile functions
(usually /tmp) doesn't support xattrs while the one used by TESTFN (the current
directory, so likely to be below /home) does. This causes the xattr related
test_shutil tests fail. skip_unless_xattr now checks both.

I have also added skip_unless_xattr to __all__ where it has been missing.

files:
  Lib/test/support.py |  28 ++++++++++++++++++----------
  1 files changed, 18 insertions(+), 10 deletions(-)


diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -24,6 +24,7 @@
 import fnmatch
 import logging.handlers
 import struct
+import tempfile
 
 try:
     import _thread, threading
@@ -51,23 +52,25 @@
     lzma = None
 
 __all__ = [
-    "Error", "TestFailed", "ResourceDenied", "import_module",
-    "verbose", "use_resources", "max_memuse", "record_original_stdout",
+    "Error", "TestFailed", "ResourceDenied", "import_module", "verbose",
+    "use_resources", "max_memuse", "record_original_stdout",
     "get_original_stdout", "unload", "unlink", "rmtree", "forget",
     "is_resource_enabled", "requires", "requires_freebsd_version",
-    "requires_linux_version", "requires_mac_ver", "find_unused_port", "bind_port",
-    "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd",
-    "findfile", "create_empty_file", "sortdict", "check_syntax_error", "open_urlresource",
-    "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource",
-    "captured_stdout", "captured_stdin", "captured_stderr", "time_out",
-    "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask',
+    "requires_linux_version", "requires_mac_ver", "find_unused_port",
+    "bind_port", "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD",
+    "temp_cwd", "findfile", "create_empty_file", "sortdict",
+    "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport",
+    "EnvironmentVarGuard", "TransientResource", "captured_stdout",
+    "captured_stdin", "captured_stderr", "time_out", "socket_peer_reset",
+    "ioerror_peer_reset", "run_with_locale", 'temp_umask',
     "transient_internet", "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", "requires_IEEE_754",
     "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
-    "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast",
-    "anticipate_failure", "run_with_tz", "requires_bz2", "requires_lzma"
+    "skip_unless_xattr", "import_fresh_module", "requires_zlib",
+    "PIPE_MAX_SIZE", "failfast", "anticipate_failure", "run_with_tz",
+    "requires_bz2", "requires_lzma"
     ]
 
 class Error(Exception):
@@ -1694,9 +1697,13 @@
     if not hasattr(os, "setxattr"):
         can = False
     else:
+        tmp_fp, tmp_name = tempfile.mkstemp()
         try:
             with open(TESTFN, "wb") as fp:
                 try:
+                    # TESTFN & tempfile may use different file systems with
+                    # different capabilities
+                    os.fsetxattr(tmp_fp, b"user.test", b"")
                     os.fsetxattr(fp.fileno(), b"user.test", b"")
                     # Kernels < 2.6.39 don't respect setxattr flags.
                     kernel_version = platform.release()
@@ -1706,6 +1713,7 @@
                     can = False
         finally:
             unlink(TESTFN)
+            unlink(tmp_name)
     _can_xattr = can
     return can
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list