Skip to content

Commit

Permalink
Restore the db _fullPath upon close() (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
keckler committed Oct 7, 2022
1 parent b4e477c commit 3d6a992
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ def close(self, completedSuccessfully=False):

if self._permission == "w":
# move out of the FAST_PATH and into the working directory
shutil.move(self._fullPath, self._fileName)
newPath = shutil.move(self._fullPath, self._fileName)
self._fullPath = os.path.abspath(newPath)

def splitDatabase(
self, keepTimeSteps: Sequence[Tuple[int, int]], label: str
Expand Down
19 changes: 19 additions & 0 deletions armi/bookkeeping/db/tests/test_database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
r""" Tests for the Database3 class
"""
# pylint: disable=missing-function-docstring,missing-class-docstring,abstract-method,protected-access,no-member,disallowed-name,invalid-name
import os
import subprocess
import unittest

import h5py
import numpy

from armi import context
from armi.bookkeeping.db import _getH5File, database3
from armi.reactor import grids
from armi.reactor import parameters
Expand Down Expand Up @@ -683,6 +685,23 @@ def test_locationPackingOldVersion(self):
self.assertEqual(unpackedData[2][0], (7, 8, 9))
self.assertEqual(unpackedData[2][1], (10, 11, 12))

def test_close(self):
intendedFileName = "xyz.h5"

db = database3.Database3(intendedFileName, "w")
self.assertEqual(db._fileName, intendedFileName)
self.assertIsNone(db._fullPath) # this isn't set until the db is opened

db.open()
self.assertEqual(
db._fullPath, os.path.join(context.getFastPath(), intendedFileName)
)

db.close() # this should move the file out of the FAST_PATH
self.assertEqual(
db._fullPath, os.path.join(os.path.abspath("."), intendedFileName)
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 3d6a992

Please sign in to comment.