armi.testing.symmetryTesting module
Testing utilities for symmetry.
Symmetry factor usage can be difficult to verify across multiple plugins, and plugins may write one-off fixes for situations involving the symmetry factor. The utilities provided here are an attempt to catch symmetry factor issues at the unit test level, rather than during integration tests.
The goal of this utility is to test symmetry intent, not functionality. This means individual implementations of symmetry-aware operations are still responsible for testing the implemetation. This module serves as a check that the parameters that are expected to change with symmetry do indeed change.
- This might be obvious, but this test CANNOT detect errors where the parameter is not either:
Labeled as a symmetry-aware parameter in the parameter definition.
Labeled as a symmetry-aware parameter in the test.
Failing to do at least one of the above will result in passing symmetry tests.
The tests here use the growToFullCore since that should be one of the most mature symmetry-aware operations.
This module provides the BasicArmiSymmetryTestHelper which is meant to be inherited into a downstream unit test. The test helper uses the SymmetryFactorTester to handle the bookkeeping tasks associated with testing symmetry.
- class armi.testing.symmetryTesting.BasicArmiSymmetryTestHelper(methodName='runTest')[source]
Bases:
TestCase
Customizable test runner for symmetry-intent audit.
This class is meant to be customized in a plugin to check the plugin-specific symmetry-aware parameters.
To use the test fixture, make a subclass test and assign the *ParamsToTest and expectedSymmetric* attributes in the setUp method of the subclass. The subclass must have super.setUp() in it’s setUp method at some point after the necessary plugin attributes are assigned.
- Variables:
coreParamsToTest (Iterable[str] | armi.reactor.parameters.parameterDefinitionCollection, optional) – Core parameters that should be initialized and tested.
assemblyParamsToTest (Iterable[str] | armi.reactor.parameters.parameterDefinitionCollection, optional) – Assembly parameters that should be initialized and tested.
blockParamsToTest (Iterable[str] | armi.reactor.parameters.parameterDefinitionCollection, optional) – Block parameters that should be initialized and tested.
expectedSymmetricCoreParams (Iterable[str], optional) – Core parameters that are expected to change with symmetry.
expectedSymmetricAssemblyParams (Iterable[str], optional) – Assembly parameters that are expected to change with symmetry.
expectedSymmetricBlockParams (Iterable[str], optional) – Block Parameters that are expected to change with symmetry.
parameterOverrides (dict[str: Any], optional) – Dictionary of specific values to assign to a particular parameter. Useful for parameters that have validators.
paramsToIgnore (Iterable[str], optional) – Parameter names to ignore the comparison results for.
customSettings (dict[str: Any]) – Dictionary of custom settings that is passed to the test reactor builder. Useful for disabling features that require additional input and are not useful for the symmetry audit.
Example
```python class MySymmetryTest(symmetryTesting.BasicArmiSymmetryTestHelper):
- def setUp():
# Tests are configured using attributes. Attributes must be set prior to calling super.setUp() # Note that it is not required to set any attributes, all have empty defaults
# Repeat for self.coreParamsToTest and self.assemblyParamsToTest as necessary: self.blockParamsToTest = [p if isinstance(p, str) else p.name for p in getPluginBlockParameterDefinitions()]
# Repeat for self.expectedSymmetricCoreParams and self.expectedSymmetricAssemblyParams as necessary: self.expectedSymmetricBlockParams = [“mySymmetricBlockParam1”, “mySymmetricBlockParam2”]
# Set specific parameter overrides if the parameters need a specific value (usually due to input validators) self.parameterOverrides = {“parameterName1”: value1, “parameterName2”: value2}
# Set specific parameters to ignore in comparison. self.paramsToIgnore = [“myIgnoredParameter”]
# Finish setting up the tests by calling the parent’s setUp method. super.setUp()
It should generally not be necessary for the plugin to implement any further unit tests, the parent class contains a test method that should adequately verify the the expected symmetric parameters are indeed expanded.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- coreParamsToTest = []
- assemblyParamsToTest = []
- blockParamsToTest = []
- expectedSymmetricCoreParams = []
- expectedSymmetricAssemblyParams = []
- expectedSymmetricBlockParams = []
- parameterOverrides = {}
- paramsToIgnore = []
- customSettings = {}
- class armi.testing.symmetryTesting.SymmetryFactorTester(armiSymmetryTester: BasicArmiSymmetryTestHelper)[source]
Bases:
object
A test runner for symmetry factors.
This class does the actual symmetry testing, but there is a lot of bookkeeping that isn’t important to expose in the test helper class so putting it here helps keep the BasicArmiSymmetryTestHelper clean.
- runSymmetryFactorTests(expectedCoreParams: Iterable[str] = [], expectedAssemblyParams: Iterable[str] = [], expectedBlockParams: Iterable[str] = [])[source]
Runs tests on how symmetry factors apply to parameters during partial-to-full core coversions and vice-versa.
This method provides a convenient way for plugins to test that symmetry factors are applied correctly to flagged parameters when the core is converted.
- Parameters:
testObject (unittest.TestCase) – The TestCase object is injected to give this fixture the ability to do unittest asserts without causing the fixture itself to be run as a unit test.
coreParams (Iterable[str], optional) – Dictionary of core parameters that the user expects to be symmetry aware.
assemblyParams (Iterable[str], optional) – Dictionary of assembly parameters that the user expects to be symmetry aware.
blockParams (Iterable[str], optional) – Dictionary of block parameters that the user expects to be symmetry aware.