def test_reject_job_not_running_must_raise(self, mocker): s = SimulatorHandler() with pytest.raises(RuntimeError) as excinfo: s.reject_job("1") assert "running" in str(excinfo.value)
def test_reject_job_not_found_must_raise(self, mocker): s = SimulatorHandler() s.start("p", "w") with pytest.raises(LookupError) as excinfo: s.reject_job("1") assert "job" in str(excinfo.value)
def test_reject_job(self, mocker): mocker.patch("batsim_py.simulator.RejectJobBatsimRequest") s = SimulatorHandler() s.start("p", "w") e = BatsimEventAPI.get_job_submitted(res=1) msg = BatsimMessage(150, [JobSubmittedBatsimEvent(150, e['data'])]) mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg) mocker.patch.object(batsim_py.jobs.Job, '_reject') s.proceed_time() job_id = e['data']['job_id'] s.reject_job(job_id) assert not s.jobs batsim_py.jobs.Job._reject.assert_called_once() simulator.RejectJobBatsimRequest.assert_called_once_with( # type: ignore 150, job_id)
def test_reject_job_must_dispatch_event(self, mocker): def foo(j: Job): self.__called, self.__job_id = True, j.id self.__called, self.__job_id = False, -1 s = SimulatorHandler() s.start("p", "w") s.subscribe(JobEvent.REJECTED, foo) e = BatsimEventAPI.get_job_submitted(res=1) msg = BatsimMessage(150, [JobSubmittedBatsimEvent(150, e['data'])]) mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg) s.proceed_time() job_id = e['data']['job_id'] s.reject_job(job_id) assert self.__called and self.__job_id == job_id