# Copyright 2019 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module provides tests for the generic Executers."""
import os
import unittest
from armi.reactor import geometry
from armi.utils import directoryChangers
from armi.physics import executers
[docs]class MockReactorParams:
def __init__(self):
self.cycle = 1
self.timeNode = 2
[docs]class MockCoreParams:
pass
[docs]class MockCore:
def __init__(self):
# just pick a random geomType
self.geomType = geometry.GeomType.CARTESIAN
self.symmetry = "full"
self.p = MockCoreParams()
[docs]class MockReactor:
def __init__(self):
self.core = MockCore()
self.o = None
self.p = MockReactorParams()
[docs]class TestExecutionOptions(unittest.TestCase):
[docs] def test_runningDirectoryPath(self):
"""
Test that the running directory path is set up correctly
based on the case title and label provided.
"""
e = executers.ExecutionOptions(label=None)
e.setRunDirFromCaseTitle(caseTitle="test")
self.assertEqual(os.path.basename(e.runDir), "508bc04f-0")
e = executers.ExecutionOptions(label="label")
e.setRunDirFromCaseTitle(caseTitle="test")
self.assertEqual(os.path.basename(e.runDir), "b07da087-0")
e = executers.ExecutionOptions(label="label2")
e.setRunDirFromCaseTitle(caseTitle="test")
self.assertEqual(os.path.basename(e.runDir), "9c1c83cb-0")
[docs]class TestExecuters(unittest.TestCase):
def setUp(self):
e = executers.ExecutionOptions(label=None)
self.executer = executers.DefaultExecuter(e, MockReactor())
[docs] def test_updateRunDir(self):
"""
Verify that runDir is updated when TemporaryDirectoryChanger is used and
not updated when ForcedCreationDirectoryChanger is used.
"""
self.assertEqual(
self.executer.dcType, directoryChangers.TemporaryDirectoryChanger
)
self.executer._updateRunDir("updatedRunDir")
self.assertEqual(self.executer.options.runDir, "updatedRunDir")
# change directoryChanger type, runDir not updated
self.executer.options.runDir = "runDir"
self.executer.dcType = directoryChangers.ForcedCreationDirectoryChanger
self.executer._updateRunDir("notThisString")
self.assertEqual(self.executer.options.runDir, "runDir")