def __init__(self, fName=None): """ Instantiate a settings object Parameters ---------- fName : str, optional Path to a valid yaml settings file that will be loaded """ self._failOnLoad = False """This is state information. The command line can take settings, which override a value in the current settings file; however, if the settings file is listed after a setting value, the setting from the settings file will be used rather than the one explicitly provided by the user on the command line. Therefore, _failOnLoad is used to prevent this from happening. """ self.path = "" app = armi.getApp() assert (app is not None) self.settings = app.getSettings() if not Settings.instance: Settings.instance = self self._backedup = {} if fName: self.loadFromInputFile(fName)
def test_getParamRenames(self): app = armi.getApp() app.pluginManager.register(TestPlugin1) app.pluginManager.register(TestPlugin4) app._paramRenames = None # need to implement better cache invalidation rules renames = app.getParamRenames() self.assertIn("oldType", renames) self.assertEqual(renames["oldType"], "type") self.assertIn("arealPD", renames) self.assertEqual(renames["arealPD"], "arealPowerDensity") app.pluginManager.register(TestPlugin2) app._paramRenames = None # need to implement better cache invalidation rules with self.assertRaisesRegex( plugins.PluginError, ".*parameter renames are already defined by another plugin.*", ): app.getParamRenames() app.pluginManager.unregister(TestPlugin2) app.pluginManager.register(TestPlugin3) with self.assertRaisesRegexp( plugins.PluginError, ".*currently-defined parameters.*" ): app.getParamRenames()
def test_splashText(self): app = getApp() splash = app.splashText self.assertIn("========", splash) self.assertIn("Advanced", splash) self.assertIn("version", splash) self.assertIn(meta.__version__, splash)
def test_getSettings(self): app = getApp() settings = app.getSettings() self.assertGreater(len(settings), 100) self.assertEqual(settings["numProcessors"].value, 1) self.assertEqual(settings["nCycles"].value, 1)
def __init__(self, fName=None): """ Instantiate a settings object Parameters ---------- fName : str, optional Path to a valid yaml settings file that will be loaded """ # if the "loadingFile" is not set, this better be True, or there are no blueprints at all self.filelessBP = False self._failOnLoad = False """This is state information. The command line can take settings, which override a value in the current settings file; however, if the settings file is listed after a setting value, the setting from the settings file will be used rather than the one explicitly provided by the user on the command line. Therefore, _failOnLoad is used to prevent this from happening. """ from armi import getApp # pylint: disable=import-outside-toplevel self.path = "" app = getApp() assert app is not None self.__settings = app.getSettings() if not Settings.instance: Settings.instance = self if fName: self.loadFromInputFile(fName)
def __setstate__(self, state): """ Rebuild schema upon unpickling since schema is unpickleable. Pickling happens during mpi broadcasts and also during testing where the test reactor is cached. See Also -------- armi.settings.setting.Setting.__getstate__ : removes schema """ from armi import getApp # pylint: disable=import-outside-toplevel self.__settings = getApp().getSettings() # restore non-setting instance attrs for key, val in state.items(): if key != "_Settings__settings": setattr(self, key, val) # with schema restored, restore all setting values for name, settingState in state["_Settings__settings"].items(): # pylint: disable=protected-access if name in self.__settings: self.__settings[name]._value = settingState.value elif isinstance(settingState, Setting): self.__settings[name] = copy(settingState) else: raise NonexistentSetting(name)
def splash(): """Emit a the active App's splash text to the runLog for the master node.""" from armi import getApp # pylint: disable=import-outside-toplevel app = getApp() assert app is not None if context.MPI_RANK == 0: runLog.raw(app.splashText)
def splash(): """ Emit a the active App's splash text to the runLog for the master node. """ app = armi.getApp() assert app is not None if armi.context.MPI_RANK == 0: runLog.raw(app.splashText)
def showVersion(self): """Print the App name and version on the command line""" from armi import getApp # pylint: disable=import-outside-toplevel prog = context.APP_NAME app = getApp() if app is None or prog == "armi": print("{0} {1}".format(prog, meta.__version__)) else: print("{0} {1}".format(prog, app.version))
def test_splashTextDifferentApp(self): import armi app = getApp() name = "DifferentApp" app.name = name armi._app = app context.APP_NAME = name splash = app.splashText self.assertIn("========", splash) self.assertIn("Advanced", splash) self.assertIn("version", splash) self.assertIn(meta.__version__, splash) self.assertIn("DifferentApp", splash)
def __setstate__(self, state): """ Rebuild schema upon unpickling since schema is unpickleable. Pickling happens during mpi broadcasts and also during testing where the test reactor is cached. See Also -------- armi.settings.setting.Setting.__getstate__ : removes schema """ self.settings = armi.getApp().getSettings() # restore non-setting instance attrs for key, val in state.items(): if key != "settings": setattr(self, key, val) # with schema restored, restore all setting values for name, settingState in state["settings"].items(): # pylint: disable=protected-access self.settings[name]._value = settingState.value
def test_getParamRenamesInvalids(self): # a basic test of the method app = getApp() app.pluginManager.register(TestPlugin1) app.pluginManager.register(TestPlugin4) app._paramRenames = None # need to implement better cache invalidation rules renames = app.getParamRenames() self.assertIn("oldType", renames) self.assertEqual(renames["oldType"], "type") self.assertIn("arealPD", renames) self.assertEqual(renames["arealPD"], "arealPowerDensity") # test the strange, invalid case self.assertIsNotNone(app._paramRenames) app._pm._counter = -1 renames = app.getParamRenames() self.assertIn("oldType", renames) self.assertEqual(renames["oldType"], "type") self.assertIn("arealPD", renames) self.assertEqual(renames["arealPD"], "arealPowerDensity")
def setParameterWithRenaming(obj, parameter, value): """ Set a parameter on an object, supporting renamed parameters. This allows older databases to work with newer ARMI versions if the parameter renames are properly recorded. """ # Watch out, this might be slow if it isn't cached by the App renames = armi.getApp().getParamRenames() name = parameter while name in renames: name = renames[name] try: obj.p[name] = value except (parameters.UnknownParameterError, AssertionError): runLog.warning( "Incompatible database has unsupported parameter: " '"{}", and will be ignored!'.format(parameter), single=True, )
def test_getParamRenames(self): # a basic test of the method app = getApp() app.pluginManager.register(TestPlugin1) app.pluginManager.register(TestPlugin4) app._paramRenames = None # need to implement better cache invalidation rules renames = app.getParamRenames() self.assertIn("oldType", renames) self.assertEqual(renames["oldType"], "type") self.assertIn("arealPD", renames) self.assertEqual(renames["arealPD"], "arealPowerDensity") # test an invalid param manager situation app._paramRenames[0][1] = -3 renames = app.getParamRenames() self.assertIn("oldType", renames) self.assertEqual(renames["oldType"], "type") self.assertIn("arealPD", renames) self.assertEqual(renames["arealPD"], "arealPowerDensity") # test the exceptions that get raised app.pluginManager.register(TestPlugin2) app._paramRenames = None # need to implement better cache invalidation rules with self.assertRaisesRegex( plugins.PluginError, ".*parameter renames are already defined by another plugin.*", ): app.getParamRenames() app.pluginManager.unregister(TestPlugin2) app.pluginManager.register(TestPlugin3) with self.assertRaisesRegex( plugins.PluginError, ".*currently-defined parameters.*" ): app.getParamRenames()
def splashText(self): """ Return a textual splash screen. Specific applications will want to customize this, but by default the ARMI one is produced, with extra data on the App name and version, if available. """ # typical ARMI splash text splash = r""" +===================================================+ | _ ____ __ __ ___ | | / \ | _ \ | \/ | |_ _| | | / _ \ | |_) | | |\/| | | | | | / ___ \ | _ < | | | | | | | | /_/ \_\ |_| \_\ |_| |_| |___| | | Advanced Reactor Modeling Interface | | | | version {0:10s} | | |""".format( meta.__version__) # add the name/version of the current App, if it's not the default if context.APP_NAME != "armi": # pylint: disable=import-outside-toplevel # avoid cyclic import from armi import getApp splash += r""" |---------------------------------------------------| | {0:>17s} app version {1:10s} |""".format(context.APP_NAME, getApp().version) # bottom border of the splash splash += r""" +===================================================+ """ return splash
def _collectParamRenames(): return {"paramRenames": getApp().getParamRenames()}
def setUp(self): """Manipulate the standard App. We can't just configure our own, since the pytest environment bleeds between tests :(""" self._backupApp = copy.deepcopy(getApp())
# pylint: disable=missing-function-docstring,missing-class-docstring,abstract-method,protected-access import asyncio import os import pytest import time import unittest import test.support # wxpython is an optional dependency, and without it we cant do much of anything. This # should raise a unittest.SkipTest if it can't find wx, signalling to pytest to skip the # rest of the module. Neat! wx = test.support.import_module("wx") from armi import configure, getApp if getApp() is None: configure() from armi.utils import gridEditor _SECONDS_PER_TICK = 0.05 def _wait(num_ticks: int) -> None: time.sleep(num_ticks * _SECONDS_PER_TICK) def _findPointInWindow(window: wx.Window, offsetFromLeft: float = 0.5, offsetFromTop: float = 0.5) -> wx.Point: """Given a window, return a point in it. Defaults to the center of the window object.
def setUp(self): # We are going to be messing with the plugin manager, which is global ARMI # state, so we back it up and restore the original when we are done. self._backupApp = copy.copy(getApp())
def test_version(self): app = getApp() ver = app.version self.assertEqual(ver, meta.__version__)