diff --git a/odml/property.py b/odml/property.py index e6fb3a5d..d3ea8b8d 100644 --- a/odml/property.py +++ b/odml/property.py @@ -329,6 +329,14 @@ def uncertainty(self): def uncertainty(self, new_value): if new_value == "": new_value = None + + if new_value and not isinstance(new_value, (int, float)): + try: + new_value = float(new_value) + except ValueError: + raise ValueError("odml.Property.uncertainty: passed uncertainty '%s' " + "is not float or int." % new_value) + self._uncertainty = new_value @property diff --git a/test/test_property.py b/test/test_property.py index 58285a5e..0877e3b3 100644 --- a/test/test_property.py +++ b/test/test_property.py @@ -14,7 +14,7 @@ def test_simple_attributes(self): p_name = "propertyName" p_origin = "from over there" p_unit = "pears" - p_uncertainty = "+-12" + p_uncertainty = "12" p_ref = "4 8 15 16 23" p_def = "an odml test property" p_dep = "yes" @@ -40,8 +40,8 @@ def test_simple_attributes(self): self.assertEqual(prop.value_origin, "%s_edit" % p_origin) prop.unit = "%s_edit" % p_unit self.assertEqual(prop.unit, "%s_edit" % p_unit) - prop.uncertainty = "%s_edit" % p_uncertainty - self.assertEqual(prop.uncertainty, "%s_edit" % p_uncertainty) + prop.uncertainty = 13 + self.assertEqual(prop.uncertainty, 13.0) prop.reference = "%s_edit" % p_ref self.assertEqual(prop.reference, "%s_edit" % p_ref) prop.definition = "%s_edit" % p_def diff --git a/test/test_rdf_writer.py b/test/test_rdf_writer.py index 9666a01b..0d1d30a6 100644 --- a/test/test_rdf_writer.py +++ b/test/test_rdf_writer.py @@ -159,7 +159,7 @@ def test_adding_other_entities_properties(self): p_unit = "u1" p_name = "p1" p_def = "p comment" - p_uncertainty = "un" + p_uncertainty = 13.0 p_dtype = "string" p_value_origin = "value" p_ref = "p_ref"