[pypy-svn] r31097 - pypy/dist/pypy/module/bz2/test

rhymes at codespeak.net rhymes at codespeak.net
Mon Aug 7 12:05:00 CEST 2006


Author: rhymes
Date: Mon Aug  7 12:04:57 2006
New Revision: 31097

Modified:
   pypy/dist/pypy/module/bz2/test/test_bz2.py
Log:
one more test for BZ2Compressor

Modified: pypy/dist/pypy/module/bz2/test/test_bz2.py
==============================================================================
--- pypy/dist/pypy/module/bz2/test/test_bz2.py	(original)
+++ pypy/dist/pypy/module/bz2/test/test_bz2.py	Mon Aug  7 12:04:57 2006
@@ -627,7 +627,35 @@
         data = bz2c.compress(HUGE_DATA)
         data = "%s%s" % (data, bz2c.flush())
         assert decompress(data) == HUGE_DATA
+
+    def test_compress_chunks_10(self):
+        def decompress(data):
+            import popen2
+            import bz2
+            pop = popen2.Popen3("bunzip2", capturestderr=1)
+            pop.tochild.write(data)
+            pop.tochild.close()
+            res = pop.fromchild.read()
+            pop.fromchild.close()
+            if pop.wait() != 0:
+                res = bz2.decompress(data)
+            return res
+
+        from bz2 import BZ2Compressor            
+        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'
         
+        bz2c = BZ2Compressor()
+        n = 0
+        data = ""
+        while True:
+            temp = TEXT[n * 10:(n + 1) * 10]
+            if not temp:
+                break
+            data = "%s%s" % (data, bz2c.compress(temp))
+            n += 1
+        data = "%s%s" % (data, bz2c.flush())
+        assert decompress(data) == TEXT
+
 # has_cmdline_bunzip2 = sys.platform not in ("win32", "os2emx", "riscos")
 # 
 # if has_cmdline_bunzip2:
@@ -647,21 +675,6 @@
 #     def decompress(self, data):
 #         return bz2.decompress(data)
 #
-# class BZ2CompressorTest(BaseTest):
-#     def testCompressChunks10(self):
-#         # "Test BZ2Compressor.compress()/flush() with chunks of 10 bytes"
-#         bz2c = BZ2Compressor()
-#         n = 0
-#         data = ''
-#         while 1:
-#             str = self.TEXT[n*10:(n+1)*10]
-#             if not str:
-#                 break
-#             data += bz2c.compress(str)
-#             n += 1
-#         data += bz2c.flush()
-#         self.assertEqual(self.decompress(data), self.TEXT)
-# 
 # class BZ2DecompressorTest(BaseTest):
 #     def test_Constructor(self):
 #         self.assertRaises(TypeError, BZ2Decompressor, 42)



More information about the Pypy-commit mailing list