diff --git a/unittests/data/test_data.py b/unittests/data/test_data.py index 50e83f1a1..b1afdada4 100644 --- a/unittests/data/test_data.py +++ b/unittests/data/test_data.py @@ -373,3 +373,82 @@ def test_get_monitors(self): self.assertEqual(3, PacmanDataView.get_ethernet_monitor_cores()) self.assertEqual(VariableSDRAM(200 + 100 + 55, 10 + 15), PacmanDataView.get_ethernet_monitor_sdram()) + + def test_required(self): + writer = PacmanDataWriter.setup() + with self.assertRaises(DataNotYetAvialable): + self.assertIsNone(PacmanDataView.get_n_boards_required()) + self.assertFalse(PacmanDataView.has_n_boards_required()) + with self.assertRaises(DataNotYetAvialable): + self.assertIsNone(PacmanDataView.get_n_chips_needed()) + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # required higher than in graph + writer.set_n_required(None, 20) + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertEqual(20, PacmanDataView.get_n_chips_needed()) + writer.set_n_chips_in_graph(15) + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertEqual(20, PacmanDataView.get_n_chips_needed()) + + # required higher than in graph + writer.set_n_chips_in_graph(25) + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertEqual(20, PacmanDataView.get_n_chips_needed()) + + # reset does not remove required + writer.start_run() + writer.finish_run() + writer.hard_reset() + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertEqual(20, PacmanDataView.get_n_chips_needed()) + + writer = PacmanDataWriter.setup() + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # in graph only + writer.set_n_chips_in_graph(25) + self.assertEqual(25, PacmanDataView.get_n_chips_needed()) + + # reset clears in graph + writer.start_run() + writer.finish_run() + writer.hard_reset() + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # N boards + writer = PacmanDataWriter.setup() + writer.set_n_required(5, None) + self.assertEqual(5, PacmanDataView.get_n_boards_required()) + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # boards does not hide in graph + writer.set_n_chips_in_graph(40) + self.assertEqual(5, PacmanDataView.get_n_boards_required()) + self.assertEqual(40, PacmanDataView.get_n_chips_needed()) + + # reset does not clear required + writer.start_run() + writer.finish_run() + writer.hard_reset() + self.assertEqual(5, PacmanDataView.get_n_boards_required()) + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # two Nones fine + writer = PacmanDataWriter.setup() + writer.set_n_required(None, None) + self.assertFalse(PacmanDataView.has_n_boards_required()) + self.assertFalse(PacmanDataView.has_n_chips_needed()) + + # Ilegal calls + with self.assertRaises(ValueError): + writer.set_n_required(5, 5) + with self.assertRaises(ValueError): + writer.set_n_required(None, -5) + with self.assertRaises(ValueError): + writer.set_n_required(0, None) + with self.assertRaises(TypeError): + writer.set_n_required(None, "five") + with self.assertRaises(TypeError): + writer.set_n_required("2.3", None)