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

rhymes at codespeak.net rhymes at codespeak.net
Sun Aug 6 01:13:50 CEST 2006


Author: rhymes
Date: Sun Aug  6 01:13:48 2006
New Revision: 31058

Modified:
   pypy/dist/pypy/module/bz2/test/test_bz2.py
Log:
one more test for BZ2File.write()

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	Sun Aug  6 01:13:48 2006
@@ -511,6 +511,37 @@
         assert decompress(f.read()) == TEXT
         f.close()
 
+    def test_write_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 BZ2File
+        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'
+
+        bz2f = BZ2File("foo", 'w')
+        n = 0
+        while True:
+            data = TEXT[n * 10:(n + 1) * 10]
+            if not data:
+                break
+            
+            bz2f.write(data)
+            n += 1
+        bz2f.close()
+        
+        f = open("foo", "rb")
+        assert decompress(f.read()) == TEXT
+        f.close()
+
 # has_cmdline_bunzip2 = sys.platform not in ("win32", "os2emx", "riscos")
 # 
 # if has_cmdline_bunzip2:
@@ -532,31 +563,6 @@
 # 
 # class BZ2FileTest(BaseTest):
 #     "Test BZ2File type miscellaneous methods."
-#     def testWrite(self):
-#         # "Test BZ2File.write()"
-#         bz2f = BZ2File(self.filename, "w")
-#         self.assertRaises(TypeError, bz2f.write)
-#         bz2f.write(self.TEXT)
-#         bz2f.close()
-#         f = open(self.filename, 'rb')
-#         self.assertEqual(self.decompress(f.read()), self.TEXT)
-#         f.close()
-# 
-#     def testWriteChunks10(self):
-#         # "Test BZ2File.write() with chunks of 10 bytes"
-#         bz2f = BZ2File(self.filename, "w")
-#         n = 0
-#         while 1:
-#             str = self.TEXT[n*10:(n+1)*10]
-#             if not str:
-#                 break
-#             bz2f.write(str)
-#             n += 1
-#         bz2f.close()
-#         f = open(self.filename, 'rb')
-#         self.assertEqual(self.decompress(f.read()), self.TEXT)
-#         f.close()
-# 
 #     def testWriteLines(self):
 #         # "Test BZ2File.writelines()"
 #         bz2f = BZ2File(self.filename, "w")



More information about the Pypy-commit mailing list