armi.testing package
Importable testing utilities.
This is a very limited set of ARMI testing tools, meant to be importable as part of the ARMI API. The goal is to provide a small set of high quality tools to help downstream ARMI developers write tests.
Notes
This will not be a catch-all for random unit test functions. Be very sparing here.
- armi.testing.loadTestReactor(inputFilePath='/home/runner/work/armi/armi/armi/testing/reactors/sodiumHexReactor', customSettings=None, inputFileName='armiRun.yaml', useCache=True)[source]
Loads a test reactor. Can be used in other test modules.
- Parameters:
inputFilePath (str, default=armi/testing/reactors/sodiumHexReactor) – Path to the directory of the input file.
customSettings (dict with str keys and values of any type, default=None) – For each key in customSettings, the cs which is loaded from the armiRun.yaml will be overwritten to the value given in customSettings for that key.
inputFileName (str, default="armiRun.yaml") – Name of the input file to run.
useCache (bool, default=True) – Look for a copy of this Reactor in the cache, if not in the cache, put it there. (Set to False when you are sure there will only be one test using this test reactor.)
Notes
If the armiRun.yaml test reactor 3 rings instead of 9, most unit tests that use it go ~4 times faster. The problem is it would breat a LOT of downstream tests that import this method. It is still worth it though.
- Returns:
o (Operator)
r (Reactor)
- armi.testing.reduceTestReactorRings(r, cs, maxNumRings)[source]
Helper method for the test reactor above.
The goal is to reduce the size of the reactor for tests that don’t need such a large reactor, and would run much faster with a smaller one.
- armi.testing.getEmptyCartesianReactor(pitch=(10.0, 16.0), throughCenterAssembly=True)[source]
Return an empty Cartesian reactor for use in tests.
- armi.testing.buildOperatorOfEmptyHexBlocks(customSettings=None)[source]
Builds a operator w/ a reactor object with some hex assemblies and blocks, but all are empty.
Doesn’t depend on inputs and loads quickly.
- Parameters:
customSettings (dict) – Dictionary of off-default settings to update
- armi.testing.buildOperatorOfEmptyCartesianBlocks(customSettings=None)[source]
Builds a operator w/ a reactor object with some Cartesian assemblies and blocks, but all are empty.
Doesn’t depend on inputs and loads quickly.
- Parameters:
customSettings (dict) – Off-default settings to update
- class armi.testing.ArmiTestHelper(methodName='runTest')[source]
Bases:
TestCaseClass containing common testing methods shared by many tests.
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.
- compareFilesLineByLine(expectedFilePath, actualFilePath, falseNegList=None, eps=None)[source]
Compare the contents of two files line by line.
Warning
The file located at actualFilePath will be deleted if they do match.
Some tests write text files that should be compared line-by-line with reference files. This method performs the comparison.
This class of test is not ideal but does cover a lot of functionality quickly. To assist in the maintenance burden, the following standards are expected and enforced:
The reference file compared against will be called either
[name]-ref.[ext]or[name].expected.The file that the test creates will be called
[name]-test.[ext]or[name].
- Parameters:
expectedFilePath (str) – Path to the reference or expected file
actualFilePath (str) – Path to the file that will be compared to
expectedFilePathfalseNegList (None or Iterable) – Optional argument. If two lines are not equal, then check if any values from
falseNegListare in this line. If so, do not fail the test.eps (float, optional) – If provided, try to determine if the only difference between compared lines is in the value of something that can be parsed into a float, and the relative difference between the two floats is below the passed eps.
- static compareLines(actual: str, expected: str, eps: float | None = None)[source]
Impl of line comparison for compareFilesLineByLine.
If rstripped lines are equal -> Good. Otherwise, split on whitespace and try to parse element pairs as floats. If they are both parsable, compare with relative eps, if provided. A side effect of the epsilon comparison is that differing whitespace between words is treated as irrelevant.
- class armi.testing.TestPlugin(methodName='runTest')[source]
Bases:
TestCaseSome sanity tests that can be used by implementing plugins.
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.
- plugin: ArmiPlugin | None = None