From a17eabe050b6c98ddc7626e4da21a904e8274975 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 10 Oct 2023 12:13:04 +0100 Subject: [PATCH] remove the with Transceiver in tests --- unittests/test_transceiver.py | 54 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/unittests/test_transceiver.py b/unittests/test_transceiver.py index 5af5f14d5..a3b1ab99a 100644 --- a/unittests/test_transceiver.py +++ b/unittests/test_transceiver.py @@ -20,7 +20,7 @@ from spinnman.data import SpiNNManDataView from spinnman.data.spinnman_data_writer import SpiNNManDataWriter from spinnman.extended.extended_transceiver import ExtendedTransceiver -from spinnman.transceiver import Transceiver +from spinnman.transceiver import create_transceiver_from_hostname, Transceiver from spinnman import constants from spinnman.messages.spinnaker_boot.system_variable_boot_values import ( SystemVariableDefinition) @@ -85,9 +85,8 @@ def test_create_new_transceiver_one_connection(self): connections = set() connections.add(SCAMPConnection( remote_host=self.board_config.remotehost)) - with extended.ExtendedTransceiver( - ver, connections=connections) as trans: - assert trans._all_connections == connections + trans = extended.ExtendedTransceiver(ver, connections=connections) + assert trans._all_connections == connections def test_create_new_transceiver_from_list_connections(self): self.board_config.set_up_remote_board() @@ -95,12 +94,11 @@ def test_create_new_transceiver_from_list_connections(self): connections.append(SCAMPConnection( remote_host=self.board_config.remotehost)) connections.append(BootConnection(remote_host="127.0.0.1")) - with transceiver.Transceiver(ver, connections=connections) as trans: - instantiated_connections = trans._all_connections + trans = transceiver.Transceiver(ver, connections=connections) + instantiated_connections = trans._all_connections - for connection in connections: - assert connection in instantiated_connections - # assert trans.get_connections() == connections + for connection in connections: + assert connection in instantiated_connections def test_retrieving_machine_details(self): self.board_config.set_up_remote_board() @@ -108,29 +106,27 @@ def test_retrieving_machine_details(self): connections.append(SCAMPConnection( remote_host=self.board_config.remotehost)) connections.append(BootConnection(remote_host="127.0.0.1")) - with transceiver.Transceiver(ver, connections=connections) as trans: - SpiNNManDataWriter.mock().set_machine(trans.get_machine_details()) - if self.board_config.board_version in (2, 3): - assert trans._get_machine_dimensions().width == 2 - assert trans._get_machine_dimensions().height == 2 - elif self.board_config.board_version in (4, 5): - assert trans._get_machine_dimensions().width == 8 - assert trans._get_machine_dimensions().height == 8 - else: - size = trans._get_machine_dimensions() - print(f"Unknown board with size {size.width} x {size.height}") - - assert any(c.is_connected() for c in trans._scamp_connections) - print(trans._get_scamp_version()) - print(trans.get_cpu_infos()) + trans = transceiver.Transceiver(ver, connections=connections) + SpiNNManDataWriter.mock().set_machine(trans.get_machine_details()) + if self.board_config.board_version in (2, 3): + assert trans._get_machine_dimensions().width == 2 + assert trans._get_machine_dimensions().height == 2 + elif self.board_config.board_version in (4, 5): + assert trans._get_machine_dimensions().width == 8 + assert trans._get_machine_dimensions().height == 8 + else: + size = trans._get_machine_dimensions() + print(f"Unknown board with size {size.width} x {size.height}") + + assert any(c.is_connected() for c in trans._scamp_connections) + print(trans._get_scamp_version()) + print(trans.get_cpu_infos()) def test_boot_board(self): self.board_config.set_up_remote_board() - with transceiver.create_transceiver_from_hostname( - self.board_config.remotehost, - self.board_config.board_version) as trans: - # self.assertFalse(trans.is_connected( unittest_setup())) - trans._boot_board() + trans = create_transceiver_from_hostname( + self.board_config.remotehost, self.board_config.board_version) + trans._boot_board() def test_set_watch_dog(self): set_config("Machine", "version", 5)