Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Apr 12, 2024
1 parent e89fa3f commit f4030e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spinn_machine/version/version_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def version_factory() -> AbstractVersion:
if version is not None:
raise SpinnMachineException(
f"Both {version=} and {versions=} found in cfg")
vs = VersionStrings.from_String(versions)
vs = VersionStrings.from_string(versions)
options = vs.options
# Use the fact that we run actions against different python versions
minor = sys.version_info.minor
Expand Down
32 changes: 29 additions & 3 deletions spinn_machine/version/version_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,46 @@ def __str__(self):
return self.text

@property
def short_str(self):
def short_str(self) -> str:
"""
The text but in a shortened version
This makes the text lower case and removes some special characters
:rtype: str
"""
return self.shorten(self.text)

# this makes sure that the description is read-only
@property
def options(self) -> List[int]:
"""
The list of the versions covered by this string
This list can grow as new versions are added
:rtype: list(int)
"""
return self._versions

@classmethod
def shorten(cls, value):
def shorten(cls, value: str) -> str:
"""
Makes the String lower case and removes some special characters
:param str value:
:rtype: str
"""
return value.lower().replace("_", "").replace("-", "").replace(" ", "")

@classmethod
def from_String(cls, value):
def from_string(cls, value: str) -> "VersionStrings":
"""
Gets a VersionString object from a String
:param str value:
:rtype: VersionStrings
"""
value_short = cls.shorten(value)
for vs in cls:
if value_short == vs.short_str:
Expand Down
6 changes: 3 additions & 3 deletions unittests/version/test_version_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def setUp(self):
unittest_setup()

def test_names(self):
vs = VersionStrings.from_String("any")
vs = VersionStrings.from_string("any")
self.assertEqual(vs.text, "Any")
vs = VersionStrings.from_String("FourPlus")
vs = VersionStrings.from_string("FourPlus")
self.assertEqual(vs.text, "Four plus")
with self.assertRaises(SpinnMachineException):
vs = VersionStrings.from_String("Foo")
vs = VersionStrings.from_string("Foo")


if __name__ == '__main__':
Expand Down

0 comments on commit f4030e7

Please sign in to comment.