[pypy-commit] pypy py3k: skip some zipimport tests when testfn_unencodable/special_char aren't

pjenvey pypy.commits at gmail.com
Wed May 18 20:59:27 EDT 2016


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r84515:ad588df8d94f
Date: 2016-05-18 17:57 -0700
http://bitbucket.org/pypy/pypy/changeset/ad588df8d94f/

Log:	skip some zipimport tests when testfn_unencodable/special_char
	aren't available and make special_char available to test_zipimport

diff --git a/pypy/module/imp/test/support.py b/pypy/module/imp/test/support.py
--- a/pypy/module/imp/test/support.py
+++ b/pypy/module/imp/test/support.py
@@ -4,14 +4,57 @@
 
     def setup_class(cls):
         space = cls.space
-        testfn = u'test_tmp'
-        testfn_unencodable = None
+        cls.w_testfn_unencodable = space.wrap(get_unencodable())
+        cls.w_special_char = space.wrap(get_special_char())
 
-        if sys.platform == 'win32':
-            testfn_unencodable = testfn + u"-\u5171\u0141\u2661\u0363\uDC80"
-        elif sys.platform != 'darwin':
-            try:
-                '\xff'.decode(sys.getfilesystemencoding())
-            except UnicodeDecodeError:
-                testfn_unencodable = testfn + u'-\udcff'
-        cls.w_testfn_unencodable = space.wrap(testfn_unencodable)
+def get_unencodable():
+    """Copy of the stdlib's support.TESTFN_UNENCODABLE:
+
+    A filename (py3k str type) that should *not* be able to be encoded
+    by the filesystem encoding (in strict mode). It can be None if we
+    cannot generate such filename.
+    """
+    testfn_unencodable = None
+    testfn = u'test_tmp'
+
+    if sys.platform == 'win32':
+        testfn_unencodable = testfn + u"-\u5171\u0141\u2661\u0363\uDC80"
+    elif sys.platform != 'darwin':
+        try:
+            '\xff'.decode(sys.getfilesystemencoding())
+        except UnicodeDecodeError:
+            testfn_unencodable = testfn + u'-\udcff'
+    return testfn_unencodable
+
+def get_special_char():
+    """Copy of the stdlib's test_imp.test_issue5604 special_char:
+
+    A non-ascii filename (py3k str type) that *should* be able to be
+    encoded by the filesystem encoding (in strict mode). It can be None
+    if we cannot generate such filename.
+    """
+    fsenc = sys.getfilesystemencoding()
+    # covers utf-8 and Windows ANSI code pages one non-space symbol from
+    # every page (http://en.wikipedia.org/wiki/Code_page)
+    known_locales = {
+        'utf-8' : b'\xc3\xa4',
+        'cp1250' : b'\x8C',
+        'cp1251' : b'\xc0',
+        'cp1252' : b'\xc0',
+        'cp1253' : b'\xc1',
+        'cp1254' : b'\xc0',
+        'cp1255' : b'\xe0',
+        'cp1256' : b'\xe0',
+        'cp1257' : b'\xc0',
+        'cp1258' : b'\xc0',
+        }
+
+    if sys.platform == 'darwin':
+        # Mac OS X uses the Normal Form D decomposition
+        # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
+        special_char = b'a\xcc\x88'
+    else:
+        special_char = known_locales.get(fsenc)
+
+    if special_char:
+        return special_char.decode(fsenc)
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -132,34 +132,11 @@
              line2 = "# encoding: iso-8859-1\n",
              bad = "# encoding: uft-8\n")
 
-    fsenc = sys.getfilesystemencoding()
-    # covers utf-8 and Windows ANSI code pages one non-space symbol from
-    # every page (http://en.wikipedia.org/wiki/Code_page)
-    known_locales = {
-        'utf-8' : b'\xc3\xa4',
-        'cp1250' : b'\x8C',
-        'cp1251' : b'\xc0',
-        'cp1252' : b'\xc0',
-        'cp1253' : b'\xc1',
-        'cp1254' : b'\xc0',
-        'cp1255' : b'\xe0',
-        'cp1256' : b'\xe0',
-        'cp1257' : b'\xc0',
-        'cp1258' : b'\xc0',
-        }
-
-    if sys.platform == 'darwin':
-        # Mac OS X uses the Normal Form D decomposition
-        # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
-        special_char = b'a\xcc\x88'
-    else:
-        special_char = known_locales.get(fsenc)
-
-    if special_char:
+    w_special_char = getattr(cls, 'w_special_char', None)
+    if not space.is_none(w_special_char):
+        special_char = space.unicode_w(w_special_char).encode(
+            sys.getfilesystemencoding())
         p.join(special_char + '.py').write('pass')
-        cls.w_special_char = space.wrap(special_char.decode(fsenc))
-    else:
-        cls.w_special_char = space.w_None
 
     # create a .pyw file
     p = setuppkg("windows", x = "x = 78")
@@ -781,9 +758,9 @@
         raises(SyntaxError, imp.find_module, 'bad', encoded.__path__)
 
     def test_find_module_fsdecode(self):
-        import sys
         name = self.special_char
         if not name:
+            import sys
             skip("can't run this test with %s as filesystem encoding"
                  % sys.getfilesystemencoding())
         import imp
diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -349,14 +349,23 @@
         assert sys.path_hooks.count(zipimport.zipimporter) == 1
 
     def w__make_unicode_filename(self):
+        if not self.testfn_unencodable:
+            import sys
+            skip("can't run this test with %s as filesystem encoding"
+                 % sys.getfilesystemencoding())
         import os
         head, tail = os.path.split(self.zipfile)
-        self.zipfile = head + os.path.sep + tail[:4] + '_ä' + tail[4:]
+        self.zipfile = (head + os.path.sep + tail[:4] +
+                        self.testfn_unencodable + tail[4:])
 
     def test_unicode_filename_notfound(self):
+        if not self.special_char:
+            import sys
+            skip("can't run this test with %s as filesystem encoding"
+                 % sys.getfilesystemencoding())
         import zipimport
         raises(zipimport.ZipImportError,
-               zipimport.zipimporter, 'caf\xe9')
+               zipimport.zipimporter, self.special_char)
 
     def test_unicode_filename_invalid_zippath(self):
         import zipimport


More information about the pypy-commit mailing list