Amaury Forgeot d'Arc avatar Amaury Forgeot d'Arc committed a509478

Make most zipimport tests pass with -A

Comments (0)

Files changed (3)


             importer = zipimport.zipimporter(os.path.join(zip_path, '_pkg'))
             assert zip_path in zipimport._zip_directory_cache
-            file_set = set(zipimport._zip_directory_cache[zip_path].iterkeys())
+            file_set = set(zipimport._zip_directory_cache[zip_path].keys())
             compare_set = set(path.replace(os.path.sep, '/') + '.py'
                               for path in self.created_paths)
             assert file_set == compare_set


         elif isinstance(value, types.ModuleType):
             name = value.__name__
             defs.append("import %s; self.%s = %s\n" % (name, symbol, name))
-        elif isinstance(value, (int, str)):
+        elif isinstance(value, str):
+            # python2 string -> Bytes string
+            defs.append("self.%s = b%r\n" % (symbol, value))
+        elif isinstance(value, unicode):
+            # python2 unicode -> python3 string
+            defs.append("self.%s = %s\n" % (symbol, repr(value)[1:]))
+        elif isinstance(value, (int, float, list)):
             defs.append("self.%s = %r\n" % (symbol, value))
-    source = py.code.Source(target_)[1:].deindent()
+    source = py.code.Source(target_)[1:]
     pyfile = udir.join('')
-    source = helpers + '\n'.join(defs) + str(source)
+    source = helpers + '\n'.join(defs) + 'if 1:\n' + str(source)
     with'w') as f:
     res, stdout, stderr = runsubprocess.run_subprocess(


         return (src, args)
     def wrap(self, obj):
+        if isinstance(obj, str):
+            return obj.decode('utf-8')
+        return obj
+    def wrapbytes(self, obj):
         return obj
     def unpackiterable(self, itr):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.