def test_set_on_when_switching_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() with pytest.raises(SystemError) as excinfo: h._set_on() assert "switching on" in str(excinfo.value)
def test_state(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) h1 = Host(0, "n", pstates=[p1, p3, p2, p4, p5]) h2 = Host(1, "n") p = Platform([h1, h2]) h1._switch_off() assert p.state == [HostState.SWITCHING_OFF, HostState.IDLE]
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_set_computation_state_when_switching_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() with pytest.raises(RuntimeError) as excinfo: h._set_computation_pstate(2) assert "idle or computing" in str(excinfo.value)
def test_switch_off_allocated_must_raise(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._allocate("job") with pytest.raises(RuntimeError) as excinfo: h._switch_off() assert "idle and free " in str(excinfo.value)
def test_switch_off_valid(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() assert h.is_switching_off and h.power == p4.watt_idle assert h.pstate == p4 and h.state == HostState.SWITCHING_OFF
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_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_without_pstates_defined_must_raise(self): h = Host(0, "n", pstates=[]) with pytest.raises(RuntimeError) as excinfo: h._switch_off() assert "undefined" in str(excinfo.value)