示例#1
0
    def test_callback_not_running_must_raise(self):
        def foo(p): pass
        s = SimulatorHandler()

        with pytest.raises(RuntimeError) as excinfo:
            s.set_callback(10, foo)

        assert "running" in str(excinfo.value)
示例#2
0
    def test_callback_must_setup_call_request(self, mocker):
        def foo(p): pass
        mocker.patch("batsim_py.simulator.CallMeLaterBatsimRequest")

        s = SimulatorHandler()
        s.start("p", "w")
        s.set_callback(50, foo)
        simulator.CallMeLaterBatsimRequest.assert_called_once_with(  # type: ignore
            0, 50+0.09)
示例#3
0
    def test_callback_invalid_time_must_raise(self, mocker):
        def foo(p): pass
        s = SimulatorHandler()

        s.start("p", "w")
        msg = BatsimMessage(50, [RequestedCallBatsimEvent(50)])
        mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg)
        s.proceed_time(50)

        with pytest.raises(ValueError) as excinfo:
            s.set_callback(50, foo)

        assert "at" in str(excinfo.value)