From 6144778cdcb9b00e00622316319c1e9051e31b47 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 9 Jun 2021 16:21:10 +0100 Subject: [PATCH 1/5] call unittest_setup in every test for simplisity --- pacman/config_setup.py | 4 +-- .../test_python_class_algorithm.py | 4 +++ .../test_python_function_algorithm.py | 4 +++ .../test_application_edge.py | 4 +++ .../test_application_graph.py | 4 +++ .../test_application_vertex.py | 5 ++++ .../graph_mapper_tests/test_graph_mapping.py | 4 +++ .../graph_mapper_tests/test_slice.py | 4 +++ .../test_machine_graph_model.py | 4 +++ .../splitter_slice_legacy_test.py | 4 +++ .../test_placement_constraints.py | 4 +++ .../placement_tests/test_placement_object.py | 4 +++ .../placement_tests/test_placements_model.py | 4 +++ .../resources_tests/test_resources_model.py | 4 +++ .../routing_info_tests/test_routing_info.py | 5 +++- .../test_routing_tables_model.py | 6 +++- .../test_one_app_one_machine.py | 5 ++++ .../test_splitter_slice_legacy.py | 5 ++++ .../tag_tests/test_tag_infos_model.py | 4 +++ unittests/model_tests/test_key_allocator.py | 5 ++++ unittests/model_tests/test_partition.py | 5 ++++ unittests/model_tests/test_slice.py | 5 ++++ .../test_basic_partitioner.py | 21 ++------------ .../test_partitioner.py | 29 ++----------------- ...artitioner_with_pre_allocated_resources.py | 12 ++++---- .../test_splitter_partitioner.py | 4 +++ .../test_connecitve_placer.py | 4 +-- .../test_one_to_one_placer.py | 8 ++--- .../test_radial_placer.py | 4 +-- .../test_same_chip_constraint.py | 4 +-- .../test_sdram_edge_placement.py | 4 +-- .../test_spreader_placer.py | 8 ++--- .../test_virtual_placement.py | 4 +-- .../test_basic_dijkstra_routing.py | 4 +-- .../test_ner_route_default.py | 4 +-- .../test_ner_route_traffic_aware.py | 8 ++--- ...test_checked_unordered_pair_compression.py | 4 +-- .../test_compressors.py | 8 ++--- .../test_ordered_covering_compression.py | 4 +-- .../test_pair_compression.py | 4 +-- .../test_unordered_pair_compression.py | 4 +-- .../test_malloc_routing_info_allocator.py | 4 +++ .../test_mask_generator.py | 2 ++ .../test_zoned_routing_allocator.py | 15 +++++++++- .../test_tags_board_addresses.py | 4 +-- unittests/test_cfg_checker.py | 4 +-- unittests/test_fixed_route_router.py | 7 ++--- unittests/test_import_all.py | 4 +++ unittests/test_pacman_algorithm_executor.py | 7 ++--- unittests/test_token_states.py | 4 +++ unittests/test_version.py | 4 +++ unittests/utilities_tests/test_constants.py | 4 +++ unittests/utilities_tests/test_json_utils.py | 4 +++ .../test_placer_algorithm_utilities.py | 4 +++ .../utilities_tests/test_resource_tracker.py | 7 ++--- 55 files changed, 199 insertions(+), 114 deletions(-) diff --git a/pacman/config_setup.py b/pacman/config_setup.py index d61e7fb91..dfe3201f9 100644 --- a/pacman/config_setup.py +++ b/pacman/config_setup.py @@ -21,7 +21,7 @@ BASE_CONFIG_FILE = "pacman.cfg" -def reset_configs(): +def unittest_setup(): """ Resets the configs so only the local default config is included. @@ -29,7 +29,7 @@ def reset_configs(): This file should only be called from PACMAN/unittests """ - clear_cfg_files() + clear_cfg_files(True) add_pacman_cfg() diff --git a/unittests/model_tests/algorithm_classes_tests/test_python_class_algorithm.py b/unittests/model_tests/algorithm_classes_tests/test_python_class_algorithm.py index 24bb08c5c..f41ad4d52 100644 --- a/unittests/model_tests/algorithm_classes_tests/test_python_class_algorithm.py +++ b/unittests/model_tests/algorithm_classes_tests/test_python_class_algorithm.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.executor.algorithm_classes import PythonClassAlgorithm @@ -22,6 +23,9 @@ class TestPythonClassAlgorithm(unittest.TestCase): tests which test the application graph object """ + def setUp(self): + unittest_setup() + def test_python_class(self): python_module = "Foo" python_class = "Bar" diff --git a/unittests/model_tests/algorithm_classes_tests/test_python_function_algorithm.py b/unittests/model_tests/algorithm_classes_tests/test_python_function_algorithm.py index 08ab569a4..8c8c4513d 100644 --- a/unittests/model_tests/algorithm_classes_tests/test_python_function_algorithm.py +++ b/unittests/model_tests/algorithm_classes_tests/test_python_function_algorithm.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.executor.algorithm_classes import PythonFunctionAlgorithm @@ -22,6 +23,9 @@ class TestPythonFunctionAlgorithm(unittest.TestCase): tests which test the application graph object """ + def setUp(self): + unittest_setup() + def test_python_module(self): python_module = "Foo" python_function = "bar" diff --git a/unittests/model_tests/application_graph_tests/test_application_edge.py b/unittests/model_tests/application_graph_tests/test_application_edge.py index d8d0d35a1..f342cf823 100644 --- a/unittests/model_tests/application_graph_tests/test_application_edge.py +++ b/unittests/model_tests/application_graph_tests/test_application_edge.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman_test_objects import SimpleTestEdge, SimpleTestVertex @@ -22,6 +23,9 @@ class TestApplicationEdgeModel(unittest.TestCase): tests which test the application graph object """ + def setUp(self): + unittest_setup() + def test_create_new_edge(self): """ test that you can create a edge between two vertices diff --git a/unittests/model_tests/application_graph_tests/test_application_graph.py b/unittests/model_tests/application_graph_tests/test_application_graph.py index faa9d48a8..1d8b016f5 100644 --- a/unittests/model_tests/application_graph_tests/test_application_graph.py +++ b/unittests/model_tests/application_graph_tests/test_application_graph.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanConfigurationException from pacman.model.graphs.application import ApplicationGraphView from pacman.model.graphs.application import ApplicationEdge, ApplicationGraph @@ -25,6 +26,9 @@ class TestApplicationGraphModel(unittest.TestCase): tests which test the application graph object """ + def setUp(self): + unittest_setup() + def test_create_new_empty_graph(self): ApplicationGraph("foo") diff --git a/unittests/model_tests/application_graph_tests/test_application_vertex.py b/unittests/model_tests/application_graph_tests/test_application_vertex.py index c8c155266..5c7d7ef92 100644 --- a/unittests/model_tests/application_graph_tests/test_application_vertex.py +++ b/unittests/model_tests/application_graph_tests/test_application_vertex.py @@ -15,6 +15,7 @@ import numpy import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanInvalidParameterException from pacman.model.constraints.partitioner_constraints import ( MaxVertexAtomsConstraint) @@ -28,6 +29,10 @@ class TestApplicationGraphModel(unittest.TestCase): """ tests which test the application graph object """ + + def setUp(self): + unittest_setup() + def test_create_new_vertex(self): """ test initialisation of a vertex diff --git a/unittests/model_tests/graph_mapper_tests/test_graph_mapping.py b/unittests/model_tests/graph_mapper_tests/test_graph_mapping.py index 15d1a354c..9412d1ea5 100644 --- a/unittests/model_tests/graph_mapper_tests/test_graph_mapping.py +++ b/unittests/model_tests/graph_mapper_tests/test_graph_mapping.py @@ -18,6 +18,7 @@ """ import unittest +from pacman.config_setup import unittest_setup from pacman.model.graphs.application import ApplicationGraph from pacman.model.graphs.common import Slice from pacman.model.graphs.machine import MachineEdge, SimpleMachineVertex, \ @@ -30,6 +31,9 @@ class TestGraphMapping(unittest.TestCase): graph mapper tests """ + def setUp(self): + unittest_setup() + def test_get_edges_from_edge(self): """ test getting the edges from a graph mapper from a edge diff --git a/unittests/model_tests/graph_mapper_tests/test_slice.py b/unittests/model_tests/graph_mapper_tests/test_slice.py index 67abd18c6..48cffcd2a 100644 --- a/unittests/model_tests/graph_mapper_tests/test_slice.py +++ b/unittests/model_tests/graph_mapper_tests/test_slice.py @@ -17,6 +17,7 @@ tests for slice """ import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanValueError from pacman.model.graphs.common import Slice @@ -26,6 +27,9 @@ class TestSliceFunctions(unittest.TestCase): slice function tests """ + def setUp(self): + unittest_setup() + def test_create_slice_valid(self): """ test creating a empty slice diff --git a/unittests/model_tests/machine_graph_tests/test_machine_graph_model.py b/unittests/model_tests/machine_graph_tests/test_machine_graph_model.py index 0e9112026..adcc89e68 100644 --- a/unittests/model_tests/machine_graph_tests/test_machine_graph_model.py +++ b/unittests/model_tests/machine_graph_tests/test_machine_graph_model.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.model.graphs.application import ApplicationGraph from pacman.model.graphs.common import EdgeTrafficType from pacman.model.graphs.machine import ( @@ -31,6 +32,9 @@ class TestMachineGraphModel(unittest.TestCase): Tests that test the functionality of the machine graph object """ + def setUp(self): + unittest_setup() + def test_new_vertex(self): """ test the creation of a machine vertex diff --git a/unittests/model_tests/partitioner_splitters_tests/splitter_slice_legacy_test.py b/unittests/model_tests/partitioner_splitters_tests/splitter_slice_legacy_test.py index 22eb76776..8c984a112 100644 --- a/unittests/model_tests/partitioner_splitters_tests/splitter_slice_legacy_test.py +++ b/unittests/model_tests/partitioner_splitters_tests/splitter_slice_legacy_test.py @@ -15,6 +15,7 @@ import unittest from testfixtures import LogCapture +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanConfigurationException from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman_test_objects import ( @@ -25,6 +26,9 @@ class TestSplitterSliceLegacy(unittest.TestCase): """ Tester for pacman.model.constraints.placer_constraints """ + def setUp(self): + unittest_setup() + def test_no_api(self): splitter = SplitterSliceLegacy() vertex = NonLegacyApplicationVertex() diff --git a/unittests/model_tests/placement_tests/test_placement_constraints.py b/unittests/model_tests/placement_tests/test_placement_constraints.py index 8a6fef691..d32ef725f 100644 --- a/unittests/model_tests/placement_tests/test_placement_constraints.py +++ b/unittests/model_tests/placement_tests/test_placement_constraints.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.model.constraints.placer_constraints import ( BoardConstraint, ChipAndCoreConstraint, RadialPlacementFromChipConstraint, SameChipAsConstraint) @@ -24,6 +25,9 @@ class TestPlacementConstraints(unittest.TestCase): """ Tester for pacman.model.constraints.placer_constraints """ + def setUp(self): + unittest_setup() + def test_board_constraint(self): c1 = BoardConstraint("1.2.3.4") self.assertEqual(c1.board_address, "1.2.3.4") diff --git a/unittests/model_tests/placement_tests/test_placement_object.py b/unittests/model_tests/placement_tests/test_placement_object.py index 852bfe755..98d71bb77 100644 --- a/unittests/model_tests/placement_tests/test_placement_object.py +++ b/unittests/model_tests/placement_tests/test_placement_object.py @@ -17,6 +17,7 @@ tests for placement """ import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanAlreadyPlacedError from pacman.model.graphs.machine import SimpleMachineVertex from pacman.model.placements import Placement, Placements @@ -27,6 +28,9 @@ class TestPlacement(unittest.TestCase): tester for placement object in pacman.model.placements.placement """ + def setUp(self): + unittest_setup() + def test_create_new_placement(self): """ test that creating a new placement puts stuff in the right place diff --git a/unittests/model_tests/placement_tests/test_placements_model.py b/unittests/model_tests/placement_tests/test_placements_model.py index 52586a6b7..a4572ba0b 100644 --- a/unittests/model_tests/placement_tests/test_placements_model.py +++ b/unittests/model_tests/placement_tests/test_placements_model.py @@ -17,6 +17,7 @@ tests for placements """ import unittest +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import SimpleMachineVertex from pacman.model.placements import Placement, Placements @@ -26,6 +27,9 @@ class TestPlacements(unittest.TestCase): tester for placements object in pacman.model.placements.placements """ + def setUp(self): + unittest_setup() + def test_create_new_placements(self): """ test creating a placements object diff --git a/unittests/model_tests/resources_tests/test_resources_model.py b/unittests/model_tests/resources_tests/test_resources_model.py index 9c69b1b8b..b374b99eb 100644 --- a/unittests/model_tests/resources_tests/test_resources_model.py +++ b/unittests/model_tests/resources_tests/test_resources_model.py @@ -19,6 +19,7 @@ from enum import Enum import tempfile import unittest +from pacman.config_setup import unittest_setup from pacman.model.resources import ( ConstantSDRAM, CPUCyclesPerTickResource, DTCMResource, ResourceContainer, IPtagResource, MultiRegionSDRAM, ReverseIPtagResource, @@ -36,6 +37,9 @@ class TestResourceModels(unittest.TestCase): unit tests on the resources object """ + def setUp(self): + unittest_setup() + def test_sdram(self): """ test that adding a SDRAM resource to a resource container works diff --git a/unittests/model_tests/routing_info_tests/test_routing_info.py b/unittests/model_tests/routing_info_tests/test_routing_info.py index e914b48cc..90ebe9e7c 100644 --- a/unittests/model_tests/routing_info_tests/test_routing_info.py +++ b/unittests/model_tests/routing_info_tests/test_routing_info.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import unittest - +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import MulticastEdgePartition from pacman.model.resources import ResourceContainer from pacman.exceptions import ( @@ -28,6 +28,9 @@ class TestRoutingInfo(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_routing_info(self): # mock to avoid having to create a graph for this test graph_code = 123 diff --git a/unittests/model_tests/routing_table_tests/test_routing_tables_model.py b/unittests/model_tests/routing_table_tests/test_routing_tables_model.py index d6fc3bbdf..d852d6b20 100644 --- a/unittests/model_tests/routing_table_tests/test_routing_tables_model.py +++ b/unittests/model_tests/routing_table_tests/test_routing_tables_model.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import unittest - +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import MulticastEdgePartition from spinn_machine import MulticastRoutingEntry from pacman.model.routing_tables import ( @@ -32,6 +32,10 @@ class TestRoutingTable(unittest.TestCase): """ tests for the routing table object """ + + def setUp(self): + unittest_setup() + def test_new_multicast_routing_table_entry(self): """ test that creating a multicast routing entry works diff --git a/unittests/model_tests/splitter_tests/test_one_app_one_machine.py b/unittests/model_tests/splitter_tests/test_one_app_one_machine.py index 69b7eb45a..50bc82c3f 100644 --- a/unittests/model_tests/splitter_tests/test_one_app_one_machine.py +++ b/unittests/model_tests/splitter_tests/test_one_app_one_machine.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanConfigurationException from pacman.model.graphs.application.abstract import ( AbstractOneAppOneMachineVertex) @@ -22,6 +23,10 @@ class TestSplitterOneAppOneMachine(unittest.TestCase): + + def setUp(self): + unittest_setup() + def test_legacy(self): splitter = SplitterOneAppOneMachine("foo") v1 = NonLegacyApplicationVertex("v1") diff --git a/unittests/model_tests/splitter_tests/test_splitter_slice_legacy.py b/unittests/model_tests/splitter_tests/test_splitter_slice_legacy.py index 0a063d4ee..b32316d6a 100644 --- a/unittests/model_tests/splitter_tests/test_splitter_slice_legacy.py +++ b/unittests/model_tests/splitter_tests/test_splitter_slice_legacy.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanConfigurationException from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman_test_objects import ( @@ -21,6 +22,10 @@ class TestSplitterSliceLegacy(unittest.TestCase): + + def setUp(self): + unittest_setup() + def test_api(self): splitter = SplitterSliceLegacy("foo") a = str(splitter) diff --git a/unittests/model_tests/tag_tests/test_tag_infos_model.py b/unittests/model_tests/tag_tests/test_tag_infos_model.py index 6b6ea6eef..b958923fd 100644 --- a/unittests/model_tests/tag_tests/test_tag_infos_model.py +++ b/unittests/model_tests/tag_tests/test_tag_infos_model.py @@ -18,6 +18,7 @@ """ import unittest from spinn_machine.tags import IPTag, ReverseIPTag +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanInvalidParameterException from pacman.model.graphs.machine import SimpleMachineVertex from pacman.model.tags import Tags @@ -28,6 +29,9 @@ class TestTagsModel(unittest.TestCase): test that the tags object works as expected """ + def setUp(self): + unittest_setup() + def test_new_tag_info(self): """ test that creating a empty tag object works diff --git a/unittests/model_tests/test_key_allocator.py b/unittests/model_tests/test_key_allocator.py index 6d9083bb4..414cfc264 100644 --- a/unittests/model_tests/test_key_allocator.py +++ b/unittests/model_tests/test_key_allocator.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.model.routing_info import BaseKeyAndMask from pacman.utilities.utility_objs import Field from pacman.model.constraints.key_allocator_constraints import ( @@ -22,6 +23,10 @@ class TestKeyAllocatorConstraints(unittest.TestCase): + + def setUp(self): + unittest_setup() + def test_contiguous_key_range_constraint(self): c1 = ContiguousKeyRangeContraint() c2 = ContiguousKeyRangeContraint() diff --git a/unittests/model_tests/test_partition.py b/unittests/model_tests/test_partition.py index 06dcf72e9..3dce4aeb1 100644 --- a/unittests/model_tests/test_partition.py +++ b/unittests/model_tests/test_partition.py @@ -14,6 +14,8 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup + from pacman.model.graphs.machine import SimpleMachineVertex from pacman.model.constraints.partitioner_constraints import ( MaxVertexAtomsConstraint, SameAtomsAsVertexConstraint, @@ -24,6 +26,9 @@ class TestPartitionConstraints(unittest.TestCase): """ Tester for pacman.model.constraints.partitioner_constraints """ + def setUp(self): + unittest_setup() + def test_max_vertex_atoms_constraint(self): c1 = MaxVertexAtomsConstraint(5) self.assertEqual(c1.size, 5) diff --git a/unittests/model_tests/test_slice.py b/unittests/model_tests/test_slice.py index a41c4e3dd..6834ecdc3 100644 --- a/unittests/model_tests/test_slice.py +++ b/unittests/model_tests/test_slice.py @@ -14,11 +14,16 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.model.graphs.common import Slice class TestSlice(unittest.TestCase): """Tests that Slices expose the correct options and are immutable.""" + + def setUp(self): + unittest_setup() + def test_basic(self): s = Slice(0, 10) assert s.n_atoms == 11 # 10 - 0 + 1 diff --git a/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py b/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py index 722450896..9d44ad107 100644 --- a/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py +++ b/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py @@ -20,7 +20,7 @@ import unittest from spinn_utilities.config_holder import load_config, set_config -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman.operations.partition_algorithms import SplitterPartitioner from spinn_machine import ( @@ -43,16 +43,10 @@ class TestBasicPartitioner(unittest.TestCase): TheTestAddress = "192.162.240.253" def setUp(self): - reset_configs() - load_config() - - def tearDown(self): - reset_configs() - - def setup(self): """ setup for all basic partitioner tests """ + unittest_setup() self.vert1 = SimpleTestVertex(10, "New AbstractConstrainedVertex 1") self.vert1.splitter = SplitterSliceLegacy() self.vert2 = SimpleTestVertex(5, "New AbstractConstrainedVertex 2") @@ -103,7 +97,6 @@ def test_partition_with_no_additional_constraints(self): """ test a partitioning with a graph with no extra constraints """ - self.setup() graph, _ = self.sp(self.graph, self.machine, 3000) self.assertEqual(len(list(graph.vertices)), 3) vert_sizes = [] @@ -117,7 +110,6 @@ def test_partition_with_no_additional_constraints_extra_edge(self): """ test that the basic form with an extra edge works """ - self.setup() self.graph.add_edge( ApplicationEdge(self.vert3, self.vert1, label="extra"), "TEST") graph, _ = self.sp(self.graph, self.machine, 3000) @@ -128,7 +120,6 @@ def test_partition_on_large_vertex_than_has_to_be_split(self): """ test that partitioning 1 large vertex can make it into 2 small ones """ - self.setup() large_vertex = SimpleTestVertex(300, "Large vertex") large_vertex.splitter = SplitterSliceLegacy() self.graph = ApplicationGraph("Graph with large vertex") @@ -142,7 +133,6 @@ def test_partition_on_very_large_vertex_than_has_to_be_split(self): test that partitioning 1 large vertex can make it into multiple small ones """ - self.setup() large_vertex = SimpleTestVertex(500, "Large vertex") large_vertex.splitter = SplitterSliceLegacy() self.assertEqual(large_vertex._model_based_max_atoms_per_core, 256) @@ -156,7 +146,6 @@ def test_partition_on_target_size_vertex_than_has_to_be_split(self): """ test that fixed partitioning causes correct number of vertices """ - self.setup() large_vertex = SimpleTestVertex(1000, "Large vertex") large_vertex.add_constraint(MaxVertexAtomsConstraint(10)) large_vertex.splitter = SplitterSliceLegacy() @@ -169,7 +158,6 @@ def test_partition_with_barely_sufficient_space(self): """ test that partitioning will work when close to filling the machine """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -212,7 +200,6 @@ def test_partition_with_insufficient_space(self): test that if there's not enough space, the test the partitioner will raise an error """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -253,7 +240,6 @@ def test_partition_with_less_sdram_than_default(self): test that the partitioner works when its machine is slightly malformed in that it has less SDRAM available """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -287,7 +273,6 @@ def test_partition_with_more_sdram_than_default(self): test that the partitioner works when its machine is slightly malformed in that it has more SDRAM available """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -321,7 +306,6 @@ def test_partition_with_unsupported_constraints(self): test that when a vertex has a constraint that is unrecognised, it raises an error """ - self.setup() constrained_vertex = SimpleTestVertex(13, "Constrained") constrained_vertex.add_constraint( NewPartitionerConstraint("Mock constraint")) @@ -332,7 +316,6 @@ def test_partition_with_empty_graph(self): """ test that the partitioner can work with an empty graph """ - self.setup() self.graph = ApplicationGraph("foo") graph, _ = self.sp(self.graph, self.machine, 3000) self.assertEqual(len(list(graph.vertices)), 0) diff --git a/unittests/operations_tests/partition_algorithms_tests/test_partitioner.py b/unittests/operations_tests/partition_algorithms_tests/test_partitioner.py index 0c73448fe..0700a4e53 100644 --- a/unittests/operations_tests/partition_algorithms_tests/test_partitioner.py +++ b/unittests/operations_tests/partition_algorithms_tests/test_partitioner.py @@ -17,8 +17,8 @@ test for partitioning """ import unittest -from spinn_utilities.config_holder import load_config, set_config -from pacman.config_setup import reset_configs +from spinn_utilities.config_holder import set_config +from pacman.config_setup import unittest_setup from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman.operations.partition_algorithms import SplitterPartitioner from spinn_machine import ( @@ -40,15 +40,9 @@ class TestPartitioner(unittest.TestCase): """ def setUp(self): - reset_configs() - load_config() - - def tearDown(self): - reset_configs() - - def setup(self): """setup for all basic partitioner tests """ + unittest_setup() self.vert1 = SimpleTestVertex(10, "New AbstractConstrainedVertex 1") self.vert1.splitter = SplitterSliceLegacy() self.vert2 = SimpleTestVertex(5, "New AbstractConstrainedVertex 2") @@ -98,7 +92,6 @@ def setup(self): def test_partition_with_no_additional_constraints(self): """test a partitioning with a graph with no extra constraints """ - self.setup() graph, _ = self.bp( self.graph, self.machine, plan_n_time_steps=100, pre_allocated_resources=PreAllocatedResourceContainer()) @@ -113,7 +106,6 @@ def test_partition_with_no_additional_constraints(self): def test_partition_with_no_additional_constraints_extra_edge(self): """test that the basic form with an extra edge works """ - self.setup() self.graph.add_edge( ApplicationEdge(self.vert3, self.vert1), "TEST") graph, _ = self.bp( @@ -126,7 +118,6 @@ def test_partition_on_large_vertex_than_has_to_be_split(self): """ test that partitioning 1 large vertex can make it into 2 small ones """ - self.setup() large_vertex = SimpleTestVertex(300, "Large vertex") large_vertex.splitter = SplitterSliceLegacy() self.graph = ApplicationGraph("Graph with large vertex") @@ -142,7 +133,6 @@ def test_partition_on_very_large_vertex_than_has_to_be_split(self): test that partitioning 1 large vertex can make it into multiple small ones """ - self.setup() large_vertex = SimpleTestVertex(500, "Large vertex") large_vertex.splitter = SplitterSliceLegacy() self.assertEqual(large_vertex._model_based_max_atoms_per_core, 256) @@ -158,7 +148,6 @@ def test_partition_on_target_size_vertex_than_has_to_be_split(self): """ test that fixed partitioning causes correct number of vertices """ - self.setup() large_vertex = SimpleTestVertex(1000, "Large vertex") large_vertex.add_constraint(MaxVertexAtomsConstraint(10)) large_vertex.splitter = SplitterSliceLegacy() @@ -173,8 +162,6 @@ def test_partition_with_barely_sufficient_space(self): """ test that partitioning will work when close to filling the machine """ - self.setup() - n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -219,7 +206,6 @@ def test_partition_with_insufficient_space(self): test that if there's not enough space, the test the partitioner will raise an error """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -261,7 +247,6 @@ def test_partition_with_less_sdram_than_default(self): test that the partitioner works when its machine is slightly malformed in that it has less SDRAM available """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -296,7 +281,6 @@ def test_partition_with_more_sdram_than_default(self): test that the partitioner works when its machine is slightly malformed in that it has more SDRAM available """ - self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) @@ -331,7 +315,6 @@ def test_partition_with_unsupported_constraints(self): test that when a vertex has a constraint that is unrecognised, it raises an error """ - self.setup() constrained_vertex = SimpleTestVertex(13, "Constrained") constrained_vertex.add_constraint( NewPartitionerConstraint("Mock constraint")) @@ -341,7 +324,6 @@ def test_partition_with_unsupported_constraints(self): def test_partition_with_empty_graph(self): """test that the partitioner can work with an empty graph """ - self.setup() self.graph = ApplicationGraph("foo") graph, _ = self.bp( self.graph, self.machine, plan_n_time_steps=100, @@ -354,7 +336,6 @@ def test_operation_with_same_size_as_vertex_constraint(self): constraints on a vertex that is split into one core """ with self.assertRaises(NotImplementedError): - self.setup() constrained_vertex = SimpleTestVertex(5, "Constrained") constrained_vertex.add_constraint( SameAtomsAsVertexConstraint(self.vert2)) @@ -372,7 +353,6 @@ def test_operation_with_same_size_as_vertex_constraint_large_vertices( constraints on a vertex which has to be split over many cores """ with self.assertRaises(NotImplementedError): - self.setup() constrained_vertex = SimpleTestVertex(300, "Constrained") new_large_vertex = SimpleTestVertex(300, "Non constrained") constrained_vertex.add_constraint( @@ -392,7 +372,6 @@ def test_operation_same_size_as_vertex_constraint_different_order(self): the order of the vertices being added is different. """ with self.assertRaises(NotImplementedError): - self.setup() constrained_vertex = SimpleTestVertex(300, "Constrained") new_large_vertex = SimpleTestVertex(300, "Non constrained") constrained_vertex.add_constraint( @@ -412,7 +391,6 @@ def test_operation_with_same_size_as_vertex_constraint_exception(self): causes errors """ with self.assertRaises(NotImplementedError): - self.setup() constrained_vertex = SimpleTestVertex(100, "Constrained") constrained_vertex.add_constraint( SameAtomsAsVertexConstraint(self.vert2)) @@ -448,7 +426,6 @@ def test_operation_with_same_size_as_vertex_constraint_chain(self): self.assertEqual(len(subvertices_2), len(subvertices_3)) def test_partitioning_with_2_massive_pops(self): - self.setup() constrained_vertex = SimpleTestVertex(16000, "Constrained") constrained_vertex.splitter = SplitterSliceLegacy() self.graph.add_vertex(constrained_vertex) diff --git a/unittests/operations_tests/partition_algorithms_tests/test_partitioner_with_pre_allocated_resources.py b/unittests/operations_tests/partition_algorithms_tests/test_partitioner_with_pre_allocated_resources.py index bd6ad7c9a..d0a8ca00e 100644 --- a/unittests/operations_tests/partition_algorithms_tests/test_partitioner_with_pre_allocated_resources.py +++ b/unittests/operations_tests/partition_algorithms_tests/test_partitioner_with_pre_allocated_resources.py @@ -15,7 +15,7 @@ import pytest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman.operations.partition_algorithms import SplitterPartitioner from pacman.exceptions import ( @@ -36,7 +36,7 @@ class TestPartitionerWithPreAllocatedResources(object): """ def test_1_chip_over_pre_allocated(self): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() @@ -60,7 +60,7 @@ def test_1_chip_over_pre_allocated(self): pre_allocated_resources=pre_allocated_res) def test_1_chip_under_pre_allocated(self): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() @@ -86,7 +86,7 @@ def test_1_chip_under_pre_allocated(self): raise Exception("should have blown up here") from e def test_1_chip_pre_allocated_same_core(self): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() @@ -111,7 +111,7 @@ def test_1_chip_pre_allocated_same_core(self): pre_allocated_resources=pre_allocated_res) def test_1_chip_pre_allocated_too_much_sdram(self): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() @@ -140,7 +140,7 @@ def test_1_chip_pre_allocated_too_much_sdram(self): pre_allocated_resources=pre_allocated_res) def test_1_chip_no_pre_allocated_too_much_sdram(self): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() diff --git a/unittests/operations_tests/partition_algorithms_tests/test_splitter_partitioner.py b/unittests/operations_tests/partition_algorithms_tests/test_splitter_partitioner.py index 933be262b..9cfde3957 100644 --- a/unittests/operations_tests/partition_algorithms_tests/test_splitter_partitioner.py +++ b/unittests/operations_tests/partition_algorithms_tests/test_splitter_partitioner.py @@ -18,6 +18,7 @@ """ import unittest +from pacman.config_setup import unittest_setup from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman.model.partitioner_splitters.abstract_splitters import ( AbstractDependentSplitter) @@ -58,6 +59,9 @@ class TestSplitterPartitioner(unittest.TestCase): """ # pylint: disable=attribute-defined-outside-init + def setUp(self): + unittest_setup() + def test_order_vertices_for_dependent_splitters(self): vertices = list() v1 = SimpleTestVertex(1, splitter=SplitterSliceLegacy(), label="v1") diff --git a/unittests/operations_tests/placer_algorithms_tests/test_connecitve_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_connecitve_placer.py index dd8da5c5c..1ea3526c4 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_connecitve_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_connecitve_placer.py @@ -15,7 +15,7 @@ import unittest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.common import Slice from pacman.model.graphs.machine import ( MachineGraph, MachineEdge, SimpleMachineVertex) @@ -30,7 +30,7 @@ class TestConnectivePlacer(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() self.machine = virtual_machine(8, 8) self.mach_graph = MachineGraph("machine") self.vertices = list() diff --git a/unittests/operations_tests/placer_algorithms_tests/test_one_to_one_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_one_to_one_placer.py index 719d4569c..cdb32911d 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_one_to_one_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_one_to_one_placer.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import pytest from spinn_machine.virtual_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanException from pacman.model.graphs.machine import ( MachineGraph, SimpleMachineVertex, MachineSpiNNakerLinkVertex, MachineEdge, @@ -31,7 +31,7 @@ def test_virtual_vertices_one_to_one(): """ Test that the placer works with a virtual vertex """ - reset_configs() + unittest_setup() # Create a graph with a virtual vertex machine_graph = MachineGraph("Test") @@ -86,7 +86,7 @@ def test_virtual_vertices_one_to_one(): def test_one_to_one(): """ Test normal 1-1 placement """ - reset_configs() + unittest_setup() # Create a graph machine_graph = MachineGraph("Test") @@ -145,7 +145,7 @@ def test_one_to_one(): def test_sdram_links(): """ Test sdram edges which should explode """ - reset_configs() + unittest_setup() # Create a graph machine_graph = MachineGraph("Test") diff --git a/unittests/operations_tests/placer_algorithms_tests/test_radial_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_radial_placer.py index e53262ea1..70d296fe4 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_radial_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_radial_placer.py @@ -15,7 +15,7 @@ import unittest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.common import Slice from pacman.model.graphs.machine import MachineGraph, SimpleMachineVertex from pacman.model.resources import ( @@ -29,7 +29,7 @@ class TestRadialPlacer(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() self.machine = virtual_machine(8, 8) self.mach_graph = MachineGraph("machine") self.vertices = list() diff --git a/unittests/operations_tests/placer_algorithms_tests/test_same_chip_constraint.py b/unittests/operations_tests/placer_algorithms_tests/test_same_chip_constraint.py index 0ba07a79a..7e68f8e2c 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_same_chip_constraint.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_same_chip_constraint.py @@ -16,7 +16,7 @@ import random import unittest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import MachineGraph, SimpleMachineVertex from pacman.model.resources import ResourceContainer from pacman.model.constraints.placer_constraints import SameChipAsConstraint @@ -27,7 +27,7 @@ class TestSameChipConstraint(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def _do_test(self, placer): machine = virtual_machine(width=8, height=8) diff --git a/unittests/operations_tests/placer_algorithms_tests/test_sdram_edge_placement.py b/unittests/operations_tests/placer_algorithms_tests/test_sdram_edge_placement.py index 8f7bb8258..418eac281 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_sdram_edge_placement.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_sdram_edge_placement.py @@ -16,7 +16,7 @@ import random import unittest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import ( MachineGraph, SDRAMMachineEdge) from pacman.model.graphs.machine import ConstantSDRAMMachinePartition @@ -29,7 +29,7 @@ class TestSameChipConstraint(unittest.TestCase): def setUp(cls): - reset_configs() + unittest_setup() def _do_test(self, placer): machine = virtual_machine(width=8, height=8) diff --git a/unittests/operations_tests/placer_algorithms_tests/test_spreader_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_spreader_placer.py index fd453068a..7c0415adf 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_spreader_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_spreader_placer.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import pytest from spinn_machine.virtual_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanException from pacman.model.graphs.machine import ( MachineGraph, SimpleMachineVertex, MachineSpiNNakerLinkVertex, @@ -32,7 +32,7 @@ def test_virtual_vertices_spreader(): """ Test that the placer works with a virtual vertex """ - reset_configs() + unittest_setup() # Create a graph with a virtual vertex machine_graph = MachineGraph("Test") @@ -92,7 +92,7 @@ def test_virtual_vertices_spreader(): def test_one_to_one(): """ Test normal 1-1 placement """ - reset_configs() + unittest_setup() # Create a graph machine_graph = MachineGraph("Test") @@ -160,7 +160,7 @@ def test_one_to_one(): def test_sdram_links(): """ Test sdram edges which should explode """ - reset_configs() + unittest_setup() # Create a graph machine_graph = MachineGraph("Test") diff --git a/unittests/operations_tests/placer_algorithms_tests/test_virtual_placement.py b/unittests/operations_tests/placer_algorithms_tests/test_virtual_placement.py index c9e3b920c..b07ed8d1e 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_virtual_placement.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_virtual_placement.py @@ -15,7 +15,7 @@ import pytest from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import ( MachineGraph, MachineSpiNNakerLinkVertex) from pacman.operations.chip_id_allocator_algorithms import ( @@ -28,7 +28,7 @@ "placer", ["OneToOnePlacer", "RadialPlacer", "SpreaderPlacer"]) def test_virtual_placement(placer): - reset_configs() + unittest_setup() machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex(spinnaker_link_id=0) diff --git a/unittests/operations_tests/router_algorithms_tests/test_basic_dijkstra_routing.py b/unittests/operations_tests/router_algorithms_tests/test_basic_dijkstra_routing.py index 243f9f0b1..6afbb42ae 100644 --- a/unittests/operations_tests/router_algorithms_tests/test_basic_dijkstra_routing.py +++ b/unittests/operations_tests/router_algorithms_tests/test_basic_dijkstra_routing.py @@ -16,7 +16,7 @@ import unittest from collections import deque -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import MulticastEdgePartition from spinn_machine.virtual_machine import virtual_machine from pacman.model.graphs.machine import ( @@ -29,7 +29,7 @@ class TestBasicDijkstraRouting(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def test_routing(self): graph = MachineGraph("Test") diff --git a/unittests/operations_tests/router_algorithms_tests/test_ner_route_default.py b/unittests/operations_tests/router_algorithms_tests/test_ner_route_default.py index 2d9e25d18..47570c9a1 100644 --- a/unittests/operations_tests/router_algorithms_tests/test_ner_route_default.py +++ b/unittests/operations_tests/router_algorithms_tests/test_ner_route_default.py @@ -12,7 +12,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import ( MachineGraph, MachineEdge, SimpleMachineVertex) from spinn_machine import virtual_machine @@ -21,7 +21,7 @@ def test_ner_route_default(): - reset_configs() + unittest_setup() graph = MachineGraph("Test") machine = virtual_machine(8, 8) placements = Placements() diff --git a/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py b/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py index 6cfa3a8fe..039e722ab 100644 --- a/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py +++ b/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py @@ -18,7 +18,7 @@ from spinn_utilities.config_holder import load_config, set_config from spinn_machine.virtual_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import ( MachineGraph, MachineEdge, MulticastEdgePartition, SimpleMachineVertex) from pacman.operations.router_algorithms import NerRouteTrafficAware @@ -29,11 +29,7 @@ class TestNerRouteTrafficAware(unittest.TestCase): def setUp(cls): - reset_configs() - load_config() - - def tearDown(self): - reset_configs() + unittest_setup() def test_routing(self): graph = MachineGraph("Test") diff --git a/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py index 499828d51..7534da431 100644 --- a/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py @@ -17,7 +17,7 @@ import sys import unittest -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) @@ -28,7 +28,7 @@ class TestUnorderedPairCompressor(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def test_onordered_pair_big(self): class_file = sys.modules[self.__module__].__file__ diff --git a/unittests/operations_tests/router_compressor_tests/test_compressors.py b/unittests/operations_tests/router_compressor_tests/test_compressors.py index 9e7abb5fe..17bbaf081 100644 --- a/unittests/operations_tests/router_compressor_tests/test_compressors.py +++ b/unittests/operations_tests/router_compressor_tests/test_compressors.py @@ -16,7 +16,7 @@ import unittest from spinn_utilities.config_holder import set_config, load_config from spinn_machine import MulticastRoutingEntry -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.routing_tables import ( UnCompressedMulticastRoutingTable, MulticastRoutingTables) from pacman.operations.router_compressors.routing_compression_checker import ( @@ -53,14 +53,10 @@ def setUp(self): original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b0010, 0b1011, [4, 5], [], False)) self.original_tables.add_routing_table(original_table) - reset_configs() - load_config() + unittest_setup() set_config( "Mapping", "router_table_compression_target_length", "None") - def tearDown(self): - load_config() - def check_compression(self, compressed_tables): for original in self.original_tables: compressed = compressed_tables.get_routing_table_for_chip( diff --git a/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py b/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py index 6d680c7ef..ef8b6bf3b 100644 --- a/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py @@ -17,7 +17,7 @@ import sys import unittest -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) @@ -28,7 +28,7 @@ class TestOrderedCoveringCompressor(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def test_oc_big(self): class_file = sys.modules[self.__module__].__file__ diff --git a/unittests/operations_tests/router_compressor_tests/test_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_pair_compression.py index 484921a97..81976c8a7 100644 --- a/unittests/operations_tests/router_compressor_tests/test_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_pair_compression.py @@ -17,7 +17,7 @@ import sys import unittest -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) @@ -27,7 +27,7 @@ class TestPairCompressor(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def test_pair_big(self): class_file = sys.modules[self.__module__].__file__ diff --git a/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py index 691fbf76f..d329b4570 100644 --- a/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py @@ -17,7 +17,7 @@ import sys import unittest -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) @@ -28,7 +28,7 @@ class TestUnorderedPairCompressor(unittest.TestCase): def setUp(self): - reset_configs() + unittest_setup() def test_onordered_pair_big(self): class_file = sys.modules[self.__module__].__file__ diff --git a/unittests/operations_tests/routing_info_algorithms_tests/test_malloc_routing_info_allocator.py b/unittests/operations_tests/routing_info_algorithms_tests/test_malloc_routing_info_allocator.py index 624e9a0c9..8da085199 100644 --- a/unittests/operations_tests/routing_info_algorithms_tests/test_malloc_routing_info_allocator.py +++ b/unittests/operations_tests/routing_info_algorithms_tests/test_malloc_routing_info_allocator.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.exceptions import PacmanRouteInfoAllocationException from pacman.model.constraints.key_allocator_constraints import ( FixedKeyAndMaskConstraint, ShareKeyConstraint) @@ -30,6 +31,9 @@ class MyTestCase(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_allocate_fixed_key_and_mask(self): allocator = MallocBasedRoutingInfoAllocator() allocator._allocate_fixed_keys_and_masks( diff --git a/unittests/operations_tests/routing_info_algorithms_tests/test_mask_generator.py b/unittests/operations_tests/routing_info_algorithms_tests/test_mask_generator.py index 59ac3ac37..1e4e247d4 100644 --- a/unittests/operations_tests/routing_info_algorithms_tests/test_mask_generator.py +++ b/unittests/operations_tests/routing_info_algorithms_tests/test_mask_generator.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import pytest +from pacman.config_setup import unittest_setup from pacman.operations.routing_info_allocator_algorithms.\ malloc_based_routing_allocator.utils import ( get_possible_masks) @@ -22,6 +23,7 @@ def test_mask_generator(): """ This checks behaviour, but with restricted bitfield sizes. """ + unittest_setup() assert frozenset(get_possible_masks(2, 4, False)) == frozenset( {14, 13, 11, 7}) assert frozenset(get_possible_masks(2, 4, True)) == frozenset( diff --git a/unittests/operations_tests/routing_info_algorithms_tests/test_zoned_routing_allocator.py b/unittests/operations_tests/routing_info_algorithms_tests/test_zoned_routing_allocator.py index f00b489ad..1eb2f8aba 100644 --- a/unittests/operations_tests/routing_info_algorithms_tests/test_zoned_routing_allocator.py +++ b/unittests/operations_tests/routing_info_algorithms_tests/test_zoned_routing_allocator.py @@ -12,6 +12,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from pacman.config_setup import unittest_setup from pacman.operations.routing_info_allocator_algorithms.\ zoned_routing_info_allocator import (flexible_allocate, global_allocate) from pacman.model.graphs.application.application_graph import ApplicationGraph @@ -223,8 +224,9 @@ def check_keys_for_application_partition_pairs( def test_global_allocator(): - # Allocate something and check it does the right thing + unittest_setup() + # Allocate something and check it does the right thing app_graph, mac_graph, n_keys_map = create_graphs1(False) # The number of bits is 7 + 5 + 8 = 20, so it shouldn't fail @@ -241,6 +243,8 @@ def test_global_allocator(): def test_flexible_allocator_no_fixed(): + unittest_setup() + # Allocate something and check it does the right thing app_graph, mac_graph, n_keys_map = create_graphs1(False) @@ -254,6 +258,7 @@ def test_flexible_allocator_no_fixed(): def test_fixed_only(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_graphs_only_fixed() flexible_allocate(mac_graph, n_keys_map) routing_info = global_allocate(mac_graph, n_keys_map) @@ -261,6 +266,7 @@ def test_fixed_only(): def test_no_edge(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_graphs_no_edge() flexible_allocate(mac_graph, n_keys_map) routing_info = global_allocate(mac_graph, n_keys_map) @@ -268,6 +274,7 @@ def test_no_edge(): def test_flexible_allocator_with_fixed(): + unittest_setup() # Allocate something and check it does the right thing app_graph, mac_graph, n_keys_map = create_graphs1(True) @@ -329,6 +336,7 @@ def create_big(with_fixed): def test_big_flexible_no_fixed(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_big(False) # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail @@ -342,6 +350,7 @@ def test_big_flexible_no_fixed(): def test_big_global_no_fixed(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_big(False) # Make the call, and it should fail routing_info = global_allocate(mac_graph, n_keys_map) @@ -360,6 +369,7 @@ def test_big_global_no_fixed(): def test_big_flexible_fixed(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_big(True) # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail @@ -372,6 +382,7 @@ def test_big_flexible_fixed(): def test_big_global_fixed(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_big(True) # Make the call, and it should fail routing_info = global_allocate(mac_graph, n_keys_map) @@ -390,6 +401,7 @@ def test_big_global_fixed(): def test_no_app_level_flexible(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_app_less() # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail routing_info = flexible_allocate(mac_graph, n_keys_map) @@ -401,6 +413,7 @@ def test_no_app_level_flexible(): def test_no_app_level_global(): + unittest_setup() app_graph, mac_graph, n_keys_map = create_app_less() # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail routing_info = global_allocate(mac_graph, n_keys_map) diff --git a/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py b/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py index b5926b0a6..7fd835ffd 100644 --- a/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py +++ b/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py @@ -16,7 +16,7 @@ import unittest from collections import defaultdict from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.placements import Placement, Placements from pacman.model.graphs.machine import SimpleMachineVertex from pacman.model.resources import ResourceContainer, IPtagResource @@ -27,7 +27,7 @@ class TestTagsBoardAddresses(unittest.TestCase): """ Tests for ip tags on different boards """ def setUp(self): - reset_configs() + unittest_setup() def test_ip_tags(self): machine = virtual_machine(12, 12) diff --git a/unittests/test_cfg_checker.py b/unittests/test_cfg_checker.py index 35d24f06f..33abb76de 100644 --- a/unittests/test_cfg_checker.py +++ b/unittests/test_cfg_checker.py @@ -16,14 +16,14 @@ import os import unittest from spinn_utilities.config_holder import run_config_checks -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup class TestCfgChecker(unittest.TestCase): @classmethod def setUpClass(cls): - reset_configs() + unittest_setup() def test_cfg_check(self): unittests = os.path.dirname(__file__) diff --git a/unittests/test_fixed_route_router.py b/unittests/test_fixed_route_router.py index c845d6de9..f13356e28 100644 --- a/unittests/test_fixed_route_router.py +++ b/unittests/test_fixed_route_router.py @@ -16,7 +16,7 @@ import pytest from spinn_utilities.config_holder import load_config, set_config from spinn_machine import virtual_machine -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.placements import Placements, Placement from pacman.operations.fixed_route_router import FixedRouteRouter from pacman.exceptions import PacmanRoutingException @@ -79,8 +79,7 @@ def _check_setup(width, height): (False, True), (True, True)]) def test_all_working(width, height, with_down_links, with_down_chips): - reset_configs() - load_config() + unittest_setup() temp_machine = virtual_machine(width=width, height=height) down_links = None if with_down_links: @@ -101,7 +100,7 @@ def test_all_working(width, height, with_down_links, with_down_chips): def test_unreachable(): - reset_configs() + unittest_setup() load_config() set_config("Machine", "down_chips", "0,2:1,3:1,4") with pytest.raises(PacmanRoutingException): diff --git a/unittests/test_import_all.py b/unittests/test_import_all.py index bcd58dc4b..7cdce7824 100644 --- a/unittests/test_import_all.py +++ b/unittests/test_import_all.py @@ -16,10 +16,14 @@ import os import unittest import spinn_utilities.package_loader as package_loader +from pacman.config_setup import unittest_setup class ImportAllModule(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_import_all(self): if os.environ.get('CONTINUOUS_INTEGRATION', 'false').lower() == 'true': package_loader.load_module("pacman", remove_pyc_files=False) diff --git a/unittests/test_pacman_algorithm_executor.py b/unittests/test_pacman_algorithm_executor.py index cd43aa1be..24ecbe1e1 100644 --- a/unittests/test_pacman_algorithm_executor.py +++ b/unittests/test_pacman_algorithm_executor.py @@ -16,7 +16,7 @@ import os import tempfile import unittest -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.executor import PACMANAlgorithmExecutor from pacman.executor.algorithm_decorators import algorithm, Token from pacman.exceptions import ( @@ -128,9 +128,8 @@ def exception_when_called(): class Test(unittest.TestCase): - @classmethod - def setUpClass(cls): - reset_configs() + def setUp(self): + unittest_setup() def test_basic_workflow(self): """ Test the basic operation of the executor diff --git a/unittests/test_token_states.py b/unittests/test_token_states.py index 7bb48d6f9..f6603ab2e 100644 --- a/unittests/test_token_states.py +++ b/unittests/test_token_states.py @@ -14,12 +14,16 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.executor.algorithm_decorators import Token from pacman.executor.token_states import TokenStates class TestTokenStates(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_union(self): token1 = Token("One") token2 = Token("Two") diff --git a/unittests/test_version.py b/unittests/test_version.py index 0b2f89b5b..bc1c1d239 100644 --- a/unittests/test_version.py +++ b/unittests/test_version.py @@ -17,12 +17,16 @@ import spinn_utilities import spinn_machine import pacman +from pacman.config_setup import unittest_setup class Test(unittest.TestCase): """ Tests for the SCAMP version comparison """ + def setUp(self): + unittest_setup() + def test_compare_versions(self): spinn_utilities_parts = spinn_utilities.__version__.split('.') spinn_machine_parts = spinn_machine.__version__.split('.') diff --git a/unittests/utilities_tests/test_constants.py b/unittests/utilities_tests/test_constants.py index 335cb4135..8ec6086cd 100644 --- a/unittests/utilities_tests/test_constants.py +++ b/unittests/utilities_tests/test_constants.py @@ -14,11 +14,15 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.utilities import constants class TestConstants(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_edges_enum(self): self.assertEqual(constants.EDGES.EAST.value, 0) self.assertEqual(constants.EDGES.NORTH_EAST.value, 1) diff --git a/unittests/utilities_tests/test_json_utils.py b/unittests/utilities_tests/test_json_utils.py index dad3814eb..aced24bcd 100644 --- a/unittests/utilities_tests/test_json_utils.py +++ b/unittests/utilities_tests/test_json_utils.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import unittest import json +from pacman.config_setup import unittest_setup from pacman.model.constraints.key_allocator_constraints import ( ContiguousKeyRangeContraint, FixedKeyAndMaskConstraint, FixedMaskConstraint) @@ -46,6 +47,9 @@ class TestJsonUtils(unittest.TestCase): # Basic graph comparators # ------------------------------------------------------------------ + def setUp(self): + unittest_setup() + def _compare_constraint(self, c1, c2, seen=None): if seen is None: seen = [] diff --git a/unittests/utilities_tests/test_placer_algorithm_utilities.py b/unittests/utilities_tests/test_placer_algorithm_utilities.py index 0dffadf8a..201a5519e 100644 --- a/unittests/utilities_tests/test_placer_algorithm_utilities.py +++ b/unittests/utilities_tests/test_placer_algorithm_utilities.py @@ -14,12 +14,16 @@ # along with this program. If not, see . import unittest +from pacman.config_setup import unittest_setup from pacman.utilities.algorithm_utilities.placer_algorithm_utilities import ( add_set) class TestUtilities(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_add_join(self): all_sets = list() all_sets.append({1, 2}) diff --git a/unittests/utilities_tests/test_resource_tracker.py b/unittests/utilities_tests/test_resource_tracker.py index 0bbc810dc..bf0f3d4df 100644 --- a/unittests/utilities_tests/test_resource_tracker.py +++ b/unittests/utilities_tests/test_resource_tracker.py @@ -16,7 +16,7 @@ import unittest from spinn_machine import ( virtual_machine, Chip, Router, SDRAM, machine_from_chips) -from pacman.config_setup import reset_configs +from pacman.config_setup import unittest_setup from pacman.model.resources import ( ResourceContainer, ConstantSDRAM, PreAllocatedResourceContainer, CoreResource, SpecificCoreResource) @@ -26,9 +26,8 @@ class TestResourceTracker(unittest.TestCase): - @classmethod - def setUpClass(cls): - reset_configs() + def setUp(self): + unittest_setup() def test_n_cores_available(self): machine = virtual_machine( From 774ed3fe331b0faab6518f0fd00a07718503bca0 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 9 Jun 2021 16:37:20 +0100 Subject: [PATCH 2/5] call unittest_setup in every test for simplisity --- pacman_integration_tests/test_big_compression.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pacman_integration_tests/test_big_compression.py b/pacman_integration_tests/test_big_compression.py index 6228d1a63..3140d29c6 100644 --- a/pacman_integration_tests/test_big_compression.py +++ b/pacman_integration_tests/test_big_compression.py @@ -18,6 +18,7 @@ import sys import unittest +from pacman.config_setup import unittest_setup from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) @@ -30,6 +31,9 @@ class TestBigCompression(unittest.TestCase): + def setUp(self): + unittest_setup() + def test_big(self): class_file = sys.modules[self.__module__].__file__ path = os.path.dirname(os.path.abspath(class_file)) From a545ff35bbf351fa85dce6c99f6be5a9620bb3a2 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 10 Jun 2021 06:39:40 +0100 Subject: [PATCH 3/5] remove extra import --- .../partition_algorithms_tests/test_basic_partitioner.py | 2 +- .../router_algorithms_tests/test_ner_route_traffic_aware.py | 2 +- .../router_compressor_tests/test_compressors.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py b/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py index 9d44ad107..23dfdb71a 100644 --- a/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py +++ b/unittests/operations_tests/partition_algorithms_tests/test_basic_partitioner.py @@ -19,7 +19,7 @@ import unittest -from spinn_utilities.config_holder import load_config, set_config +from spinn_utilities.config_holder import set_config from pacman.config_setup import unittest_setup from pacman.model.partitioner_splitters import SplitterSliceLegacy from pacman.operations.partition_algorithms import SplitterPartitioner diff --git a/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py b/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py index 039e722ab..d6952c0e0 100644 --- a/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py +++ b/unittests/operations_tests/router_algorithms_tests/test_ner_route_traffic_aware.py @@ -16,7 +16,7 @@ import unittest from collections import deque -from spinn_utilities.config_holder import load_config, set_config +from spinn_utilities.config_holder import set_config from spinn_machine.virtual_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.model.graphs.machine import ( diff --git a/unittests/operations_tests/router_compressor_tests/test_compressors.py b/unittests/operations_tests/router_compressor_tests/test_compressors.py index 17bbaf081..b6e0a19e2 100644 --- a/unittests/operations_tests/router_compressor_tests/test_compressors.py +++ b/unittests/operations_tests/router_compressor_tests/test_compressors.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import unittest -from spinn_utilities.config_holder import set_config, load_config +from spinn_utilities.config_holder import set_config from spinn_machine import MulticastRoutingEntry from pacman.config_setup import unittest_setup from pacman.model.routing_tables import ( From 9ca89c55070444803bf42536f5d7208353d5eba8 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 10 Jun 2021 12:32:27 +0100 Subject: [PATCH 4/5] direct load_config call no longer needed --- unittests/test_fixed_route_router.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittests/test_fixed_route_router.py b/unittests/test_fixed_route_router.py index f13356e28..a5b1cde7e 100644 --- a/unittests/test_fixed_route_router.py +++ b/unittests/test_fixed_route_router.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import pytest -from spinn_utilities.config_holder import load_config, set_config +from spinn_utilities.config_holder import set_config from spinn_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.model.placements import Placements, Placement @@ -101,7 +101,6 @@ def test_all_working(width, height, with_down_links, with_down_chips): def test_unreachable(): unittest_setup() - load_config() set_config("Machine", "down_chips", "0,2:1,3:1,4") with pytest.raises(PacmanRoutingException): _check_setup(8, 8) From b2b73ca1ee642c2f8d812c18735eb185bbbcf4b2 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 10 Jun 2021 13:58:37 +0100 Subject: [PATCH 5/5] no unittest_step for import all --- unittests/test_import_all.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/unittests/test_import_all.py b/unittests/test_import_all.py index 7cdce7824..615dede20 100644 --- a/unittests/test_import_all.py +++ b/unittests/test_import_all.py @@ -16,13 +16,11 @@ import os import unittest import spinn_utilities.package_loader as package_loader -from pacman.config_setup import unittest_setup class ImportAllModule(unittest.TestCase): - def setUp(self): - unittest_setup() + # no unittest_setup to check all imports work without it def test_import_all(self): if os.environ.get('CONTINUOUS_INTEGRATION', 'false').lower() == 'true':