Skip to content

Commit

Permalink
Add executer options to executer unit test (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Dec 7, 2023
1 parent eef678c commit db1d152
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions armi/physics/tests/test_executers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit db1d152

Please sign in to comment.