Skip to content

Commit

Permalink
Improving error testing
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Nov 1, 2024
1 parent 7dffa72 commit b376a85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
8 changes: 5 additions & 3 deletions armi/bookkeeping/db/tests/test_comparedb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,17 @@ def test_diffSpecialData(self):
refData4 = f4.create_dataset("numberDensities", data=a2)
refData4.attrs["shapes"] = "2"
refData4.attrs["numDens"] = a2
refData4.attrs["specialFormatting"] = True
f5 = h5py.File("test_diffSpecialData5.hdf5", "w")
srcData5 = f5.create_dataset("numberDensities", data=a2)
srcData5.attrs["shapes"] = "2"
srcData5.attrs["numDens"] = a2
srcData5.attrs["specialFormatting"] = True

# there should an exception
with self.assertRaises(Exception) as e:
# there should a log message
with mockRunLogs.BufferLog() as mock:
_diffSpecialData(refData4, srcData5, out, dr)
self.assertIn("Unable to unpack special data for paramName", e)
self.assertIn("Unable to unpack special data for", mock.getStdout())

# make an H5 datasets that will add a np.inf diff because keys don't match
f6 = h5py.File("test_diffSpecialData6.hdf5", "w")
Expand Down
21 changes: 13 additions & 8 deletions armi/utils/tests/test_pathTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import unittest

from armi import context
from armi.tests import mockRunLogs
from armi.utils import pathTools
from armi.utils.directoryChangers import TemporaryDirectoryChanger

Expand All @@ -36,11 +37,13 @@ def test_copyOrWarnFile(self):
pathTools.copyOrWarn("Test File", path, pathCopy)
self.assertTrue(os.path.exists(pathCopy))

# Test an exception
with self.assertRaises(Exception) as e:
# Test a non-existant file
with mockRunLogs.BufferLog() as mock:
pathTools.copyOrWarn("Test File", "FileDoesntExist.txt", pathCopy)
self.assertIn("Could not copy", e)
self.assertIn("No such file or directory", e)
self.assertIn("Could not copy", mock.getStdout())
self.assertIn(
"The system cannot find the file specified", mock.getStdout()
)

def test_copyOrWarnDir(self):
with TemporaryDirectoryChanger():
Expand All @@ -55,11 +58,13 @@ def test_copyOrWarnDir(self):
self.assertTrue(os.path.exists(pathDirCopy))
self.assertTrue(os.path.exists(os.path.join(pathDirCopy, "test.txt")))

# Test an exception
with self.assertRaises(Exception) as e:
# Test a non-existant file
with mockRunLogs.BufferLog() as mock:
pathTools.copyOrWarn("Test File", "DirDoesntExist", pathDirCopy)
self.assertIn("Could not copy", e)
self.assertIn("No such file or directory", e)
self.assertIn("Could not copy", mock.getStdout())
self.assertIn(
"The system cannot find the file specified", mock.getStdout()
)

def test_separateModuleAndAttribute(self):
self.assertRaises(
Expand Down

0 comments on commit b376a85

Please sign in to comment.