From 4a17c2a9245fd43dff7312ed44d01d0ff38e1c60 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 12 Apr 2024 14:13:28 +0100 Subject: [PATCH] VersionStrings --- spinn_machine/spinn_machine.cfg | 2 + spinn_machine/version/__init__.py | 8 +-- spinn_machine/version/version_factory.py | 17 +++--- spinn_machine/version/version_strings.py | 68 ++++++++++++++++++++++++ unittests/data/test_data.py | 20 +++---- unittests/test_chip.py | 4 +- unittests/test_json_machine.py | 12 ++--- unittests/test_machine.py | 43 ++++++++------- unittests/test_using_virtual_machine.py | 37 +++++++------ unittests/version/test_version201.py | 5 +- unittests/version/test_version3.py | 5 +- unittests/version/test_version5.py | 5 +- unittests/version/test_version_string.py | 39 ++++++++++++++ 13 files changed, 182 insertions(+), 83 deletions(-) create mode 100644 spinn_machine/version/version_strings.py create mode 100644 unittests/version/test_version_string.py diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index 8a0a6f60..5cc2cee1 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -2,6 +2,8 @@ [Machine] version = None +# Used Instead of version if multiple versions should be tested! +versions = None width = None height = None # Note: if json_path is set all other configs for virtual boards are ignored diff --git a/spinn_machine/version/__init__.py b/spinn_machine/version/__init__.py index 15f8c69b..83b00d3e 100644 --- a/spinn_machine/version/__init__.py +++ b/spinn_machine/version/__init__.py @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .version_factory import ( - ANY_VERSION, BIG_MACHINE, FIVE, FOUR_PLUS_CHIPS, MULTIPLE_BOARDS, - SPIN2_1CHIP, THREE, version_factory, WRAPPABLE) +from .version_factory import FIVE, SPIN2_1CHIP, THREE, version_factory -__all__ = ["ANY_VERSION", "BIG_MACHINE", "FIVE", "FOUR_PLUS_CHIPS", - "MULTIPLE_BOARDS", "SPIN2_1CHIP", "THREE", "version_factory", - "WRAPPABLE"] +__all__ = ["FIVE", "SPIN2_1CHIP", "THREE", "version_factory"] diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index bdce5c66..e297a8dd 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -20,6 +20,7 @@ get_config_int_or_none, get_config_str_or_none) from spinn_utilities.log import FormatAdapter from spinn_machine.exceptions import SpinnMachineException +from .version_strings import VersionStrings if TYPE_CHECKING: from .abstract_version import AbstractVersion @@ -62,17 +63,13 @@ def version_factory() -> AbstractVersion: from .version_201 import Version201 version = get_config_int_or_none("Machine", "version") - - if version is not None and version < 0: - if version == ANY_VERSION: - options = [THREE, FIVE, SPIN2_1CHIP] - elif version == FOUR_PLUS_CHIPS: - options = [THREE] - elif version in [BIG_MACHINE, MULTIPLE_BOARDS, WRAPPABLE]: - options = [FIVE] - else: + versions = get_config_str_or_none("Machine", "versions") + if versions is not None: + if version is not None: raise SpinnMachineException( - f"Unexpected cfg [Machine]version {version}") + f"Both {version=} and {versions=} found in cfg") + vs = VersionStrings.from_String(versions) + options = vs.options # Use the fact that we run actions against different python versions minor = sys.version_info.minor version = options[minor % len(options)] diff --git a/spinn_machine/version/version_strings.py b/spinn_machine/version/version_strings.py new file mode 100644 index 00000000..a8e16d1c --- /dev/null +++ b/spinn_machine/version/version_strings.py @@ -0,0 +1,68 @@ +# Copyright (c) 2024 The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from enum import StrEnum +from typing import List +from spinn_machine.exceptions import SpinnMachineException + + +class VersionStrings(StrEnum): + """ + A description of strings in cfg settings to say test versions + + As additional Versions are added this should allow easy testing of these + as far as possible. + """ + + ANY = ("Any", [3, 5, 201]) + FOUR_PLUS = ("Four plus", [3, 5]) + # To test stuff with more than four chips. + BIG = ("Big", [5]) + # Specifically to test stuff over multiple boards + MULTIPLE_BOARDS = ("Multiple boards", [5]) + # Specifically to test the various wrapping Machine classes + WRAPPABLE = ("Wrappable", [5]) + + def __new__(cls, *args, **kwds): + s = str.__new__(cls) + s._value_ = args[0] + return s + + # ignore the first param since it's already set by __new__ + def __init__(self, _: str, versions: List[int]): + self._versions = versions + + def __str__(self): + return self.value + + @property + def short_str(self): + return self.shorten(self.value) + + # this makes sure that the description is read-only + @property + def options(self) -> List[int]: + return self._versions + + @classmethod + def shorten(cls, value): + return value.lower().replace("_", "").replace("-", "").replace(" ", "") + + @classmethod + def from_String(cls, value): + value_short = cls.shorten(value) + for vs in cls: + if value_short == vs.short_str: + return vs + raise SpinnMachineException(f"No version for {value=}") diff --git a/unittests/data/test_data.py b/unittests/data/test_data.py index 807800d5..a20cb737 100644 --- a/unittests/data/test_data.py +++ b/unittests/data/test_data.py @@ -19,14 +19,14 @@ from spinn_machine.config_setup import unittest_setup from spinn_machine.data import MachineDataView from spinn_machine.data.machine_data_writer import MachineDataWriter -from spinn_machine.version import ANY_VERSION, FOUR_PLUS_CHIPS +from spinn_machine.version import FIVE, THREE +from spinn_machine.version.version_strings import VersionStrings class TestSimulatorData(unittest.TestCase): def setUp(self): unittest_setup() - set_config("Machine", "version", 5) def test_setup(self): # What happens before setup depends on the previous test @@ -38,12 +38,12 @@ def test_setup(self): MachineDataView.get_chip_at(1, 1) def test_mock(self): - MachineDataWriter.mock() + set_config("Machine", "version", FIVE) self.assertEqual(3, MachineDataView.get_chip_at(3, 5).x) self.assertEqual(48, MachineDataView.get_machine().n_chips) def test_machine(self): - set_config("Machine", "version", 3) + set_config("Machine", "version", THREE) writer = MachineDataWriter.setup() with self.assertRaises(DataNotYetAvialable): @@ -59,6 +59,7 @@ def test_machine(self): self.assertTrue(MachineDataView.has_machine()) def test_where_is_mocked(self): + set_config("Machine", "versions", VersionStrings.MULTIPLE_BOARDS.value) writer = MachineDataWriter.mock() self.assertEqual( "No Machine created yet", @@ -76,6 +77,7 @@ def test_where_is_mocked(self): MachineDataView.where_is_chip(machine.get_chip_at(2, 8))) def test_where_is_setup(self): + set_config("Machine", "versions", VersionStrings.MULTIPLE_BOARDS.value) writer = MachineDataWriter.setup() self.assertEqual( "No Machine created yet", @@ -98,24 +100,24 @@ def test_where_is_setup(self): def test_mock_any(self): # Should work with any version - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) # check there is a value not what it is machine = MachineDataView.get_machine() self.assertGreaterEqual(machine.n_chips, 1) def test_mock_4_or_more(self): # Should work with any version - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) # check there is a value not what it is machine = MachineDataView.get_machine() self.assertGreaterEqual(machine.n_chips, 4) - def test_mockAny(self): + def test_mock_big(self): # Should work with any version - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.BIG.value) # check there is a value not what it is machine = MachineDataView.get_machine() - self.assertGreaterEqual(machine.n_chips, 1) + self.assertGreaterEqual(machine.n_chips, 48) def test_mock3(self): # Should work with any version diff --git a/unittests/test_chip.py b/unittests/test_chip.py index 0d0fac6f..dd309865 100644 --- a/unittests/test_chip.py +++ b/unittests/test_chip.py @@ -17,14 +17,14 @@ from spinn_utilities.ordered_set import OrderedSet from spinn_machine import Link, Router, Chip from spinn_machine.config_setup import unittest_setup -from spinn_machine.version import ANY_VERSION +from spinn_machine.version.version_strings import VersionStrings class TestingChip(unittest.TestCase): def setUp(self): unittest_setup() - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) self._x = 0 self._y = 1 diff --git a/unittests/test_json_machine.py b/unittests/test_json_machine.py index 370f3510..93f1a036 100644 --- a/unittests/test_json_machine.py +++ b/unittests/test_json_machine.py @@ -20,8 +20,8 @@ from spinn_machine.data.machine_data_writer import MachineDataWriter from spinn_machine.config_setup import unittest_setup from spinn_machine.json_machine import (machine_from_json, to_json_path) -from spinn_machine.version import ( - BIG_MACHINE, FOUR_PLUS_CHIPS, FIVE, MULTIPLE_BOARDS, SPIN2_1CHIP, THREE) +from spinn_machine.version import (FIVE, SPIN2_1CHIP, THREE) +from spinn_machine.version.version_strings import VersionStrings class TestJsonMachine(unittest.TestCase): @@ -69,7 +69,7 @@ def test_json_version_201(self): self.assertEqual(str(vchip), str(jchip)) def test_json_hole(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) set_config("Machine", "down_chips", "3,3") writer = MachineDataWriter.mock() vm = virtual_machine_by_min_size(5, 5) @@ -84,7 +84,7 @@ def test_json_hole(self): self.assertEqual(str(vchip), str(jchip)) def test_exceptions(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) writer = MachineDataWriter.mock() vm = virtual_machine_by_boards(1) writer.set_machine(vm) @@ -104,7 +104,7 @@ def test_exceptions(self): self.assertEqual(vchip10.tag_ids, chip10.tag_ids) def test_monitor_exceptions(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) vm = virtual_machine_by_boards(1) MachineDataWriter.mock().set_machine(vm) for chip in vm.chips: @@ -121,7 +121,7 @@ def test_monitor_exceptions(self): machine_from_json(jpath) def test_ethernet_exceptions(self): - set_config("Machine", "version", MULTIPLE_BOARDS) + set_config("Machine", "versions", VersionStrings.MULTIPLE_BOARDS.value) vm = virtual_machine_by_boards(2) MachineDataWriter.mock().set_machine(vm) eth2 = vm.ethernet_connected_chips[1] diff --git a/unittests/test_machine.py b/unittests/test_machine.py index 09998bd4..f8422c46 100644 --- a/unittests/test_machine.py +++ b/unittests/test_machine.py @@ -20,9 +20,8 @@ from spinn_utilities.config_holder import set_config from spinn_utilities.testing import log_checker from spinn_machine import Link, Router, Chip -from spinn_machine.version import ( - ANY_VERSION, BIG_MACHINE, FIVE, FOUR_PLUS_CHIPS, MULTIPLE_BOARDS, - WRAPPABLE) +from spinn_machine.version import FIVE +from spinn_machine.version.version_strings import VersionStrings from spinn_machine.virtual_machine import ( virtual_machine_by_boards, virtual_machine_by_min_size) from spinn_machine.config_setup import unittest_setup @@ -151,7 +150,7 @@ def test_chip_already_exists(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) machine = virtual_machine_by_boards(1) with self.assertRaises(SpinnMachineAlreadyExistsException): machine.add_chip(Chip( @@ -165,7 +164,7 @@ def test_machine_get_chip_at(self): :rtype: None """ - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) new_machine = virtual_machine_by_min_size(2, 2) self.assertEqual(1, new_machine.get_chip_at(1, 0).x) self.assertEqual(0, new_machine.get_chip_at(1, 0).y) @@ -179,7 +178,7 @@ def test_machine_big_x(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -200,7 +199,7 @@ def test_machine_big_y(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -221,7 +220,7 @@ def test_machine_get_chip_at_invalid_location(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape @@ -234,7 +233,7 @@ def test_machine_is_chip_at_true(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape @@ -247,14 +246,14 @@ def test_machine_is_chip_at_false(self): :rtype: None """ - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape self.assertFalse(new_machine.is_chip_at(width + 2, height // 2)) def test_machine_get_chips_on_board(self): - set_config("Machine", "version", MULTIPLE_BOARDS) + set_config("Machine", "versions", VersionStrings.MULTIPLE_BOARDS.value) new_machine = virtual_machine_by_boards(3) version = MachineDataView.get_machine_version() for eth_chip in new_machine._ethernet_connected_chips: @@ -274,7 +273,7 @@ def test_x_y_over_link(self): Notice that the function only does the math not validate the values. :return: """ - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) # full wrap around machine = MachineDataView.get_machine_version().create_machine(24, 24) self.assertEqual(machine.xy_over_link(0, 0, 4), (23, 23)) @@ -303,7 +302,7 @@ def test_get_global_xy(self): Notice that the function only does the math not validate the values. :return: """ - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) # full wrap around machine = MachineDataView.get_machine_version().create_machine(24, 24) self.assertEqual(machine.get_global_xy(1, 4, 4, 20), (5, 0)) @@ -322,7 +321,7 @@ def test_get_global_xy(self): self.assertEqual(machine.get_global_xy(5, 0, 20, 4), (25, 4)) def test_no_boot(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -331,7 +330,7 @@ def test_no_boot(self): machine.validate() def test_negative_x(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -342,7 +341,7 @@ def test_negative_x(self): machine.validate() def test_negative_y(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -359,14 +358,14 @@ def _non_ethernet_chip(self, machine): raise SpinnMachineException("No none Ethernet Chip") def test_weird_ethernet1(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) machine = virtual_machine_by_boards(1) self._non_ethernet_chip(machine)._ip_address = "1.2.3.4" with self.assertRaises(SpinnMachineException): machine.validate() def test_bad_ethernet_chip_x(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) machine = virtual_machine_by_boards(1) width, _ = MachineDataView.get_machine_version().board_shape self._non_ethernet_chip(machine)._nearest_ethernet_x = width + 1 @@ -374,7 +373,7 @@ def test_bad_ethernet_chip_x(self): machine.validate() def test_bad_ethernet_chip_no_chip(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) machine = virtual_machine_by_boards(1) _, height = MachineDataView.get_machine_version().board_shape self._non_ethernet_chip(machine)._nearest_ethernet_x = height + 1 @@ -382,7 +381,7 @@ def test_bad_ethernet_chip_no_chip(self): machine.validate() def test_concentric_xys(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) machine = virtual_machine_by_min_size(5, 5) found = list(machine.concentric_xys(2, (2, 2))) expected = [ @@ -393,10 +392,10 @@ def test_concentric_xys(self): self.assertListEqual(expected, found) def test_too_few_cores(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.ANY.value) machine = virtual_machine_by_boards(1) # Hack to get n_processors return a low number - chip = self._non_ethernet_chip(machine) + chip = next(machine.chips) chip._placable_processors = tuple([1, 2]) with self.assertRaises(SpinnMachineException): machine.validate() diff --git a/unittests/test_using_virtual_machine.py b/unittests/test_using_virtual_machine.py index b1d5c455..841ed4c2 100644 --- a/unittests/test_using_virtual_machine.py +++ b/unittests/test_using_virtual_machine.py @@ -22,8 +22,7 @@ from spinn_machine.exceptions import (SpinnMachineException) from spinn_machine.ignores import IgnoreChip, IgnoreCore, IgnoreLink from spinn_machine.machine_factory import machine_repair -from spinn_machine.version import ( - ANY_VERSION, BIG_MACHINE, FOUR_PLUS_CHIPS, WRAPPABLE) +from spinn_machine.version.version_strings import VersionStrings from spinn_machine.version.version_5 import CHIPS_PER_BOARD from .geometry import (to_xyz, shortest_mesh_path_length, shortest_torus_path_length, minimise_xyz) @@ -62,7 +61,7 @@ def _create_chip(self, x, y): nearest_ethernet_chip[1], None) def test_new_vm_with_max_cores(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) version = MachineDataView.get_machine_version() n_cpus = version.max_cores_per_chip - 5 set_config("Machine", "max_machine_core", n_cpus) @@ -81,7 +80,7 @@ def test_new_vm_with_max_cores(self): len(list(chip.scamp_processors_ids))) def test_iter_chips(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) vm = virtual_machine_by_boards(1) n_chips = MachineDataView.get_machine_version().n_chips_per_board self.assertEqual(n_chips, vm.n_chips) @@ -91,7 +90,7 @@ def test_iter_chips(self): self.assertEqual(n_chips, count) def test_down_chip(self): - set_config("Machine", "version", FOUR_PLUS_CHIPS) + set_config("Machine", "versions", VersionStrings.FOUR_PLUS.value) down_chips = set() down_chips.add((1, 1)) set_config("Machine", "down_chips", "1,1") @@ -110,7 +109,7 @@ def _check_path(self, source, target, path, width, height): self.assertEqual(target, new_target, "{}{}".format(source, path)) def test_nowrap_shortest_path(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) machine = virtual_machine(16, 28, validate=True) for source in machine.chip_coordinates: for target in machine.chip_coordinates: @@ -124,7 +123,7 @@ def test_nowrap_shortest_path(self): self._check_path(source, target, path, 1000000, 1000000) def test_fullwrap_shortest_path(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) width = 12 height = 24 machine = virtual_machine(width, height, validate=True) @@ -141,7 +140,7 @@ def test_fullwrap_shortest_path(self): self._check_path(source, target, path, width, height) def test_hoizontal_wrap_shortest_path(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) width = 12 height = 16 machine = virtual_machine(width, height, validate=False) @@ -166,7 +165,7 @@ def test_hoizontal_wrap_shortest_path(self): self._check_path(source, target, path, width, height) def test_vertical_wrap_shortest_path(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) width = 16 height = 12 machine = virtual_machine(width, height, validate=False) @@ -191,7 +190,7 @@ def test_vertical_wrap_shortest_path(self): self._check_path(source, target, path, width, height) def test_minimize(self): - set_config("Machine", "version", ANY_VERSION) + set_config("Machine", "versions", VersionStrings.ANY.value) machine = virtual_machine_by_boards(1) for x in range(-3, 3): for y in range(-3, 3): @@ -200,7 +199,7 @@ def test_minimize(self): self.assertEqual(min1, min2) def test_unreachable_incoming_chips(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) machine = virtual_machine_by_min_size(6, 6) # Delete links incoming to 3, 3 @@ -213,7 +212,7 @@ def test_unreachable_incoming_chips(self): self.assertListEqual([(3, 3)], unreachable) def test_unreachable_outgoing_chips(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) machine = virtual_machine_by_min_size(6, 6) # Delete links outgoing from 3, 3 @@ -224,7 +223,7 @@ def test_unreachable_outgoing_chips(self): self.assertListEqual([(3, 3)], unreachable) def test_unreachable_incoming_local_chips(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -234,7 +233,7 @@ def test_unreachable_incoming_local_chips(self): self.assertListEqual([(8, 7)], unreachable) def test_unreachable_outgoing_local_chips(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -244,7 +243,7 @@ def test_unreachable_outgoing_local_chips(self): self.assertListEqual([(8, 7)], unreachable) def test_repair_with_local_orphan(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -259,7 +258,7 @@ def test_repair_with_local_orphan(self): self.assertFalse(repaired.is_chip_at(8, 7)) def test_repair_with_one_way_links_different_boards(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) machine = virtual_machine(12, 12) # Assumes boards of exactly size 8,8 # Delete some links between boards @@ -275,7 +274,7 @@ def test_repair_with_one_way_links_different_boards(self): self.assertIsNotNone(new_machine) def test_oneway_link_no_repair(self): - set_config("Machine", "version", WRAPPABLE) + set_config("Machine", "versions", VersionStrings.WRAPPABLE.value) machine = virtual_machine(8, 8) # Delete some random links @@ -292,7 +291,7 @@ def test_oneway_link_no_repair(self): self.assertIsNotNone(new_machine) def test_removed_chip_repair(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) machine = virtual_machine_by_boards(1) del machine._chips[(3, 3)] @@ -302,7 +301,7 @@ def test_removed_chip_repair(self): self.assertFalse(new_machine.is_link_at(2, 2, 1)) def test_ignores(self): - set_config("Machine", "version", BIG_MACHINE) + set_config("Machine", "versions", VersionStrings.BIG.value) set_config("Machine", "down_chips", "2,2:4,4:6,6,ignored_ip") set_config("Machine", "down_cores", "1,1,1:3,3,3: 5,5,-5:7,7,7,ignored_ip:0,0,5-10") diff --git a/unittests/version/test_version201.py b/unittests/version/test_version201.py index b36734e8..c30f4638 100644 --- a/unittests/version/test_version201.py +++ b/unittests/version/test_version201.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 The University of Manchester +# Copyright (c) 2024 The University of Manchester # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,8 +24,7 @@ class TestVersion201(unittest.TestCase): - """ Tests of IPTag - """ + def setUp(self): unittest_setup() diff --git a/unittests/version/test_version3.py b/unittests/version/test_version3.py index 50a7f575..c837392e 100644 --- a/unittests/version/test_version3.py +++ b/unittests/version/test_version3.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 The University of Manchester +# Copyright (c) 2023 The University of Manchester # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,8 +24,7 @@ class TestVersion3(unittest.TestCase): - """ Tests of IPTag - """ + def setUp(self): unittest_setup() diff --git a/unittests/version/test_version5.py b/unittests/version/test_version5.py index 65195811..8faf84ac 100644 --- a/unittests/version/test_version5.py +++ b/unittests/version/test_version5.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 The University of Manchester +# Copyright (c) 2023 The University of Manchester # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ class TestVersion5(unittest.TestCase): - """ Tests of IPTag - """ + def setUp(self): unittest_setup() diff --git a/unittests/version/test_version_string.py b/unittests/version/test_version_string.py new file mode 100644 index 00000000..31510e88 --- /dev/null +++ b/unittests/version/test_version_string.py @@ -0,0 +1,39 @@ +# Copyright (c) 2024 The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Testing Versions +""" +import unittest +from spinn_machine.config_setup import unittest_setup +from spinn_machine.exceptions import SpinnMachineException +from spinn_machine.version.version_strings import VersionStrings + + +class TestVersionString(unittest.TestCase): + + def setUp(self): + unittest_setup() + + def test_names(self): + vs = VersionStrings.from_String("any") + self.assertEqual(vs.value, "Any") + vs = VersionStrings.from_String("FourPlus") + self.assertEqual(vs.value, "Four plus") + with self.assertRaises(SpinnMachineException): + vs = VersionStrings.from_String("Foo") + + +if __name__ == '__main__': + unittest.main()