예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    def test_merge_check(self):
        # Test dtype check
        source = Property(name="source", dtype="string")
        destination = Property(name="destination", dtype="string")

        destination.merge_check(source)
        source.dtype = "int"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value check
        source = Property(name="source", value=[1, 2, 3])
        destination = Property(name="destination", value=[4, 5, 6])
        destination.merge_check(source)

        # Test value convertable
        source = Property(name="source", value=["7", "8"])
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value not convertable
        source = Property(name="source", value=["nine", "ten"])
        with self.assertRaises(ValueError):
            destination.merge_check(source)
        with self.assertRaises(ValueError):
            destination.merge_check(source, False)

        # Test unit check
        source = Property(name="source", unit="Hz")
        destination = Property(name="destination", unit="Hz")

        destination.merge_check(source)
        source.unit = "s"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test uncertainty check
        source = Property(name="source", uncertainty=0.0)
        destination = Property(name="destination", uncertainty=0.0)

        destination.merge_check(source)
        source.uncertainty = 10.0
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test definition check
        source = Property(name="source", definition="Freude\t schoener\nGoetterfunken\n")
        destination = Property(name="destination",
                               definition="FREUDE schoener GOETTERfunken")

        destination.merge_check(source)
        source.definition = "Freunde schoender Goetterfunken"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test reference check
        source = Property(name="source", reference="portal.g-node.org")
        destination = Property(name="destination", reference="portal.g-node.org")

        destination.merge_check(source)
        source.reference = "portal.g-node.org/odml/terminologies/v1.1"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value origin check
        source = Property(name="source", value_origin="file")
        destination = Property(name="destination", value_origin="file")

        destination.merge_check(source)
        source.value_origin = "other file"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)
예제 #4
0
    def test_merge_check(self):
        # Test dtype check
        source = Property(name="source", dtype="string")
        destination = Property(name="destination", dtype="string")

        destination.merge_check(source)
        source.dtype = "int"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value check
        source = Property(name="source", value=[1, 2, 3])
        destination = Property(name="destination", value=[4, 5, 6])
        destination.merge_check(source)

        # Test value convertable
        source = Property(name="source", value=["7", "8"])
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value not convertable
        source = Property(name="source", value=["nine", "ten"])
        with self.assertRaises(ValueError):
            destination.merge_check(source)
        with self.assertRaises(ValueError):
            destination.merge_check(source, False)

        # Test unit check
        source = Property(name="source", unit="Hz")
        destination = Property(name="destination", unit="Hz")

        destination.merge_check(source)
        source.unit = "s"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test uncertainty check
        source = Property(name="source", uncertainty=0.0)
        destination = Property(name="destination", uncertainty=0.0)

        destination.merge_check(source)
        source.uncertainty = 10.0
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test definition check
        source = Property(name="source", definition="Freude\t schoener\nGoetterfunken\n")
        destination = Property(name="destination",
                               definition="FREUDE schoener GOETTERfunken")

        destination.merge_check(source)
        source.definition = "Freunde schoender Goetterfunken"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test reference check
        source = Property(name="source", reference="portal.g-node.org")
        destination = Property(name="destination", reference="portal.g-node.org")

        destination.merge_check(source)
        source.reference = "portal.g-node.org/odml/terminologies/v1.1"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)

        # Test value origin check
        source = Property(name="source", value_origin="file")
        destination = Property(name="destination", value_origin="file")

        destination.merge_check(source)
        source.value_origin = "other file"
        with self.assertRaises(ValueError):
            destination.merge_check(source)

        destination.merge_check(source, False)