From 3992d3a382bbbd0ac1c8485b055e6dae45916385 Mon Sep 17 00:00:00 2001 From: tcmcclan-ornl <144276349+tcmcclan-ornl@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:27:54 -0400 Subject: [PATCH] Fixed instance checker in voidMat (#264) * Fixed instance checker in voidMat Fixed the void mat instance checker to check for the first entry being an int, second entry being a float or int, and the third entry being a str. * Update config_cadtocsg_non_defaults.json Updated config_cadtocsg_non_defaults.json to test voidMat with a material defined * Update tests/config_cadtocsg_non_defaults.json * Update src/geouned/GEOUNED/utils/data_classes.py black format --------- Co-authored-by: Patrick Sauvan --- src/geouned/GEOUNED/utils/data_classes.py | 15 +++++++++++---- tests/config_cadtocsg_non_defaults.json | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/geouned/GEOUNED/utils/data_classes.py b/src/geouned/GEOUNED/utils/data_classes.py index 1eb9a6b7..6891224d 100644 --- a/src/geouned/GEOUNED/utils/data_classes.py +++ b/src/geouned/GEOUNED/utils/data_classes.py @@ -769,10 +769,17 @@ def voidMat(self): def voidMat(self, voidMat: list): if not isinstance(voidMat, list): raise TypeError(f"geouned.Settings.voidMat should be a list, not a {type(voidMat)}") - for entry in voidMat: - if not isinstance(entry, int): - raise TypeError(f"geouned.Settings.voidMat should be a list of ints, not a {type(entry)}") - self._voidMat = voidMat + if len(voidMat) == 0: + self._voidMat = voidMat + else: + if not isinstance(voidMat[0], int): + raise TypeError(f"first entry of geouned.Settings.voidMat should be an int, not a {type(entry)}") + if not isinstance(voidMat[1], int): + if not isinstance(voidMat[1], float): + raise TypeError(f"second entry of geouned.Settings.voidMat should be an int or float, not a {type(entry)}") + if not isinstance(voidMat[2], str): + raise TypeError(f"third entry of geouned.Settings.voidMat should be a str, not a {type(entry)}") + self._voidMat = voidMat @property def voidExclude(self): diff --git a/tests/config_cadtocsg_non_defaults.json b/tests/config_cadtocsg_non_defaults.json index 9c7deb05..3d16f197 100644 --- a/tests/config_cadtocsg_non_defaults.json +++ b/tests/config_cadtocsg_non_defaults.json @@ -12,6 +12,7 @@ "P_abc": "15.7e" }, "Settings": { - "matFile": "non default" + "matFile": "non default", + "voidMat": [1, -1.29E-3, "Dry air"] } -} \ No newline at end of file +}