def test_takeover_while_takeover_raises(): relayer = Relayer(BaseClass, [Protocol.AirPlay]) relayer.register(SubClass4("airplay"), Protocol.AirPlay) relayer.takeover(Protocol.DMAP) with pytest.raises(exceptions.InvalidStateError): relayer.takeover(Protocol.DMAP)
def test_takeover_overrides_main_instance(): relayer = Relayer(BaseClass, [Protocol.MRP, Protocol.DMAP]) relayer.register(SubClass4("mrp"), Protocol.MRP) relayer.register(SubClass4("dmap"), Protocol.DMAP) relayer.takeover(Protocol.DMAP) assert relayer.main_instance.no_args() == "dmap"
def test_takeover_with_missing_implementation(): relayer = Relayer(BaseClass, [Protocol.AirPlay, Protocol.DMAP]) relayer.register(SubClass1(), Protocol.AirPlay) relayer.register(BaseClass(), Protocol.DMAP) relayer.takeover(Protocol.DMAP) assert relayer.relay("no_args")() == "subclass1"
def test_takeover_overrides_main_protocol(): relayer = Relayer(BaseClass, [Protocol.MRP, Protocol.DMAP]) relayer.register(SubClass4("mrp"), Protocol.MRP) relayer.register(SubClass4("dmap"), Protocol.DMAP) relayer.takeover(Protocol.DMAP) assert relayer.main_protocol == Protocol.DMAP
def test_takeover_overrides_manual_priority(): relayer = Relayer(BaseClass, [Protocol.MRP, Protocol.DMAP, Protocol.AirPlay]) relayer.register(SubClass4("airplay"), Protocol.AirPlay) relayer.register(SubClass4("mrp"), Protocol.MRP) relayer.register(SubClass4("dmap"), Protocol.DMAP) relayer.takeover(Protocol.AirPlay) assert (relayer.relay( "no_args", [Protocol.DMAP, Protocol.MRP, Protocol.AirPlay])() == "airplay")
def test_takeover_and_release(): relayer = Relayer(BaseClass, [Protocol.MRP, Protocol.DMAP, Protocol.AirPlay]) relayer.register(SubClass4("airplay"), Protocol.AirPlay) relayer.register(SubClass4("mrp"), Protocol.MRP) relayer.register(SubClass4("dmap"), Protocol.DMAP) assert relayer.relay("no_args")() == "mrp" relayer.takeover(Protocol.AirPlay) assert relayer.relay("no_args")() == "airplay" relayer.release() assert relayer.relay("no_args")() == "mrp"