1010ctx = zmq .Context ()
1111class TestRecv (unittest .TestCase ):
1212 def test_sndrcv (self ):
13+ """send an array"""
1314 A = np .array ([1 ,2 ,3 ])
1415 req = ctx .socket (zmq .REQ )
1516 req .connect ('tcp://localhost:9002' )
@@ -19,5 +20,41 @@ def test_sndrcv(self):
1920 B , metadata = mmi .recv_array (rep )
2021 numpy .testing .assert_array_equal (A , B )
2122
23+ def test_metadata_only (self ):
24+ """send a message with only metadata"""
25+ req = ctx .socket (zmq .REQ )
26+ req .connect ('tcp://localhost:9002' )
27+ rep = ctx .socket (zmq .REP )
28+ rep .bind ('tcp://*:9002' )
29+ mmi .send_array (req , A = None )
30+ _ , metadata = mmi .recv_array (rep )
31+ self .assertTrue ('timestamp' in metadata )
32+
33+ def test_missing (self ):
34+ """send an array with missing data"""
35+ A = np .array ([1 , 2 , 3 , 4 ])
36+ A = np .ma .masked_less (A , 2 )
37+ req = ctx .socket (zmq .REQ )
38+ req .connect ('tcp://localhost:9002' )
39+ rep = ctx .socket (zmq .REP )
40+ rep .bind ('tcp://*:9002' )
41+ mmi .send_array (req , A )
42+ B , metadata = mmi .recv_array (rep )
43+ numpy .testing .assert_array_equal (A , B )
44+
45+ def test_missing_scalar (self ):
46+ """send an array with missing data as a scalar"""
47+ A = np .array ([1 , 2 , 3 , 4 ])
48+ A = np .ma .masked_less (A , 2 )
49+ # test if it works if we use a numpy scalar
50+ A .fill_value = np .int32 (9999 )
51+ req = ctx .socket (zmq .REQ )
52+ req .connect ('tcp://localhost:9002' )
53+ rep = ctx .socket (zmq .REP )
54+ rep .bind ('tcp://*:9002' )
55+ mmi .send_array (req , A )
56+ B , metadata = mmi .recv_array (rep )
57+ numpy .testing .assert_array_equal (A , B )
58+
2259
2360
0 commit comments