Skip to content

Commit

Permalink
Moving anl-afci-177 test files to their own directory (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Oct 17, 2024
1 parent 01b0ade commit 8b5163a
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 78 deletions.
14 changes: 9 additions & 5 deletions armi/bookkeeping/tests/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
also re-exported by `__init__.py`, so that other things (like the documentation system)
can use it without having to import the rest of ARMI.
"""
import os

from armi.tests import TEST_ROOT


# These files are needed to run the data_model ipython notebook, which is done in
# test_historyTracker, and when building the docs.
TUTORIAL_FILES = [
"anl-afci-177-blueprints.yaml",
"anl-afci-177-coreMap.yaml",
"anl-afci-177-fuelManagement.py",
"anl-afci-177.yaml",
"data_model.ipynb",
os.path.join(TEST_ROOT, "anl-afci-177", "anl-afci-177-blueprints.yaml"),
os.path.join(TEST_ROOT, "anl-afci-177", "anl-afci-177-coreMap.yaml"),
os.path.join(TEST_ROOT, "anl-afci-177", "anl-afci-177-fuelManagement.py"),
os.path.join(TEST_ROOT, "anl-afci-177", "anl-afci-177.yaml"),
os.path.join(TEST_ROOT, "tutorials", "data_model.ipynb"),
]
19 changes: 14 additions & 5 deletions armi/bookkeeping/tests/test_historyTracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,29 @@ class TestHistoryTracker(ArmiTestHelper):

@classmethod
def setUpClass(cls):
# We need to be in the TUTORIAL_DIR so that for `filesToMove` to work right.
os.chdir(TUTORIAL_DIR)

# Do this work in a temp dir, to avoid race conditions.
cls.dirChanger = TemporaryDirectoryChanger(filesToMove=TUTORIAL_FILES)
cls.dirChanger = TemporaryDirectoryChanger()
cls.dirChanger.__enter__()

os.mkdir("tutorials")
os.mkdir(CASE_TITLE)

for filePath in TUTORIAL_FILES:
dirName = CASE_TITLE if CASE_TITLE in filePath else "tutorials"
outFile = os.path.join(
cls.dirChanger.destination, dirName, os.path.basename(filePath)
)
shutil.copyfile(filePath, outFile)

os.chdir(os.path.join(cls.dirChanger.destination, "tutorials"))
runTutorialNotebook()

@classmethod
def tearDownClass(cls):
cls.dirChanger.__exit__(None, None, None)

def setUp(self):
cs = settings.Settings(f"{CASE_TITLE}.yaml")
cs = settings.Settings(f"../{CASE_TITLE}/{CASE_TITLE}.yaml")
newSettings = {}
newSettings["db"] = True
newSettings["nCycles"] = 2
Expand Down
2 changes: 1 addition & 1 deletion armi/cases/tests/test_suiteBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"..",
"..",
"tests",
"tutorials",
"anl-afci-177",
"anl-afci-177.yaml",
)
)
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions armi/tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from armi.tests import TEST_ROOT

TUTORIALS = os.path.join(TEST_ROOT, "tutorials")
ANL_ACFI_177 = os.path.join(TEST_ROOT, "anl-afci-177")


class NotebookTests(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions armi/tests/tutorials/data_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"metadata": {},
"outputs": [],
"source": [
"o=armi.init(fName=\"anl-afci-177.yaml\");\n",
"o=armi.init(fName=\"../anl-afci-177/anl-afci-177.yaml\");\n",
"o.r.core.sortAssemsByRing() # makes innermost assemblies appear first"
]
},
Expand Down Expand Up @@ -468,7 +468,7 @@
"outputs": [],
"source": [
"from armi.bookkeeping import db\n",
"databaseLocation = \"anl-afci-177.h5\"\n",
"databaseLocation = \"../tutorials/anl-afci-177.h5\"\n",
"cycle, timeNode = 0, 1\n",
"dbo = db.databaseFactory(databaseLocation, \"r\")\n",
"with dbo:\n",
Expand Down
4 changes: 2 additions & 2 deletions armi/tests/tutorials/param_sweep.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"from armi.cases import suiteBuilder\n",
"from armi.cases.inputModifiers import inputModifiers\n",
"\n",
"cs = settings.Settings('anl-afci-177.yaml')\n",
"cs = settings.Settings('../anl-afci-177/anl-afci-177.yaml')\n",
"case = cases.Case(cs)"
]
},
Expand Down Expand Up @@ -268,7 +268,7 @@
"source": [
"def loadSuite():\n",
" print('Loading suite results...')\n",
" cs = settings.Settings('anl-afci-177.yaml')\n",
" cs = settings.Settings('../anl-afci-177/anl-afci-177.yaml')\n",
" suite = cases.CaseSuite(cs)\n",
" suite.discover(patterns=[\"anl-afci-177-????.yaml\"])\n",
" suite = sorted(suite, key=lambda c: c.cs.inputDirectory)\n",
Expand Down
31 changes: 16 additions & 15 deletions armi/utils/directoryChangers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class DirectoryChanger:
Filenames to bring back from the destination to the cwd. Note that if any of these
files do not exist then the file will be skipped and a warning will be provided.
dumpOnException : bool, optional
Flag to tell system to retrieve the entire directory if an exception
is raised within a the context manager.
Flag to tell system to retrieve the entire directory if an exception is raised within a the
context manager.
outputPath : str, optional
Output path for filesToRetrieve. If None, default is the initial working directory
from which the DirectoryChanger is called.
Output path for filesToRetrieve. If None, default is the initial working directory from
which the DirectoryChanger is called.
"""

def __init__(
Expand Down Expand Up @@ -177,10 +177,9 @@ def _transferFiles(initialPath, destinationPath, fileList):
"""
Transfer files into or out of the directory.
This is used in ``moveFiles`` and ``retrieveFiles`` to shuffle files about when
creating a target directory or when coming back, respectively. Beware that this
uses ``shutil.copy()`` under the hood, which doesn't play nicely with
directories. Future revisions should improve this.
This is used in ``moveFiles`` and ``retrieveFiles`` to shuffle files about when creating a
target directory or when coming back, respectively. Beware that this uses ``shutil.copy()``
under the hood, which doesn't play nicely with directories.
Parameters
----------
Expand All @@ -189,20 +188,22 @@ def _transferFiles(initialPath, destinationPath, fileList):
destinationPath: str
Path to the folder to move file to.
fileList : list of str or list of tuple
File names to move from initial to destination. If this is a
simple list of strings, the files will be transferred. Alternatively
tuples of (initialName, finalName) are allowed if you want the file
renamed during transit. In the non-tuple option, globs/wildcards
File names to move from initial to destination. If this is a simple list of strings, the
files will be transferred. Alternatively tuples of (initialName, finalName) are allowed
if you want the file renamed during transit. In the non-tuple option, globs/wildcards
are allowed.
.. warning:: On Windows the max number of characters in a path is 260.
If you exceed this you will see FileNotFound errors here.
Warning
-------
On Windows the max number of characters in a path is 260.
If you exceed this you will see FileNotFound errors here.
"""
if not fileList:
return

if not os.path.exists(destinationPath):
os.makedirs(destinationPath)

for pattern in fileList:
if isinstance(pattern, tuple):
# allow renames in transit
Expand Down
4 changes: 1 addition & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
APIDOC_REL = ".apidocs"
SOURCE_DIR = os.path.join("..", "armi")
_TUTORIAL_FILES = [
pathlib.Path(SOURCE_DIR) / "tests" / "tutorials" / fName
for fName in bookkeepingTests.TUTORIAL_FILES
if "ipynb" not in fName
fName for fName in bookkeepingTests.TUTORIAL_FILES if "ipynb" not in fName
]


Expand Down
8 changes: 4 additions & 4 deletions doc/tutorials/data_model.nblink
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"path": "../../armi/tests/tutorials/data_model.ipynb",
"extra-media": [
"../../armi/tests/tutorials/anl-afci-177-blueprints.yaml",
"../../armi/tests/tutorials/anl-afci-177.yaml",
"../../armi/tests/tutorials/anl-afci-177-coreMap.yaml",
"../../armi/tests/tutorials/anl-afci-177-fuelManagement.py"
"../../armi/tests/anl-afci-177/anl-afci-177-blueprints.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177-coreMap.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177-fuelManagement.py"
]
}
8 changes: 4 additions & 4 deletions doc/tutorials/making_your_first_app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ for your own interests!).

Here are the files you can download into the run directory.

* :download:`Blueprints <../../armi/tests/tutorials/anl-afci-177-blueprints.yaml>`
* :download:`Settings <../../armi/tests/tutorials/anl-afci-177.yaml>`
* :download:`Core map <../../armi/tests/tutorials/anl-afci-177-coreMap.yaml>`
* :download:`Fuel management <../../armi/tests/tutorials/anl-afci-177-fuelManagement.py>`
* :download:`Blueprints <../../armi/tests/anl-afci-177/anl-afci-177-blueprints.yaml>`
* :download:`Settings <../../armi/tests/anl-afci-177/anl-afci-177.yaml>`
* :download:`Core map <../../armi/tests/anl-afci-177/anl-afci-177-coreMap.yaml>`
* :download:`Fuel management <../../armi/tests/anl-afci-177/anl-afci-177-fuelManagement.py>`


Then, run your app!::
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorials/param_sweep.nblink
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"path": "../../armi/tests/tutorials/param_sweep.ipynb",
"extra-media": [
"../../armi/tests/tutorials/anl-afci-177-blueprints.yaml",
"../../armi/tests/tutorials/anl-afci-177.yaml",
"../../armi/tests/tutorials/anl-afci-177-coreMap.yaml",
"../../armi/tests/tutorials/anl-afci-177-fuelManagement.py"
"../../armi/tests/anl-afci-177/anl-afci-177-blueprints.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177-coreMap.yaml",
"../../armi/tests/anl-afci-177/anl-afci-177-fuelManagement.py"
]
}
Loading

0 comments on commit 8b5163a

Please sign in to comment.