def test_switch_ps_must_dispatch_host_event(self, mocker): def foo(h: Host): self.__called, self.__h_id = True, h.id self.__called, self.__h_id = False, -1 s = SimulatorHandler() s.start("p", "w") s.subscribe(HostEvent.COMPUTATION_POWER_STATE_CHANGED, foo) h = s.platform.get_host(0) ps = h.get_pstate_by_type(PowerStateType.COMPUTATION) s.switch_power_state(0, ps[-1].id) assert self.__called and self.__h_id == 0
def test_switch_ps(self, mocker): mocker.patch("batsim_py.simulator.SetResourceStateBatsimRequest") mocker.patch.object(batsim_py.resources.Host, '_set_computation_pstate') s = SimulatorHandler() s.start("p", "w") h = s.platform.get_host(0) ps = h.get_pstate_by_type(PowerStateType.COMPUTATION) assert len(ps) == 2 s.switch_power_state(0, ps[-1].id) batsim_py.resources.Host._set_computation_pstate.assert_called_once() simulator.SetResourceStateBatsimRequest.assert_called_once_with( # type: ignore 0, [0], ps[-1].id)
def test_switch_ps_not_found_must_raise(self): s = SimulatorHandler() s.start("p", "w") with pytest.raises(LookupError) as excinfo: s.switch_power_state(10, 0) assert 'resources' in str(excinfo.value)
def test_switch_ps_not_running_must_raise(self): s = SimulatorHandler() with pytest.raises(RuntimeError) as excinfo: s.switch_power_state(0, 0) assert 'running' in str(excinfo.value)