Repository: NREL/hescore-hpxml

Issue:
Throw descriptive error message on SlabOnGrade foundations when a Slab element is missing
Currently, when foundations are defined without attaching a slab element, translator will throw an error of "integer division or modulo by zero". A more descriptive error is expected to reflect the missing input.
Might be a sub-issue of #106 .

Discussion:

Patch:
diff --git a/hescorehpxml/__init__.py b/hescorehpxml/__init__.py
index 55a58b86..e7bfb5c8 100644
--- a/hescorehpxml/__init__.py
+++ b/hescorehpxml/__init__.py
@@ -1345,7 +1345,7 @@ class HPXMLtoHEScoreTranslator(object):
             elif zone_floor['foundation_type'] == 'slab_on_grade':
                 del fw_eff_rvalues[11]  # remove unused values
                 del fw_eff_rvalues[19]
-                slabs = foundation.xpath('h:Slab', namespaces=ns)
+                slabs = xpath(foundation, 'h:Slab', raise_err=True, aslist=True)
                 slabua = 0
                 slabtotalperimeter = 0
                 for slab in slabs:


Test patch:
diff --git a/tests/tests.py b/tests/tests.py
index 1f6fd6cb..60924139 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -320,6 +320,15 @@ class TestOtherHouses(unittest.TestCase, ComparatorBase):
                                 r'The house is a slab on grade foundation, but has foundation walls\.',
                                 tr.hpxml_to_hescore_dict)
 
+    def test_slab_missing(self):
+        tr = self._load_xmlfile('house3')
+        el = self.xpath('//h:Slab')
+        el.getparent().remove(el)
+        self.assertRaises(
+            ElementNotFoundError,
+            tr.hpxml_to_hescore_dict
+        )
+
     def test_missing_window_area(self):
         tr = self._load_xmlfile('hescore_min')
         el = self.xpath('//h:Window[1]/h:Area')