def test_add_protocol(patch_protocols, valid_params): proto = protocols.Protocol(**valid_params) protocols.add_protocol(proto) assert protocols.PROTOCOLS == [proto] assert proto.name in protocols._names_to_protocols assert proto.code in protocols._codes_to_protocols proto = protocols.Protocol(protocols.P_TCP, "tcp", "uint16be")
def test_add_protocol(patch_protocols): proto = protocols.Protocol(**valid_params()) protocols.add_protocol(proto) assert protocols.PROTOCOLS == [proto] assert proto.name in protocols._names_to_protocols assert proto.code in protocols._codes_to_protocols proto = protocols.Protocol( protocols.P_TCP, 16, "tcp", protocols.code_to_varint(protocols.P_TCP))
def test_add_protocol_twice(patch_protocols): proto = protocols.Protocol(**valid_params()) protocols.add_protocol(proto) with pytest.raises(ValueError): protocols.add_protocol(proto) del protocols._names_to_protocols[proto.name] with pytest.raises(ValueError): protocols.add_protocol(proto) del protocols._codes_to_protocols[proto.code] protocols.add_protocol(proto) assert protocols.PROTOCOLS == [proto, proto]
def test_add_protocol_twice(patch_protocols, valid_params): proto = protocols.Protocol(**valid_params) protocols.add_protocol(proto) with pytest.raises(exceptions.ProtocolExistsError): protocols.add_protocol(proto) del protocols._names_to_protocols[proto.name] with pytest.raises(exceptions.ProtocolExistsError): protocols.add_protocol(proto) del protocols._codes_to_protocols[proto.code] protocols.add_protocol(proto) assert protocols.PROTOCOLS == [proto, proto]