def test_check_semantics(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) assert m.is_valid_semantics() m[34] = 1 assert not m.is_valid_semantics()
def test_reset(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) m.reset(seqnum=1) assert m.is_valid_semantics() m.reset(seqnum=2, extra={8: b'2'}) assert m.is_valid_semantics()
def test_auto_reset(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg, auto_reset=True) assert m.is_valid_semantics() m[8] = b'lol' assert m.is_valid_semantics() del m[9] assert m.is_valid_semantics()
def test_checksum(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) assert m.is_valid_checksum() m[34] = b'0' assert not m.is_valid_checksum() m[10] = str(int(m[10].decode()) - 1).encode().zfill(3) assert m.is_valid_checksum()
def test_y_message_groupstructure(self): tlg = fix.GroupStructure({ 55: fix.GroupStructure({ x: None for x in (55, 48, 107, 167, 22, 207, 461, 202, 30025, 30024) }) }) assert tlg.is_valid_construct()
def test_modify(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) m[34] = b'2' m[350, 1, 350] = b'cc' del m[350, 0, 351] build = bytes(m) expected = self.byte_msg.replace(b'34=1', b'34=2').replace( b'350=aa', b'350=cc').replace(b'351=22\x01', b'') assert build == expected
def test_check_header_trailer(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) assert m.is_valid_header_trailer() m[34] = b'2' assert not m.is_valid_header_trailer() m[34] = b'22' assert not m.is_valid_header_trailer() m[34] = b'1' del m[350][0][350] assert not m.is_valid_header_trailer()
def test_groupstructure(self): tlg = fix.GroupStructure({350: fix.Group([350, 351])}, validate_construct=False) assert not tlg.is_valid_construct() tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) assert tlg.is_valid_construct() tlg = fix.GroupStructure({350: 2}, validate_construct=False) assert not tlg.is_valid_construct() tlg = fix.GroupStructure( {350: fix.GroupStructure({ 350: None, 351: None })}) assert tlg.is_valid_construct() tlg = fix.GroupStructure( { 350: fix.GroupStructure({ 350: b'1', 351: None }, validate_construct=False), 341: 1 }, validate_construct=False) assert not tlg.is_valid_construct()
def test_parse(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) assert m[8] == b'FIX v.lol' assert m[34] == b'1' assert m[350][0][350] == b'1' assert m[350, 0, 350] == b'1' assert m[350][0][351] == b'22' assert m[350][1][350] == b'aa' assert m[350][1][351] == b'bb' expected_checksum = str((sum(self.content_part) + sum(self.header)) % 256).zfill(3).encode() assert m.checksum == expected_checksum inner_group_id_tags = set(m.iter_inner_group_id_tags()) assert inner_group_id_tags == {350}
def test_intersecting_groups(self): g = fix.GroupStructure( { 8: None, 9: None, 34: None, 350: fix.GroupStructure({ 350: None, 351: None }), 351: fix.GroupStructure({351: None}), 10: None }, validate_construct=False) assert fix.is_intersecting_groups(g.inner_groups)
def test_copy_group(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) g = tlg.current_level_to_group() assert dict(g) == {350: None} assert g.id_tag == 350
def test_inner_groups(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) l = tlg.inner_groups assert len(l) == 1 assert l[0] is tlg[350]
def test_check_valid_construct2(self): g = fix.GroupStructure({}) g.is_valid_construct()
def test_check_valid_construct(self): g = fix.GroupStructure({8: b'8'}, req_tags={9}) assert not g.is_valid_construct()
def test_empty_group2(self): fix.GroupStructure({}, validate_construct=True)
def test_copy_group_only(self): g = fix.GroupStructure({8: None}) g2 = g.current_level_to_group() assert g2[8] is None assert g2 is not g assert_raises(KeyError, g2.__getitem__, 9)
def test_build(self): tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) m = fix.Message.parse(self.byte_msg, tlg) build = bytes(m) assert build == self.byte_msg