Test that dynamic array types enforce matching lengths
()
| 202 | |
| 203 | |
| 204 | def test_dynamic_array(): |
| 205 | """Test that dynamic array types enforce matching lengths""" |
| 206 | ns = MessageNamespace(['msgtype,test1,1', |
| 207 | 'msgdata,test1,count,u16,', |
| 208 | 'msgdata,test1,arr1,byte,count', |
| 209 | 'msgdata,test1,arr2,u32,count']) |
| 210 | |
| 211 | # This one is fine. |
| 212 | m = Message(ns.get_msgtype('test1'), |
| 213 | arr1='01020304', arr2='[1,2,3,4]') |
| 214 | buf = io.BytesIO() |
| 215 | m.write(buf) |
| 216 | assert buf.getvalue() == bytes([0, 1] |
| 217 | + [0, 4] |
| 218 | + [1, 2, 3, 4] |
| 219 | + [0, 0, 0, 1, |
| 220 | 0, 0, 0, 2, |
| 221 | 0, 0, 0, 3, |
| 222 | 0, 0, 0, 4]) |
| 223 | |
| 224 | # These ones are not |
| 225 | with pytest.raises(ValueError, match='Inconsistent length.*count'): |
| 226 | m = Message(ns.get_msgtype('test1'), |
| 227 | arr1='01020304', arr2='[1,2,3]') |
| 228 | |
| 229 | with pytest.raises(ValueError, match='Inconsistent length.*count'): |
| 230 | m = Message(ns.get_msgtype('test1'), |
| 231 | arr1='01020304', arr2='[1,2,3,4,5]') |
nothing calls this directly
no test coverage detected