diff --git a/spinnman/model/cpu_infos.py b/spinnman/model/cpu_infos.py index 4840576ac..d230cb4fb 100644 --- a/spinnman/model/cpu_infos.py +++ b/spinnman/model/cpu_infos.py @@ -90,6 +90,20 @@ def infos_for_state(self, state: CPUState) -> 'CPUInfos': for_state.add_info(info) return for_state + def infos_not_in_states(self, states: Iterable[CPUState]) -> 'CPUInfos': + """ + Creates a new CpuInfos object with Just the Infos that match the state. + + :param iterable(~spinnman.model.enums.CPUState) states: + :return: New Infos object with the filtered infos if any + :rtype: CPUInfos + """ + for_state = CPUInfos() + for info in self._cpu_infos.values(): + if info.state not in states: + for_state.add_info(info) + return for_state + def get_status_string(self) -> str: """ Get a string indicating the status of the given cores. diff --git a/unittests/model_tests/test_cpu_infos.py b/unittests/model_tests/test_cpu_infos.py index 1e5c55332..4b030156a 100644 --- a/unittests/model_tests/test_cpu_infos.py +++ b/unittests/model_tests/test_cpu_infos.py @@ -43,13 +43,14 @@ def test_cpu_infos(self): "['0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']", str(finished)) self.assertTrue(finished) + finished = infos.infos_not_in_states( + [CPUState.RUNNING, CPUState.RUN_TIME_EXCEPTION]) + self.assertEqual( + "['0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']", str(finished)) + idle = infos.infos_for_state(CPUState.IDLE) self.assertFalse(idle) - info = infos.get_cpu_info(0, 0, 2) - self.assertEqual( - "0:0:02 (06) FINISHED scamp-3 0", str(info)) - # the str is for example purpose and may change without notice self.assertEqual(infos.get_status_string(), "0:0:1 in state RUNNING\n"