diff options
author | Max Sperlich <max.sperlich@livingsocial.com> | 2013-12-11 21:44:05 -0500 |
---|---|---|
committer | Max Sperlich <max.sperlich@livingsocial.com> | 2013-12-11 21:44:05 -0500 |
commit | f5f223f44394235bff517260aee16b928ea8471b (patch) | |
tree | 2dff865548873d504988132b52f28d3a7008ade7 /numpy/lib/tests/test_format.py | |
parent | e09c5f040fa020bb47c6610356214c0477c206aa (diff) | |
download | numpy-f5f223f44394235bff517260aee16b928ea8471b.tar.gz |
MAINT: Change test to read random sized chunks
Speeds the test up vs. reading single bytes at a time, and is now
correctly handled when reading the magic string and array header.
Diffstat (limited to 'numpy/lib/tests/test_format.py')
-rw-r--r-- | numpy/lib/tests/test_format.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index dbcdaaaa6..b9be643c8 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -411,16 +411,12 @@ record_arrays = [ ] -#BytesIO that reads a single byte at a time -class BytesIOSingleByte(BytesIO): +#BytesIO that reads a random number of bytes at a time +class BytesIOSRandomSize(BytesIO): def read(self, size=None): - #Return first 512 bytes normally, otherwise checking magic bytes - #and reading header fails - if self.tell() > 512: - size = 1 - else: - size = min(size, 512) - return super(BytesIOSingleByte, self).read(size) + import random + size = random.randint(1, size) + return super(BytesIOSRandomSize, self).read(size) def roundtrip(arr): @@ -431,10 +427,10 @@ def roundtrip(arr): return arr2 -def roundtrip_onebyte(arr): +def roundtrip_randsize(arr): f = BytesIO() format.write_array(f, arr) - f2 = BytesIOSingleByte(f.getvalue()) + f2 = BytesIOSRandomSize(f.getvalue()) arr2 = format.read_array(f2) return arr2 @@ -458,10 +454,10 @@ def test_roundtrip(): yield assert_array_equal, arr, arr2 -def test_roundtrip_onebyte(): +def test_roundtrip_randsize(): for arr in basic_arrays + record_arrays: if arr.dtype != object: - arr2 = roundtrip_onebyte(arr) + arr2 = roundtrip_randsize(arr) yield assert_array_equal, arr, arr2 |