def bootstrapArmiTestEnv(): """ Perform ARMI config appropriate for running unit tests .. tip:: This can be imported and run from other ARMI applications for test support. """ from armi.nucDirectory import nuclideBases cs = caseSettings.Settings() context.Mode.setMode(context.Mode.BATCH) settings.setMasterCs(cs) # Need to init burnChain. # see armi.cases.case.Case._initBurnChain with open(cs["burnChainFileName"]) as burnChainStream: nuclideBases.imposeBurnChain(burnChainStream) # turn on a non-interactive mpl backend to minimize errors related to # initializing Tcl in parallel tests matplotlib.use("agg") # set and create a test-specific FAST_PATH for parallel unit testing # Not all unit tests have operators, and operators are usually # responsible for making FAST_PATH, so we make it here. # It will be deleted by the atexit hook. context.activateLocalFastPath() if not os.path.exists(context.getFastPath()): os.makedirs(context.getFastPath()) # some tests need to find the TEST_ROOT via an env variable when they're # filling in templates with ``$ARMITESTBASE`` in them or opening # input files use the variable in an `!include` tag. Thus # we provide it here. os.environ["ARMITESTBASE"] = TEST_ROOT
def _initFastPath(): """ Create the FAST_PATH directory for fast local operations Notes ----- The FAST_PATH was once created at import-time in order to support modules that use FAST_PATH without operators (e.g. Database). However, we decided to leave FAST_PATH as the CWD in INTERACTIVE mode, so this should not be a problem anymore, and we can safely move FAST_PATH creation back into the Operator. If the operator is being used interactively (e.g. at a prompt) we will still use a temporary local fast path (in case the user is working on a slow network path). """ context.activateLocalFastPath() try: os.makedirs(context.getFastPath()) except OSError: # If FAST_PATH exists already that generally should be an error because # different processes will be stepping on each other. # The exception to this rule is in cases that instantiate multiple operators in one # process (e.g. unit tests that loadTestReactor). Since the FAST_PATH is set at # import, these will use the same path multiple times. We pass here for that reason. if not os.path.exists(context.getFastPath()): # if it actually doesn't exist, that's an actual error. Raise raise