[pypy-commit] pypy numpy-data-buffer: test numpy.fromfile.
timo_jbo
noreply at buildbot.pypy.org
Mon Oct 3 17:36:04 CEST 2011
Author: Timo Paulssen <timonator at perpetuum-immobile.de>
Branch: numpy-data-buffer
Changeset: r47797:49b174c8db3a
Date: 2011-10-03 17:35 +0200
http://bitbucket.org/pypy/pypy/changeset/49b174c8db3a/
Log: test numpy.fromfile.
diff --git a/lib_pypy/pypy_test/test_numpy.py b/lib_pypy/pypy_test/test_numpy.py
--- a/lib_pypy/pypy_test/test_numpy.py
+++ b/lib_pypy/pypy_test/test_numpy.py
@@ -145,3 +145,35 @@
assert b == 1 << 24
assert c == 1 << 16
assert d == 1 << 8
+
+ def test_fromfile(self):
+ from numpy import fromfile
+ from tempfile import NamedTemporaryFile
+ from os import remove
+ import cStringIO
+ import struct
+
+ my_file = cStringIO.StringIO(struct.pack("iiiiiiii", *range(8)))
+ a = fromfile(my_file, dtype="i")
+ assert list(a) == range(8)
+ my_file.seek(0)
+ b = fromfile(my_file, dtype="i", count=3)
+ assert list(b) == range(3)
+
+ my_file = cStringIO.StringIO(struct.pack("dddddddd", *[f / 5.0 for f in range(8)]))
+ a = fromfile(my_file, dtype=float)
+ assert list(a) == [f / 5.0 for f in range(8)]
+
+ my_file = cStringIO.StringIO(" ".join(map(str, range(10))))
+ a = fromfile(my_file, dtype="i", sep=" ")
+ assert list(a) == range(10)
+ my_file.seek(0)
+ b = fromfile(my_file, dtype="i", sep=" ", count=3)
+ assert list(b) == range(3)
+
+ tmpf = NamedTemporaryFile(delete=False)
+ tmpf.file.write(struct.pack("dddddddd", *[f / 5.0 for f in range(8)]))
+ tmpf.file.close()
+ a = fromfile(tmpf.name, dtype=float)
+ assert list(a) == [f / 5.0 for f in range(8)]
+ remove(tmpf.name)
More information about the pypy-commit
mailing list