Example #1
0
    def test_simple_attributes(self):
        sec_name = "sec name"
        sec_type = "sec type"
        sec_def = "an odml test section"
        sec_ref = "from over there"

        sec = Section(name=sec_name, type=sec_type, definition=sec_def, reference=sec_ref)

        self.assertEqual(sec.name, sec_name)
        self.assertEqual(sec.type, sec_type)
        self.assertEqual(sec.definition, sec_def)
        self.assertEqual(sec.reference, sec_ref)

        # Test setting attributes
        sec.name = "%s_edit" % sec_name
        self.assertEqual(sec.name, "%s_edit" % sec_name)
        sec.type = "%s_edit" % sec_type
        self.assertEqual(sec.type, "%s_edit" % sec_type)
        sec.definition = "%s_edit" % sec_def
        self.assertEqual(sec.definition, "%s_edit" % sec_def)
        sec.reference = "%s_edit" % sec_ref
        self.assertEqual(sec.reference, "%s_edit" % sec_ref)

        # Test setting attributes to None when '' is passed.
        sec.reference = ""
        self.assertIsNone(sec.reference)
        sec.definition = ""
        self.assertIsNone(sec.definition)
Example #2
0
    def test_merge_check(self):
        # -- Root level Section checks

        # Test empty Section check
        source = Section(name="source")
        destination = Section(name="destination")

        destination.merge_check(source, True)

        # Test definition check
        source = Section(name="source", definition="def")
        destination = Section(name="destination", definition="def")

        destination.merge_check(source, True)
        source.definition = "other def"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # Test reference check
        source = Section(name="source", reference="ref")
        destination = Section(name="destination", reference="ref")

        destination.merge_check(source, True)
        source.reference = "other ref"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # -- First child level Section checks
        source = Section(name="source")
        destination = Section(name="destination")

        s_sec_one = Section(name="lvl", type="one",
                            reference="ref", definition="def", parent=source)
        s_sec_two = Section(name="unrelated", type="one",
                            reference="one", definition="one", parent=source)

        d_sec_one = Section(name="lvl", type="one",
                            reference="ref", definition="def", parent=destination)
        d_sec_two = Section(name="unrelated", type="two",
                            reference="two", definition="two", parent=destination)

        # Test Section child level definition check
        destination.merge_check(source, True)
        s_sec_one.definition = "other def"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # Test Section child level reference check
        s_sec_one.definition = "def"
        s_sec_one.reference = "other ref"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # -- Second child level Section checks
        source = Section(name="source")
        destination = Section(name="destination")

        s_sec_one = Section(name="lvl", type="one",
                            reference="ref", definition="def", parent=source)
        s_subsec_one = Section(name="lvl", type="two",
                               reference="ref2", definition="def2", parent=s_sec_one)
        s_sec_two = Section(name="unrelated", type="one",
                            reference="one", definition="one", parent=source)
        s_subsec_two = Section(name="lvl", type="two",
                               reference="none1", definition="none1", parent=s_sec_two)

        d_sec_one = Section(name="lvl", type="one",
                            reference="ref", definition="def", parent=destination)
        d_subsec_one = Section(name="lvl", type="two",
                               reference="ref2", definition="def2", parent=d_sec_one)
        d_sec_two = Section(name="unrelated", type="two",
                            reference="two", definition="two", parent=destination)
        d_subsec_two = Section(name="lvl", type="two",
                               reference="none2", definition="none2", parent=d_sec_two)

        # Test Section 2nd child level definition check
        # Check no definition/reference ValueError between s_subsec_two and d_subsec_one
        # since their parents will not be merged.
        destination.merge_check(source, True)

        # Raise a definition ValueError between s_subsec_one and d_subsec_one
        # since their parents will be merged.
        s_subsec_one.definition = "other def"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # Test Section 2nd child level reference check
        s_subsec_one.definition = "def2"

        # Raise a reference ValueError between s_subsec_one and d_subsec_one
        # since their parents will be merged.
        s_subsec_one.reference = "other ref"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # -- Root level Property checks
        # All Property checks will only test unit failure in the Section merge context.
        # Other failures are covered by the specific Property merge check tests.
        source = Section(name="source")
        destination = Section(name="destination")

        s_prop = Property(name="prop", parent=source)
        d_prop = Property(name="prop", parent=destination)

        destination.merge_check(source, True)
        s_prop.unit = "Hz"
        d_prop.unit = "s"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # -- First child level Property checks
        source = Section(name="source")
        destination = Section(name="destination")

        s_prop_one = Property(name="lvl one", unit="Hz", parent=source)
        s_prop_two = Property(name="unrelated one", unit="one", parent=source)

        d_prop_one = Property(name="lvl one", unit="Hz", parent=destination)
        d_prop_two = Property(name="unrelated two", unit="two", parent=destination)

        # Test Property child level check
        destination.merge_check(source, True)

        # Test raise ValueError between s_prop_one and d_prop_one
        s_prop_one.unit = "other unit"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)

        # -- Second child level Property checks
        source = Section(name="source")
        destination = Section(name="destination")

        s_sec_one = Section(name="lvl", type="one", parent=source)
        s_subprop_one = Property(name="lvl one", unit="Hz", parent=s_sec_one)

        s_sec_two = Section(name="unrelated", type="one", parent=source)
        s_subprop_two = Property(name="unrelated one", unit="one", parent=s_sec_two)

        d_sec_one = Section(name="lvl", type="one", parent=destination)
        d_subprop_one = Property(name="lvl one", unit="Hz", parent=d_sec_one)

        d_sec_two = Section(name="unrelated", type="two", parent=destination)
        d_subprop_two = Property(name="unrelated one", unit="two", parent=d_sec_two)

        # Test Property 2nd child level definition check
        # Check no unit ValueError between s_subprop_two and d_subprop_one
        # since their parents will not be merged.
        destination.merge_check(source, True)

        # Raise a unit ValueError between s_subprop_one and d_subprop_one
        # since their parents will be merged.
        s_subprop_one.unit = "other unit"
        with self.assertRaises(ValueError):
            destination.merge_check(source, True)