]> granicus.if.org Git - python/commitdiff
Merged manually from 2.7 branch to 3.x trunk.
authorFlorent Xicluna <florent.xicluna@gmail.com>
Mon, 9 Aug 2010 17:18:05 +0000 (17:18 +0000)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Mon, 9 Aug 2010 17:18:05 +0000 (17:18 +0000)
  ------------------------------------------------------------------------
  r81149 | florent.xicluna | 2010-05-13 23:40:01 +0200 (jeu. 13 mai 2010) | 2 lignes

  Better test skipping, with message in the log.
  ------------------------------------------------------------------------
  r81150 | florent.xicluna | 2010-05-13 23:41:05 +0200 (jeu. 13 mai 2010) | 2 lignes

  Improve test feedback to troubleshoot issue #8423 on OS X.
  ------------------------------------------------------------------------
  r81151 | florent.xicluna | 2010-05-14 01:46:48 +0200 (ven. 14 mai 2010) | 2 lignes

  Revert changeset r81150 which helped diagnose issue #8423 on some OS X buildbot.
  ------------------------------------------------------------------------
  r82056 | florent.xicluna | 2010-06-17 22:30:56 +0200 (jeu. 17 juin 2010) | 2 lignes

  Add few words about test.test_genericpath.CommonTest
  ------------------------------------------------------------------------

Lib/test/test_genericpath.py
Lib/test/test_pep277.py

index 2955f494693c1d8f3cf8f8c1e0c9dcf17fb544f9..50638a1cf0f14cf84e469145766fd7d0fe92aa64 100644 (file)
@@ -180,6 +180,9 @@ class GenericTest(unittest.TestCase):
             safe_rmdir(support.TESTFN)
 
 
+# Following TestCase is not supposed to be run from test_genericpath.
+# It is inherited by other test modules (macpath, ntpath, posixpath).
+
 class CommonTest(GenericTest):
     # The path module to be tested
     pathmodule = None
index aba1368997b73d72ecb7054c712e90d50ac73080..60d99dbbba0ba1a32db276084e09dafa26acd513 100644 (file)
@@ -40,6 +40,18 @@ if sys.platform != 'darwin':
                                 #  NFKC('\u2001') == NFKC('\u2003')
 ])
 
+
+# Is it Unicode-friendly?
+if not os.path.supports_unicode_filenames:
+    fsencoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
+    try:
+        for name in filenames:
+            name.encode(fsencoding)
+    except UnicodeEncodeError:
+        raise unittest.SkipTest("only NT+ and systems with "
+                                "Unicode-friendly filesystem encoding")
+
+
 # Destroy directory dirname and all files under it, to one level.
 def deltree(dirname):
     # Don't hide legitimate errors:  if one of these suckers exists, it's
@@ -63,14 +75,8 @@ class UnicodeFileTests(unittest.TestCase):
         files = set()
         for name in self.files:
             name = os.path.join(support.TESTFN, self.norm(name))
-            try:
-                f = open(name, 'wb')
-            except UnicodeEncodeError:
-                if not os.path.supports_unicode_filenames:
-                    self.skipTest("only NT+ and systems with Unicode-friendly"
-                                  "filesystem encoding")
-            f.write((name+'\n').encode("utf-8"))
-            f.close()
+            with open(name, 'wb') as f:
+                f.write((name+'\n').encode("utf-8"))
             os.stat(name)
             files.add(name)
         self.files = files