[pypy-commit] cffi default: Write a passing test about files and buffers.
arigo
noreply at buildbot.pypy.org
Sun Jun 17 14:47:41 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r401:d862ba0c2d0d
Date: 2012-06-17 14:45 +0200
http://bitbucket.org/cffi/cffi/changeset/d862ba0c2d0d/
Log: Write a passing test about files and buffers.
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -809,6 +809,22 @@
a2 = ffi.new("int[]", range(100, 115))
assert str(ffi.buffer(a1)) == str(ffi.buffer(a2, 4*10))
+ def test_ffi_buffer_with_file(self):
+ ffi = FFI(backend=self.Backend())
+ import tempfile, os, array
+ fd, filename = tempfile.mkstemp()
+ f = os.fdopen(fd, 'r+b')
+ a = ffi.new("int[]", range(1005))
+ f.write(ffi.buffer(a, 1000 * ffi.sizeof("int")))
+ f.seek(0)
+ assert f.read() == array.array('i', range(1000)).tostring()
+ f.seek(0)
+ b = ffi.new("int[]", 1005)
+ f.readinto(ffi.buffer(b, 1000 * ffi.sizeof("int")))
+ assert list(a)[:1000] + [0] * (len(a)-1000) == list(b)
+ f.close()
+ os.unlink(filename)
+
def test_new_struct_containing_array_varsize(self):
py.test.skip("later?")
ffi = FFI(backend=self.Backend())
More information about the pypy-commit
mailing list