Skip to content

Commit cdcc3ab

Browse files
committed
bugfix on check of unit and perunit if these attributes dont exist
1 parent 78cdbb6 commit cdcc3ab

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

esdlvalidator/validation/functions/check_child_attribute_not_null.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ def check_units(self, prop, qau):
164164
correct = 0
165165
msg = {"offending_asset": self.value.id}
166166
for i in range(0, len(self.args["unit_type"])):
167-
unittype = getattr(qau, self.args["unit_type"][i])
168-
unit = self.args["unit"][i]
169-
if str(unittype.name).lower() == str(unit).lower():
170-
correct += 1
167+
if hasattr(qau, self.args["unit_type"][i]):
168+
unittype = getattr(qau, self.args["unit_type"][i])
169+
unit = self.args["unit"][i]
170+
if str(unittype.name).lower() == str(unit).lower():
171+
correct += 1
171172
if correct != len(self.args["unit_type"]):
172173
result = self.__create_message("{0} should contain {1} of type {2}".format(prop, self.args["unit_type"],
173174
self.args["unit"]), self.value)

esdlvalidator/validation/tests/test_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_validate_poc_scheme(self):
108108
elif validation.name == "costinformation_exists":
109109
self.assertEqual(len(validation.warnings), 8)
110110
elif validation.name == "investmentcost_per_power_undefined":
111-
self.assertEqual(len(validation.errors), 1)
111+
self.assertEqual(len(validation.errors), 2)
112112
elif validation.name == "fixed_opex_undefined":
113113
self.assertEqual(len(validation.errors), 1)
114114
elif validation.name == "var_opex_undefined":

testdata/esdls/PoC_validator with return network.esdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<profileQuantityAndUnit xsi:type="esdl:QuantityAndUnitType" perUnit="WATT" unit="EURO" id="dbe7fea2-c345-4aab-9df0-3afc27ff1751" description="Cost in EUR/kW" perMultiplier="KILO" physicalQuantity="COST"/>
2222
</installationCosts>
2323
<investmentCosts xsi:type="esdl:SingleValue" value="10.0" id="c162cc99-7c02-4866-8813-b68e72cc1d34">
24-
<profileQuantityAndUnit xsi:type="esdl:QuantityAndUnitType" perUnit="WATT" unit="EURO" id="aeeb19dc-815c-4801-9681-9f6058bbbaf1" description="Cost in EUR/kW" perMultiplier="KILO" physicalQuantity="COST"/>
24+
<profileQuantityAndUnit xsi:type="esdl:QuantityAndUnitType" unit="EURO" id="aeeb19dc-815c-4801-9681-9f6058bbbaf1" description="Cost in EUR/kW" perMultiplier="KILO" physicalQuantity="COST"/>
2525
</investmentCosts>
2626
</costInformation>
2727
</asset>

0 commit comments

Comments
 (0)