From db1d1525989368b03130e0e5709595bb7a84c8f5 Mon Sep 17 00:00:00 2001 From: John Stilley <1831479+john-science@users.noreply.github.com> Date: Thu, 7 Dec 2023 07:42:11 -0800 Subject: [PATCH] Add executer options to executer unit test (#1523) --- armi/physics/tests/test_executers.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/armi/physics/tests/test_executers.py b/armi/physics/tests/test_executers.py index a918a6152..e4e9fefad 100644 --- a/armi/physics/tests/test_executers.py +++ b/armi/physics/tests/test_executers.py @@ -113,10 +113,17 @@ def test_runExternalExecutable(self): """ filePath = "test_runExternalExecutable.py" outFile = "tmp.txt" + label = "printExtraStuff" - class TestSillyExecuter(executers.Executer): + class MockExecutionOptions(executers.ExecutionOptions): + pass + + class MockExecuter(executers.Executer): def run(self, args): - subprocess.run(["python", filePath, args]) + if self.options.label == label: + subprocess.run(["python", filePath, "extra stuff"]) + else: + subprocess.run(["python", filePath, args]) with directoryChangers.TemporaryDirectoryChanger(): # build a mock external program (a little Python script) @@ -126,7 +133,8 @@ def run(self, args): self.assertFalse(os.path.exists(outFile)) # set up an executer for our little test program - exe = TestSillyExecuter(None, None) + opts = MockExecutionOptions() + exe = MockExecuter(opts, None) exe.run("") # make sure the output file exists now @@ -141,6 +149,12 @@ def run(self, args): newTxt = open(outFile, "r").read() self.assertIn(testString, newTxt) + # now prove the options object can affect the execution + exe.options.label = label + exe.run("") + newerTxt = open(outFile, "r").read() + self.assertIn("extra stuff", newerTxt) + @staticmethod def __makeALittleTestProgram(filePath, outFile): """Helper method to write a tiny Python script.