From 356750cf50db14dd90d9d22a1c08d4ac04801d2b Mon Sep 17 00:00:00 2001 From: John Stilley <1831479+john-science@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:02:40 -0700 Subject: [PATCH] Alphabetizing Flags.toString results (#1912) --- armi/reactor/flags.py | 3 ++- armi/reactor/tests/test_flags.py | 8 ++++++++ doc/release/0.4.rst | 13 +++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/armi/reactor/flags.py b/armi/reactor/flags.py index 14bcff7e8..3386772f9 100644 --- a/armi/reactor/flags.py +++ b/armi/reactor/flags.py @@ -185,7 +185,8 @@ def _toString(cls, typeSpec): ----- This converts a flag from ``Flags.A|B`` to ``'A B'`` """ - return str(typeSpec).split("{}.".format(cls.__name__))[1].replace("|", " ") + strings = str(typeSpec).split("{}.".format(cls.__name__))[1] + return " ".join(sorted(strings.split("|"))) class Flags(Flag): diff --git a/armi/reactor/tests/test_flags.py b/armi/reactor/tests/test_flags.py index bbc4c1cb8..7155cae95 100644 --- a/armi/reactor/tests/test_flags.py +++ b/armi/reactor/tests/test_flags.py @@ -38,6 +38,14 @@ def test_flagsToAndFromString(self): self.assertEqual(flags.Flags.toString(f), "FUEL") self.assertEqual(f, flags.Flags.fromString("FUEL")) + def test_toStringAlphabetical(self): + """Ensure that, for multiple flags, toString() returns them in alphabetical order.""" + flagz = flags.Flags.AXIAL | flags.Flags.LOWER + self.assertEqual(flags.Flags.toString(flagz), "AXIAL LOWER") + + flagz = flags.Flags.LOWER | flags.Flags.AXIAL + self.assertEqual(flags.Flags.toString(flagz), "AXIAL LOWER") + def test_fromStringStrict(self): self._help_fromString(flags.Flags.fromString) with self.assertRaises(flags.InvalidFlagsError): diff --git a/doc/release/0.4.rst b/doc/release/0.4.rst index 45f7dba34..cda3e8ffd 100644 --- a/doc/release/0.4.rst +++ b/doc/release/0.4.rst @@ -14,17 +14,15 @@ New Features #. Allow merging a component with zero area into another component (`PR#1858 `_) #. Provide utilities for determining location of a rotated object in a hexagonal lattice (``getIndexOfRotatedCell``). (`PR#1846 `_) -#. Provide ``Parameter.hasCategory`` for quickly checking if a parameter is defined with a given category. - (`PR#1899 `_) -#. Provide ``ParameterCollection.where`` for efficient iteration over parameters who's definition. - matches a given condition. (`PR#1899 `_) -#. Plugins can provide the ``getAxialExpansionChanger`` hook to customize axial expansion. - (`PR#1870 `_) +#. Provide ``ParameterCollection.where`` for efficient iteration over parameters who's definition matches a given condition. (`PR#1899 `_) +#. Plugins can provide the ``getAxialExpansionChanger`` hook to customize axial expansion. (`PR#1870 `_) +#. Alphabetizing ``Flags.toString()`` results. (`PR#1912 `_) #. Moving ``settingsValidation`` from ``operators`` to ``settings``. (`PR#1895 `_) #. Removing deprecated method ``prepSearch``. (`PR#1845 `_) #. Removing unused function ``SkippingXsGen_BuChangedLessThanTolerance``. (`PR#1845 `_) @@ -42,8 +40,7 @@ Bug Fixes #. Changed data type of ``thKernel`` setting from ``bool`` to ``str`` in ``ThermalHydraulicsPlugin``. (`PR#1855 `_) #. Rotate hexagonal assembly patches correctly on facemap plots. (`PR#1883 `_) #. Update height of fluid components after axial expansion (`PR#1828 `_) -#. Material theoretical density is serialized to and read from database. - (`PR#1852 `_) +#. Material theoretical density is serialized to and read from database. (`PR#1852 `_) #. TBD Quality Work