Beispiel #1
0
    def test_concepts_can_type_check(self):
        # Try passing in wrong data type to a typed concept:
        doc = Entrypoint("CutSheet", self.taxonomy)
        concept = doc.get_concept_by_name(
            "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_by_name("solar:TransformerStyle")  # string
        self.assertTrue(concept.validate_datatype("Autobot"))
        self.assertTrue(concept.validate_datatype("Decepticon"))
        self.assertFalse(concept.validate_datatype(99.99))

        concept = doc.get_concept_by_name(
            "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_by_name("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"))
Beispiel #2
0
    def test_concepts_load_metadata(self):
        doc = Entrypoint("CutSheet", self.taxonomy)

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

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

        self.assertEqual(device.get_metadata("period_type"),
                         PeriodType.duration)
        self.assertEqual(device.get_metadata("type_name"),
                         "solar-types:deviceItemType")
        self.assertEqual(device.get_metadata("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)