[pypy-svn] r61270 - in pypy/trunk/pypy/module/bz2: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jan 23 17:04:01 CET 2009
Author: fijal
Date: Fri Jan 23 17:04:00 2009
New Revision: 61270
Modified:
pypy/trunk/pypy/module/bz2/interp_bz2.py
pypy/trunk/pypy/module/bz2/test/test_bz2_file.py
Log:
a test and a fix
Modified: pypy/trunk/pypy/module/bz2/interp_bz2.py
==============================================================================
--- pypy/trunk/pypy/module/bz2/interp_bz2.py (original)
+++ pypy/trunk/pypy/module/bz2/interp_bz2.py Fri Jan 23 17:04:00 2009
@@ -547,17 +547,18 @@
self.bzs.c_next_out = out_buf
rffi.setintfield(self.bzs, 'c_avail_out', out_bufsize)
- if temp:
- return self.space.wrap("".join(temp))
-
+
if rffi.getintfield(self.bzs, 'c_avail_out'):
size = _bzs_total_out(self.bzs) - total_out
res = "".join([out_buf[i] for i in range(size)])
+ else:
+ total_out = _bzs_total_out(self.bzs)
+ res = "".join([out_buf[i] for i in range(total_out)])
+ if not temp:
return self.space.wrap(res)
-
- total_out = _bzs_total_out(self.bzs)
- res = "".join([out_buf[i] for i in range(total_out)])
- return self.space.wrap(res)
+ else:
+ temp.append(res)
+ return self.space.wrap("".join(temp))
finally:
lltype.free(out_buf, flavor='raw')
flush.unwrap_spec = ['self']
Modified: pypy/trunk/pypy/module/bz2/test/test_bz2_file.py
==============================================================================
--- pypy/trunk/pypy/module/bz2/test/test_bz2_file.py (original)
+++ pypy/trunk/pypy/module/bz2/test/test_bz2_file.py Fri Jan 23 17:04:00 2009
@@ -2,6 +2,7 @@
from pypy.conftest import gettestobjspace
from pypy.module.bz2.test.support import CheckAllocation
import os
+import random
if os.name == "nt":
from py.test import skip
@@ -39,6 +40,8 @@
mod.create_temp_file = create_temp_file
mod.decompress = decompress
mod.create_broken_temp_file = create_broken_temp_file
+ s = 'abcdefghijklmnop'
+ mod.RANDOM_DATA = ''.join([s[int(random.random() * len(s))] for i in range(30000)])
class AppTestBZ2File: #(CheckAllocation):
# XXX for unknown reasons, we cannot do allocation checks, as sth is
@@ -53,6 +56,7 @@
cls.w_create_temp_file = space.wrap(create_temp_file)
cls.w_decompress = space.wrap(decompress)
cls.w_create_broken_temp_file = space.wrap(create_broken_temp_file)
+ cls.w_random_data = space.wrap(RANDOM_DATA)
def test_attributes(self):
from bz2 import BZ2File
@@ -401,6 +405,16 @@
raises(IOError, bz2f.write, "abc")
raises(IOError, bz2f.writelines, ["abc"])
bz2f.close()
+
+ def test_write_bigger_file(self):
+ from bz2 import BZ2File
+ import random
+ bz2f = BZ2File(self.temppath, 'w')
+ bz2f.write(self.random_data)
+ bz2f.close()
+ bz2f = BZ2File(self.temppath, 'r')
+ assert bz2f.read() == self.random_data
+
# has_cmdline_bunzip2 = sys.platform not in ("win32", "os2emx", "riscos")
#
More information about the Pypy-commit
mailing list