def test_parent_references(self): msg = Struct('foo', 'foo_type') child = Struct('sub', 'subelement_type') child['field'] = uint_field() msg['subbi'] = child self.assertEquals(msg, child._parent) self.assertEquals(msg, child['field']._parent._parent)
def test_in(self): msg = Struct('foo', 'foo_type') msg['a'] = uint_field() msg['b'] = uint_field() msg['c'] = uint_field() self.assertTrue('a' in msg) self.assertFalse('d' in msg)
def create_message(params): struct = Struct('foo', 'foo_type') for key in params: struct[key] = uint_field(params[key]) return struct
def _get_struct(self, name, parent): struct = Struct(name or self.name, self.type, align=self._align) struct._parent = parent return struct
def test_not_iterable(self): msg = Struct('foo', 'foo_type') msg['a'] = uint_field() self.assertRaises(TypeError, iter, msg) self.assertRaises(TypeError, iter, msg.a)
def test_decode_dynamic_with_subtractor(self): msg = Struct('foo', 'foo_type') msg['len'] = Field('uint', 'len', to_bin('0x04')) dyn_len = Length('len-2') self.assertEqual(dyn_len.decode(msg), 2)
def test_decode_dynamic(self): msg = Struct('foo', 'foo_type') msg['len'] = Field('uint', 'len', to_bin('0x04')) dyn_len = Length('len') self.assertEquals(dyn_len.decode(msg), 4)