From d03821a1869d9ab074b8e421a0b53e3b2f09d56b Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 2 Nov 2023 14:07:37 +0000 Subject: [PATCH 1/2] infos_not_in_states method --- spinnman/model/cpu_infos.py | 14 ++++++++++++++ unittests/model_tests/test_cpu_infos.py | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) 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..8d6d9e30c 100644 --- a/unittests/model_tests/test_cpu_infos.py +++ b/unittests/model_tests/test_cpu_infos.py @@ -43,12 +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(), From 11849b22e4cf5e67cea032495d15b93339af9894 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 2 Nov 2023 14:11:58 +0000 Subject: [PATCH 2/2] flake8 --- unittests/model_tests/test_cpu_infos.py | 1 - 1 file changed, 1 deletion(-) diff --git a/unittests/model_tests/test_cpu_infos.py b/unittests/model_tests/test_cpu_infos.py index 8d6d9e30c..4b030156a 100644 --- a/unittests/model_tests/test_cpu_infos.py +++ b/unittests/model_tests/test_cpu_infos.py @@ -51,7 +51,6 @@ def test_cpu_infos(self): idle = infos.infos_for_state(CPUState.IDLE) self.assertFalse(idle) - # the str is for example purpose and may change without notice self.assertEqual(infos.get_status_string(), "0:0:1 in state RUNNING\n"