Source

pypy / pypy / module / bz2 / test / test_bz2_compdecomp.py

Diff from to

File pypy/module/bz2/test/test_bz2_compdecomp.py

 from pypy.interpreter.gateway import interp2app
 from pypy.module.bz2.test.support import CheckAllocation
 from pypy.module.bz2 import interp_bz2
-
+from pypy.interpreter.gateway import interp2app
+import os, py
 
 HUGE_OK = False
 
     def decompress(space, w_data):
         import popen2
         import bz2
-        data = space.str_w(w_data)
+        data = space.bytes_w(w_data)
         pop = popen2.Popen3("bunzip2", capturestderr=1)
         pop.tochild.write(data)
         pop.tochild.close()
         pop.fromchild.close()
         if pop.wait() != 0:
             res = bz2.decompress(data)
-        return space.wrap(res)
+        return space.wrapbytes(res)
 
     mod.TEXT = 'root:x:0:0:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:\ndaemon:x:2:2:daemon:/sbin:\nadm:x:3:4:adm:/var/adm:\nlp:x:4:7:lp:/var/spool/lpd:\nsync:x:5:0:sync:/sbin:/bin/sync\nshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\nhalt:x:7:0:halt:/sbin:/sbin/halt\nmail:x:8:12:mail:/var/spool/mail:\nnews:x:9:13:news:/var/spool/news:\nuucp:x:10:14:uucp:/var/spool/uucp:\noperator:x:11:0:operator:/root:\ngames:x:12:100:games:/usr/games:\ngopher:x:13:30:gopher:/usr/lib/gopher-data:\nftp:x:14:50:FTP User:/var/ftp:/bin/bash\nnobody:x:65534:65534:Nobody:/home:\npostfix:x:100:101:postfix:/var/spool/postfix:\nniemeyer:x:500:500::/home/niemeyer:/bin/bash\npostgres:x:101:102:PostgreSQL Server:/var/lib/pgsql:/bin/bash\nmysql:x:102:103:MySQL server:/var/lib/mysql:/bin/bash\nwww:x:103:104::/var/www:/bin/false\n'
     mod.DATA = DATA
     spaceconfig = dict(usemodules=('bz2',))
 
     def setup_class(cls):
-        cls.w_TEXT = cls.space.wrap(TEXT)
+        cls.w_TEXT = cls.space.wrapbytes(TEXT)
         if cls.runappdirect:
             cls.w_decompress = lambda self, *args: decompress(cls.space, *args)
         else:
         bz2c = BZ2Compressor()
         raises(TypeError, bz2c.compress)
         data = bz2c.compress(self.TEXT)
-        data = "%s%s" % (data, bz2c.flush())
+        data += bz2c.flush()
         assert self.decompress(data) == self.TEXT
         
     def test_compress_huge_data(self):
         bz2c = BZ2Compressor()
         raises(TypeError, bz2c.compress)
         data = bz2c.compress(HUGE_DATA)
-        data = "%s%s" % (data, bz2c.flush())
+        data += bz2c.flush()
         assert self.decompress(data) == HUGE_DATA
 
     def test_compress_chunks_10(self):
         
         bz2c = BZ2Compressor()
         n = 0
-        data = ""
+        data = b""
         while True:
             temp = self.TEXT[n * 10:(n + 1) * 10]
             if not temp:
                 break
-            data = "%s%s" % (data, bz2c.compress(temp))
+            data += bz2c.compress(temp)
             n += 1
-        data = "%s%s" % (data, bz2c.flush())
+        data += bz2c.flush()
         assert self.decompress(data) == self.TEXT
 
     def test_buffer(self):
         from bz2 import BZ2Compressor
         bz2c = BZ2Compressor()
-        data = bz2c.compress(buffer(self.TEXT))
-        data = "%s%s" % (data, bz2c.flush())
+        data = bz2c.compress(memoryview(self.TEXT))
+        data += bz2c.flush()
         assert self.decompress(data) == self.TEXT
 
 
     spaceconfig = dict(usemodules=('bz2',))
 
     def setup_class(cls):
-        cls.w_TEXT = cls.space.wrap(TEXT)
-        cls.w_DATA = cls.space.wrap(DATA)
-        cls.w_BUGGY_DATA = cls.space.wrap(BUGGY_DATA)
+        cls.w_TEXT = cls.space.wrapbytes(TEXT)
+        cls.w_DATA = cls.space.wrapbytes(DATA)
+        cls.w_BUGGY_DATA = cls.space.wrapbytes(BUGGY_DATA)
         
     def test_creation(self):
         from bz2 import BZ2Decompressor
         from bz2 import BZ2Decompressor
         
         bz2d = BZ2Decompressor()
-        assert bz2d.unused_data == ""
+        assert bz2d.unused_data == b""
 
     def test_decompress(self):
         from bz2 import BZ2Decompressor
         from bz2 import BZ2Decompressor
         
         bz2d = BZ2Decompressor()
-        decompressed_data = ""
+        decompressed_data = b""
         n = 0
         while True:
             temp = self.DATA[n * 10:(n + 1) * 10]
             if not temp:
                 break
-            decompressed_data = "%s%s" % (decompressed_data, bz2d.decompress(temp))
+            decompressed_data += bz2d.decompress(temp)
             n += 1
         
         assert decompressed_data == self.TEXT
         from bz2 import BZ2Decompressor
         
         bz2d = BZ2Decompressor()
-        unused_data = "this is unused data"
+        unused_data = b"this is unused data"
         decompressed_data = bz2d.decompress(self.DATA + unused_data)
         assert decompressed_data == self.TEXT
         assert bz2d.unused_data == unused_data
         
         bz2d = BZ2Decompressor()
         bz2d.decompress(self.DATA)
-        raises(EOFError, bz2d.decompress, "foo")
-        raises(EOFError, bz2d.decompress, "")
+        raises(EOFError, bz2d.decompress, b"foo")
+        raises(EOFError, bz2d.decompress, b"")
 
     def test_buffer(self):
         from bz2 import BZ2Decompressor
         bz2d = BZ2Decompressor()
-        decompressed_data = bz2d.decompress(buffer(self.DATA))
+        decompressed_data = bz2d.decompress(memoryview(self.DATA))
         assert decompressed_data == self.TEXT
 
     def test_subsequent_read(self):
         from bz2 import BZ2Decompressor
         bz2d = BZ2Decompressor()
         decompressed_data = bz2d.decompress(self.BUGGY_DATA)
-        assert decompressed_data == ''
+        assert decompressed_data == b''
         raises(IOError, bz2d.decompress, self.BUGGY_DATA)
 
 
     spaceconfig = dict(usemodules=('bz2',))
 
     def setup_class(cls):
-        cls.w_TEXT = cls.space.wrap(TEXT)
-        cls.w_DATA = cls.space.wrap(DATA)
+        cls.w_TEXT = cls.space.wrapbytes(TEXT)
+        cls.w_DATA = cls.space.wrapbytes(DATA)
         if cls.runappdirect:
             cls.w_decompress = lambda self, *args: decompress(cls.space, *args)
         else:
         from bz2 import compress
     
         raises(TypeError, compress, 123)
-        raises(ValueError, compress, "foo", 10)
-        raises(TypeError, compress, "foo", "foo")
+        raises(ValueError, compress, b"foo", 10)
+        raises(TypeError, compress, b"foo", b"foo")
     
         data = compress(self.TEXT)
         assert self.decompress(data) == self.TEXT
         import bz2
     
         raises(TypeError, bz2.decompress)
-        assert bz2.decompress("") == ""
+        assert bz2.decompress(b"") == b""
         decompressed_data = bz2.decompress(self.DATA)
         assert decompressed_data == self.TEXT
 
 
     def test_buffer(self):
         import bz2
-        data = bz2.compress(buffer(self.TEXT))
-        result = bz2.decompress(buffer(data))
+        data = bz2.compress(memoryview(self.TEXT))
+        result = bz2.decompress(memoryview(data))
         assert result == self.TEXT