def validate_units(parameter): """ Check if the parameter attribute units exists (It is required) and reports the value and if it is valid unit name. """ LOGGER.info("Checking parameter attribute: units") if parameter.data_type in ('Discrete', 'Multi-state', 'Enumerated Discrete'): return if parameter.units is None: LOGGER.warn("No attribute 'units' for '%s'. Attribute is Required.", parameter.name) else: if type(parameter.units).__name__ not in ['str', 'string', 'string_']: LOGGER.error("'units' expected to be a string, got %s", type(parameter.units).__name__) if parameter.units == '': LOGGER.info("Attribute 'units' is present for '%s', but empty.", parameter.name) elif parameter.units in ut.available(): LOGGER.info("Attribute 'units' is present for '%s' and has a " "valid unit of '%s'.", parameter.name, parameter.units) else: LOGGER.error("Attribute 'units' is present for '%s', but has an " "unknown unit of '%s'.", parameter.name, parameter.units)
def validate_units(parameter): """ Check if the parameter attribute units exists (It is required) and reports the value and if it is valid unit name. """ LOGGER.info("Checking parameter attribute: units") if parameter.data_type in ('Discrete', 'Multi-state', 'Enumerated Discrete'): return if parameter.units is None: LOGGER.warn("'units': No attribute for '%s'. Attribute is Required.", parameter.name) else: if type(parameter.units).__name__ not in ['str', 'string', 'string_']: LOGGER.error("'units': Attribute expected to be a string, got %s", type(parameter.units).__name__) if parameter.units == '': LOGGER.info("'units': Attribute is present for '%s', but empty.", parameter.name) available = parameter.units in ut.available() corrections = ut.UNIT_CORRECTIONS.get(parameter.units) converting = ut.STANDARD_CONVERSIONS.get((corrections or parameter.units)) if converting: convserion_desc = ut.UNIT_DESCRIPTIONS.get(converting) LOGGER.error("'units': Attribute is present for '%s', but from " "the value ('%s') the parameter data requires " "converting to %s with a units value of '%s'.", parameter.name, parameter.units, convserion_desc, converting) elif corrections: LOGGER.error("'units': Attribute is present for '%s', but the " "value ('%s') needs to be updated to '%s'.", parameter.name, parameter.units, corrections) elif available: LOGGER.info("'units': Attribute is present for '%s' and has a " "valid unit of '%s'.", parameter.name, parameter.units) else: LOGGER.error("'units': Attribute is present for '%s', but has an " "unknown unit of '%s'.", parameter.name, parameter.units)
def test__vapp__weight_unit__invalid(self): invalid = set(ut.available()) - set( (None, ut.KG, ut.LB, ut.SLUG, ut.TONNE)) for unit in invalid: self.vs.weight_unit = unit self.assertRaises(KeyError, self.vs.vapp, '15', 120000)
def test__vapp__weight_unit__invalid(self): invalid = set(ut.available()) - set((None, ut.KG, ut.LB, ut.TONNE)) for unit in invalid: self.vs.weight_unit = unit self.assertRaises(KeyError, self.vs.vapp, '15', 120000)