Skip to content

Commit d1e8ea3

Browse files
committed
Add unit test to ensure that fix for #35 works.
1 parent b25489b commit d1e8ea3

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

CHANGES.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
Change Log
44
==========
55

6-
Release 0.4.4.3 (In Development)
6+
Release 0.4.4.3 (May 16, 2019)
77
------------------------------
88
* Configure contiguous integration with Travis.
9+
* Move unit tests out of msgpack_numpy module.
910
* Add workaround for issue handling n-dim arrays on MacOS (#35).
1011

1112
Release 0.4.4.2 (November 8, 2018)

tests.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class test_numpy_msgpack(TestCase):
2626
def setUp(self):
2727
patch()
2828

29-
def encode_decode(self, x, use_bin_type=False, raw=True):
29+
def encode_decode(self, x, use_bin_type=False, raw=True,
30+
use_list=True, max_bin_len=-1):
3031
x_enc = msgpack.packb(x, use_bin_type=use_bin_type)
31-
return msgpack.unpackb(x_enc, raw=raw)
32+
return msgpack.unpackb(x_enc, raw=raw, use_list=use_list,
33+
max_bin_len=max_bin_len)
3234

3335
def encode_thirdparty(self, obj):
3436
return dict(__thirdparty__=True, foo=obj.foo)
@@ -38,10 +40,13 @@ def decode_thirdparty(self, obj):
3840
return ThirdParty(foo=obj[b'foo'])
3941
return obj
4042

41-
def encode_decode_thirdparty(self, x, use_bin_type=False, raw=True):
43+
def encode_decode_thirdparty(self, x, use_bin_type=False, raw=True,
44+
use_list=True, max_bin_len=-1):
4245
x_enc = msgpack.packb(x, default=self.encode_thirdparty,
4346
use_bin_type=use_bin_type)
44-
return msgpack.unpackb(x_enc, raw=raw, object_hook=self.decode_thirdparty)
47+
return msgpack.unpackb(x_enc, raw=raw,
48+
object_hook=self.decode_thirdparty,
49+
use_list=use_list, max_bin_len=max_bin_len)
4550

4651
def test_bin(self):
4752
# Since bytes == str in Python 2.7, the following
@@ -195,6 +200,16 @@ def test_numpy_array_float_2d(self):
195200
assert_array_equal(x, x_rec)
196201
assert_equal(x.dtype, x_rec.dtype)
197202

203+
def test_numpy_array_float_2d_macos(self):
204+
"""
205+
Unit test for weird data loss error on MacOS (#35).
206+
"""
207+
x = np.random.rand(5,5).astype(np.float32)
208+
x_rec = self.encode_decode(x, use_bin_type=True, raw=False,
209+
use_list=False, max_bin_len=50000000)
210+
assert_array_equal(x, x_rec)
211+
assert_equal(x.dtype, x_rec.dtype)
212+
198213
def test_numpy_array_str(self):
199214
x = np.array([b'aaa', b'bbbb', b'ccccc'])
200215
x_rec = self.encode_decode(x)

0 commit comments

Comments
 (0)