[pypy-svn] r76140 - in pypy/branch/interplevel-array/pypy/module/array: . test
hakanardo at codespeak.net
hakanardo at codespeak.net
Mon Jul 12 15:14:32 CEST 2010
Author: hakanardo
Date: Mon Jul 12 15:14:31 2010
New Revision: 76140
Modified:
pypy/branch/interplevel-array/pypy/module/array/app_array.py
pypy/branch/interplevel-array/pypy/module/array/interp_array.py
pypy/branch/interplevel-array/pypy/module/array/test/test_array.py
Log:
to/fromfile
Modified: pypy/branch/interplevel-array/pypy/module/array/app_array.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/app_array.py (original)
+++ pypy/branch/interplevel-array/pypy/module/array/app_array.py Mon Jul 12 15:14:31 2010
@@ -36,12 +36,11 @@
the array. Also called as read."""
if not isinstance(f, file):
raise TypeError("arg1 must be open file")
- self._fromfile(f, n)
-
- def _fromfile(self, f, n):
size = self.itemsize * n
+ print "read"
item = f.read(size)
+ print item
if len(item) < size:
n = len(item) % self.itemsize
if n != 0: item = item[0:-(len(item) % self.itemsize)]
Modified: pypy/branch/interplevel-array/pypy/module/array/interp_array.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/interp_array.py (original)
+++ pypy/branch/interplevel-array/pypy/module/array/interp_array.py Mon Jul 12 15:14:31 2010
@@ -460,7 +460,6 @@
fromunicode = appmethod('fromunicode'),
fromfile = appmethod('fromfile'),
read = appmethod('fromfile'),
- _fromfile = appmethod('_fromfile'),
fromlist = appmethod('fromlist'),
tolist = interp2app(W_Array.descr_tolist),
Modified: pypy/branch/interplevel-array/pypy/module/array/test/test_array.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/test/test_array.py (original)
+++ pypy/branch/interplevel-array/pypy/module/array/test/test_array.py Mon Jul 12 15:14:31 2010
@@ -153,12 +153,17 @@
def test_fromfile(self):
- class myfile(object):
- def __init__(self, c, s):
- self.c = c
- self.s = s
- def read(self,n):
- return self.c*min(n,self.s)
+ ## class myfile(object):
+ ## def __init__(self, c, s):
+ ## self.c = c
+ ## self.s = s
+ ## def read(self,n):
+ ## return self.c*min(n,self.s)
+ def myfile(c, s):
+ f=open('/tmp/deleteme', 'w')
+ f.write(c*s)
+ f.close()
+ return open('/tmp/deleteme', 'r')
f=open('/dev/zero','r')
for t in 'bBhHiIlLfd':
@@ -167,16 +172,16 @@
assert len(a)==2 and a[0]==0 and a[1]==0
a = self.array('b')
- a._fromfile(myfile('\x01', 20),2)
+ a.fromfile(myfile('\x01', 20),2)
assert len(a)==2 and a[0]==1 and a[1]==1
a = self.array('h')
- a._fromfile(myfile('\x01', 20),2)
+ a.fromfile(myfile('\x01', 20),2)
assert len(a)==2 and a[0]==257 and a[1]==257
for i in (0,1):
a = self.array('h')
- raises(EOFError, a._fromfile, myfile('\x01', 2+i),2)
+ raises(EOFError, a.fromfile, myfile('\x01', 2+i),2)
assert len(a)==1 and a[0]==257
@@ -357,10 +362,11 @@
a=self.array('i', s)
assert a[0]==1 and a[1]==2 and a[2]==3
- unpack=self.unpack
+ unpack=self.struct.unpack
values = (-129, 128, -128, 127, 0, 255, -1, 256, -32760, 32760)
s = self.array('i', values).tostring()
- a=unpack('i'*len(values), s)
+ fmt = 'i'*len(values)
+ a=unpack(fmt, s)
assert a==values
for tcodes, values in (('bhilfd', (-128, 127, 0, 1, 7, -10)),
@@ -371,14 +377,16 @@
s = self.array(tc, values).tostring()
a=unpack(tc*len(values), s)
assert a==values
-
-
- #FIXME: How to test?
- #from cStringIO import StringIO
- #f=StringIO()
- #self.array('c', ('h', 'i')).tofile(f)
- #assert f.getvalue() == 'hi'
+ f=open('/tmp/deleteme', 'w')
+ self.array('c', ('h', 'i')).tofile(f)
+ f.close()
+ assert open('/tmp/deleteme', 'r').readline() == 'hi'
+
+ a=self.array('c')
+ a.fromfile(open('/tmp/deleteme', 'r'),2)
+ assert repr(a) == "array('c', 'hi')"
+
raises(ValueError, self.array('i').tounicode)
assert self.array('u', unicode('hello')).tounicode() == unicode('hello')
@@ -561,7 +569,7 @@
import array
cls.array = array.array
import struct
- cls.unpack = struct.unpack
+ cls.struct = struct
class AppTestArray(BaseArrayTests):
@@ -571,15 +579,8 @@
import array
return array.array
""")
- cls.w_unpack = cls.space.appexec([], """():
+ cls.w_struct = cls.space.appexec([], """():
import struct
- return struct.unpack
+ return struct
""")
-## class AppTestAppArray(AppTestArray):
-## def setup_class(cls):
-## cls.space = gettestobjspace(usemodules=('array',))
-## cls.w_array = cls.space.appexec([], """():
-## import apparray
-## return apparray.array
-## """)
More information about the Pypy-commit
mailing list