From b376a85eae0b6a1f6f3bccf78796a7222cca7967 Mon Sep 17 00:00:00 2001 From: jstilley Date: Fri, 1 Nov 2024 15:19:14 -0700 Subject: [PATCH 1/2] Improving error testing --- armi/bookkeeping/db/tests/test_comparedb3.py | 8 +++++--- armi/utils/tests/test_pathTools.py | 21 ++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/armi/bookkeeping/db/tests/test_comparedb3.py b/armi/bookkeeping/db/tests/test_comparedb3.py index a19b94950..2b07a3dc9 100644 --- a/armi/bookkeeping/db/tests/test_comparedb3.py +++ b/armi/bookkeeping/db/tests/test_comparedb3.py @@ -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") diff --git a/armi/utils/tests/test_pathTools.py b/armi/utils/tests/test_pathTools.py index 2b6f046db..5ab97bd77 100644 --- a/armi/utils/tests/test_pathTools.py +++ b/armi/utils/tests/test_pathTools.py @@ -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 @@ -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(): @@ -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( From 7146a8acaaa561046b73f633ecad04bf7b801f01 Mon Sep 17 00:00:00 2001 From: jstilley Date: Fri, 1 Nov 2024 15:37:43 -0700 Subject: [PATCH 2/2] Whoops - that is a Linux error message --- armi/utils/tests/test_pathTools.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/armi/utils/tests/test_pathTools.py b/armi/utils/tests/test_pathTools.py index 5ab97bd77..8ac3affe0 100644 --- a/armi/utils/tests/test_pathTools.py +++ b/armi/utils/tests/test_pathTools.py @@ -41,9 +41,6 @@ def test_copyOrWarnFile(self): with mockRunLogs.BufferLog() as mock: pathTools.copyOrWarn("Test File", "FileDoesntExist.txt", pathCopy) self.assertIn("Could not copy", mock.getStdout()) - self.assertIn( - "The system cannot find the file specified", mock.getStdout() - ) def test_copyOrWarnDir(self): with TemporaryDirectoryChanger(): @@ -62,9 +59,6 @@ def test_copyOrWarnDir(self): with mockRunLogs.BufferLog() as mock: pathTools.copyOrWarn("Test File", "DirDoesntExist", pathDirCopy) self.assertIn("Could not copy", mock.getStdout()) - self.assertIn( - "The system cannot find the file specified", mock.getStdout() - ) def test_separateModuleAndAttribute(self): self.assertRaises(