def test_set_off_when_idle_must_raise(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) with pytest.raises(SystemError) as excinfo: h._set_off() assert "switching off" in str(excinfo.value)
def test_set_off_valid(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) h._switch_off() h._set_off() assert h.is_sleeping and h.power == p1.watt_full assert h.state == HostState.SLEEPING and h.pstate == p1
def test_start_computing_when_off_must_raise(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(3, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) h._switch_off() h._set_off() h._allocate("job") with pytest.raises(SystemError) as excinfo: h._start_computing() assert "idle or computing" in str(excinfo.value)
def test_set_on_valid(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) h._switch_off() h._set_off() h._switch_on() h._set_on() assert h.is_idle and h.pstate == p2 and h.state == HostState.IDLE
def test_set_computation_state_when_off_must_raise(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.COMPUTATION, 15, 150) p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p5 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4, p5]) h._switch_off() h._set_off() with pytest.raises(RuntimeError) as excinfo: h._set_computation_pstate(2) assert "idle or computing" in str(excinfo.value)
def test_switch_on_already_switching_on_must_raises(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(3, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) h._switch_off() h._set_off() h._switch_on() with pytest.raises(RuntimeError) as excinfo: h._switch_on() assert "be sleeping" in str(excinfo.value)
def test_switch_off_switching_on_must_raises(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.COMPUTATION, 1000, 10000) p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p5 = PowerState(4, PowerStateType.SWITCHING_ON, 25, 25) h = Host(0, "n", pstates=[p1, p3, p2, p4, p5]) h._switch_off() h._set_off() h._switch_on() with pytest.raises(RuntimeError) as excinfo: h._switch_off() assert "idle and free " in str(excinfo.value)