Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving error testing #2004

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 7 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,10 @@ 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())

def test_copyOrWarnDir(self):
with TemporaryDirectoryChanger():
Expand All @@ -55,11 +55,10 @@ 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())

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