def test_name(self): # Test id is used when name is not provided prop = Property() self.assertIsNotNone(prop.name) self.assertEqual(prop.name, prop.id) # Test name is properly set on init name = "rumpelstilzchen" prop = Property(name) self.assertEqual(prop.name, name) # Test name can be properly set on single and connected Properties prop = Property() self.assertNotEqual(prop.name, "prop") prop.name = "prop" self.assertEqual(prop.name, "prop") sec = Section() prop_a = Property(parent=sec) self.assertNotEqual(prop_a.name, "prop_a") prop_a.name = "prop_a" self.assertEqual(prop_a.name, "prop_a") # Test property name can be changed with siblings prop_b = Property(name="prop_b", parent=sec) self.assertEqual(prop_b.name, "prop_b") prop_b.name = "prop" self.assertEqual(prop_b.name, "prop") # Test property name set will fail on existing sibling with same name with self.assertRaises(KeyError): prop_b.name = "prop_a" self.assertEqual(prop_b.name, "prop")
def test_name(self): # Test id is used when name is not provided p = Property() self.assertIsNotNone(p.name) self.assertEqual(p.name, p.id) # Test name is properly set on init name = "rumpelstilzchen" p = Property(name) self.assertEqual(p.name, name) # Test name can be properly set on single and connected Properties prop = Property() self.assertNotEqual(prop.name, "prop") prop.name = "prop" self.assertEqual(prop.name, "prop") sec = Section() prop_a = Property(parent=sec) self.assertNotEqual(prop_a.name, "prop_a") prop_a.name = "prop_a" self.assertEqual(prop_a.name, "prop_a") # Test property name can be changed with siblings prop_b = Property(name="prop_b", parent=sec) self.assertEqual(prop_b.name, "prop_b") prop_b.name = "prop" self.assertEqual(prop_b.name, "prop") # Test property name set will fail on existing sibling with same name with self.assertRaises(KeyError): prop_b.name = "prop_a" self.assertEqual(prop_b.name, "prop")
def test_comparison(self): p_name = "propertyName" p_origin = "from over there" p_unit = "pears" p_uncertainty = "+-12" p_ref = "4 8 15 16 23" p_def = "an odml test property" p_dep = "yes" p_dep_val = "42" p_val = ["a", "b"] prop_a = Property(name=p_name, value_origin=p_origin, unit=p_unit, uncertainty=p_uncertainty, reference=p_ref, definition=p_def, dependency=p_dep, dependency_value=p_dep_val, value=p_val) prop_b = Property(name=p_name, value_origin=p_origin, unit=p_unit, uncertainty=p_uncertainty, reference=p_ref, definition=p_def, dependency=p_dep, dependency_value=p_dep_val, value=p_val) self.assertEqual(prop_a, prop_b) prop_b.name = 'newPropertyName' self.assertNotEqual(prop_a, prop_b)
def test_simple_attributes(self): p_name = "propertyName" p_origin = "from over there" p_unit = "pears" p_uncertainty = "12" p_ref = "4 8 15 16 23" p_def = "an odml test property" p_dep = "yes" p_dep_val = "42" prop = Property(name=p_name, value_origin=p_origin, unit=p_unit, uncertainty=p_uncertainty, reference=p_ref, definition=p_def, dependency=p_dep, dependency_value=p_dep_val) self.assertEqual(prop.name, p_name) self.assertEqual(prop.value_origin, p_origin) self.assertEqual(prop.unit, p_unit) self.assertEqual(prop.uncertainty, p_uncertainty) self.assertEqual(prop.reference, p_ref) self.assertEqual(prop.definition, p_def) self.assertEqual(prop.dependency, p_dep) self.assertEqual(prop.dependency_value, p_dep_val) # Test setting attributes prop.name = "%s_edit" % p_name self.assertEqual(prop.name, "%s_edit" % p_name) prop.value_origin = "%s_edit" % p_origin 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 = 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 self.assertEqual(prop.definition, "%s_edit" % p_def) prop.dependency = "%s_edit" % p_dep self.assertEqual(prop.dependency, "%s_edit" % p_dep) prop.dependency_value = "%s_edit" % p_dep_val self.assertEqual(prop.dependency_value, "%s_edit" % p_dep_val) # Test setting attributes to None when '' is passed. prop.value_origin = "" self.assertIsNone(prop.value_origin) prop.unit = "" self.assertIsNone(prop.unit) prop.uncertainty = "" self.assertIsNone(prop.uncertainty) prop.reference = "" self.assertIsNone(prop.reference) prop.definition = "" self.assertIsNone(prop.definition) prop.dependency = "" self.assertIsNone(prop.dependency) prop.dependency_value = "" self.assertIsNone(prop.dependency_value)