コード例 #1
0
    def test_concepts_can_type_check(self):
        # Try passing in wrong data type to a typed concept:
        doc = OBInstance("CutSheet", self.taxonomy)
        concept = doc.get_concept(
            "solar:TrackerNumberOfControllers")  # integer
        self.assertTrue(concept.validate_datatype("3"))
        self.assertFalse(concept.validate_datatype("3.5"))
        self.assertFalse(concept.validate_datatype("a few"))

        concept = doc.get_concept("solar:TransformerStyle")  # string
        self.assertTrue(concept.validate_datatype("Autobot"))
        self.assertTrue(concept.validate_datatype("Decepticon"))
        #TODO: 99.99 can be converted to valid string
        self.assertTrue(concept.validate_datatype(99.99))

        concept = doc.get_concept("solar:TransformerDesignFactor")  # decimal
        self.assertTrue(concept.validate_datatype("0.99"))
        self.assertTrue(concept.validate_datatype("1"))
        self.assertFalse(concept.validate_datatype("pretty good"))

        concept = doc.get_concept("solar:MeterRevenueGrade")  # boolean
        self.assertTrue(concept.validate_datatype("True"))
        self.assertTrue(concept.validate_datatype("False"))
        self.assertTrue(concept.validate_datatype(True))
        self.assertTrue(concept.validate_datatype(False))
        self.assertFalse(concept.validate_datatype("yes"))
        self.assertFalse(concept.validate_datatype("7"))
コード例 #2
0
    def test_concepts_load_details(self):
        doc = OBInstance("CutSheet", self.taxonomy)

        frequency = doc.get_concept("solar:RevenueMeterFrequency")
        device = doc.get_concept("solar:TypeOfDevice")

        # Metadata such as period-type, type-name, and nillable should be available
        # on the concept objects:
        self.assertEqual(frequency.get_details("period_type"),
                         PeriodType.duration)
        self.assertEqual(frequency.get_details("type_name"),
                         "num-us:frequencyItemType")
        self.assertEqual(frequency.get_details("nillable"), True)

        self.assertEqual(device.get_details("period_type"),
                         PeriodType.duration)
        self.assertEqual(device.get_details("type_name"),
                         "solar-types:deviceItemType")
        self.assertEqual(device.get_details("nillable"), True)

        # Parents and children should be correct:
        self.assertEqual(device.parent.name, 'solar:CutSheetDetailsLineItems')
        self.assertEqual(frequency.parent.name,
                         'solar:ProductIdentifierMeterAbstract')
        self.assertEqual(len(device.children), 0)
        self.assertEqual(len(frequency.children), 0)