def test_str(self): self.assertEqual(typ.default_values("string"), typ.str_get(None)) self.assertEqual(typ.default_values("string"), typ.str_get("")) self.assertEqual(typ.default_values("string"), typ.str_get([])) self.assertEqual(typ.default_values("string"), typ.str_get({})) # Make sure boolean values are properly converted to string. self.assertEqual(typ.str_get(False), 'False') self.assertEqual(typ.str_get(True), 'True')
def test_str(self): self.assertEqual(typ.default_values("string"), typ.str_get(None)) self.assertEqual(typ.default_values("string"), typ.str_get("")) self.assertEqual(typ.default_values("string"), typ.str_get([])) self.assertEqual(typ.default_values("string"), typ.str_get({})) # Make sure boolean values are properly converted to string. self.assertEqual(typ.str_get(False), 'False') self.assertEqual(typ.str_get(True), 'True')
def test_float(self): self.assertEqual(typ.default_values("float"), typ.float_get(None)) self.assertEqual(typ.default_values("float"), typ.float_get("")) self.assertIsInstance(typ.float_get(1), float) self.assertIsInstance(typ.float_get("1.1"), float) self.assertEqual(typ.float_get(123.45), 123.45) with self.assertRaises(TypeError): _ = typ.float_get([]) with self.assertRaises(TypeError): _ = typ.float_get({}) with self.assertRaises(ValueError): _ = typ.float_get("fail")
def test_float(self): self.assertEqual(typ.default_values("float"), typ.float_get(None)) self.assertEqual(typ.default_values("float"), typ.float_get("")) self.assertIsInstance(typ.float_get(1), float) self.assertIsInstance(typ.float_get("1.1"), float) self.assertEqual(typ.float_get(123.45), 123.45) with self.assertRaises(TypeError): _ = typ.float_get([]) with self.assertRaises(TypeError): _ = typ.float_get({}) with self.assertRaises(ValueError): _ = typ.float_get("fail")
def handle_property_import(prop): """ Every odml-ui property requires at least one default value according to its dtype, otherwise the property is currently broken. Further the properties are augmented with 'pseudo_values' which need to be initialized and added to each property. :param prop: imported odml.BaseProperty """ if len(prop.values) < 1: if prop.dtype: prop.values = [default_values(prop.dtype)] else: prop.values = [default_values('string')] create_pseudo_values([prop])
def test_int(self): self.assertEqual(typ.default_values("int"), typ.int_get(None)) self.assertEqual(typ.default_values("int"), typ.int_get("")) self.assertIsInstance(typ.int_get(11), int) self.assertIsInstance(typ.int_get(1.1), int) self.assertIsInstance(typ.int_get("11"), int) self.assertEqual(typ.int_get("123456789012345678901"), 123456789012345678901) self.assertEqual(typ.int_get("-123456789012345678901"), -123456789012345678901) self.assertEqual(typ.int_get("123.45"), 123) with self.assertRaises(TypeError): _ = typ.int_get([]) with self.assertRaises(TypeError): _ = typ.int_get({}) with self.assertRaises(ValueError): _ = typ.int_get("fail")
def test_int(self): self.assertEqual(typ.default_values("int"), typ.int_get(None)) self.assertEqual(typ.default_values("int"), typ.int_get("")) self.assertIsInstance(typ.int_get(11), int) self.assertIsInstance(typ.int_get(1.1), int) self.assertIsInstance(typ.int_get("11"), int) self.assertEqual(typ.int_get("123456789012345678901"), 123456789012345678901) self.assertEqual(typ.int_get("-123456789012345678901"), -123456789012345678901) self.assertEqual(typ.int_get("123.45"), 123) with self.assertRaises(TypeError): _ = typ.int_get([]) with self.assertRaises(TypeError): _ = typ.int_get({}) with self.assertRaises(ValueError): _ = typ.int_get("fail")
def test_bool(self): self.assertEqual(typ.default_values("boolean"), typ.boolean_get(None)) self.assertEqual(typ.default_values("boolean"), typ.boolean_get("")) self.assertEqual(typ.default_values("boolean"), typ.boolean_get([])) self.assertEqual(typ.default_values("boolean"), typ.boolean_get({})) true_values = [True, "TRUE", "true", "T", "t", "1", 1] for val in true_values: self.assertTrue(typ.boolean_get(val)) false_values = [False, "FALSE", "false", "F", "f", "0", 0] for val in false_values: self.assertFalse(typ.boolean_get(val)) with self.assertRaises(ValueError): typ.boolean_get("text") with self.assertRaises(ValueError): typ.boolean_get(12) with self.assertRaises(ValueError): typ.boolean_get(2.1)
def test_bool(self): self.assertEqual(typ.default_values("boolean"), typ.boolean_get(None)) self.assertEqual(typ.default_values("boolean"), typ.boolean_get("")) self.assertEqual(typ.default_values("boolean"), typ.boolean_get([])) self.assertEqual(typ.default_values("boolean"), typ.boolean_get({})) true_values = [True, "TRUE", "true", "T", "t", "1", 1] for val in true_values: self.assertTrue(typ.boolean_get(val)) false_values = [False, "FALSE", "false", "F", "f", "0", 0] for val in false_values: self.assertFalse(typ.boolean_get(val)) with self.assertRaises(ValueError): typ.boolean_get("text") with self.assertRaises(ValueError): typ.boolean_get(12) with self.assertRaises(ValueError): typ.boolean_get(2.1)
def __init__(self, parent, index=None): self._property = parent if index is None: # Instantiate a new odML value index = len(self._property.value) dtype = self.parent.dtype default_value = dtypes.default_values(dtype) self.parent.value.append(default_value) assert (isinstance(index, int)) self._index = index
def __init__(self, parent, index=None): self._property = parent # Instantiate a new odML value if index is None: index = len(self._property.values) dtype = self.parent.dtype default_value = dtypes.default_values(dtype) # property.values returns a copy: we therefore need an in between step # to append a new value and reassign the modified value to the parent # property.values. val_cp = self.parent.values val_cp.append(default_value) self.parent.values = val_cp assert (isinstance(index, int)) self._index = index
def add_property(self, widget, obj_prop_pair): """ popup menu action: add property add a property to the active section """ (obj, prop) = obj_prop_pair if prop is None: name = self.get_new_obj_name(obj.properties, prefix='Unnamed Property') prop = odml.Property(name=name, dtype='string') # The default value part should be put in odML core library prop._value = [dtypes.default_values('string')] create_pseudo_values([prop]) else: prefix = prop.name name = self.get_new_obj_name(obj.properties, prefix=prefix) prop = prop.clone() prop.name = name cmd = commands.AppendValue(obj=obj, val=prop) self.execute(cmd)
def add_property(self, _, obj_prop_pair): """ Add a Property to a selected Section. :param obj_prop_pair: Tuple containing *obj*, an odml.Section, and *prop*, either None or the new odml.Property. """ (obj, prop) = obj_prop_pair if prop is None: name = self.get_new_obj_name(obj.properties, prefix='Unnamed Property') prop = odml.Property(name=name, dtype='string') # The default value part should be put in odML core library prop.values = [dtypes.default_values('string')] create_pseudo_values([prop]) else: prefix = prop.name name = self.get_new_obj_name(obj.properties, prefix=prefix) prop = prop.clone() prop.name = name create_pseudo_values([prop]) cmd = commands.AppendValue(obj=obj, val=prop) self.execute(cmd)