def test_validate_concept_value(self): concept = taxonomy.Element() concept.id = "SomeId" concept.nillable = False self.assertFalse(validator.validate_concept_value(concept, None)) concept.nillable = True self.assertTrue(validator.validate_concept_value(concept, None)) concept.type_name = "xbrli:booleanItemType" self.assertFalse(validator.validate_concept_value(concept, "Arf")) self.assertFalse(validator.validate_concept_value(concept, 52)) self.assertTrue(validator.validate_concept_value(concept, False)) self.assertTrue(validator.validate_concept_value(concept, True)) concept.type_name = "xbrli:integerItemType" self.assertFalse(validator.validate_concept_value(concept, "Arf")) self.assertFalse(validator.validate_concept_value(concept, True)) self.assertTrue(validator.validate_concept_value(concept, -52)) self.assertTrue(validator.validate_concept_value(concept, 52)) concept.type_name = "xbrli:stringItemType" self.assertFalse(validator.validate_concept_value(concept, False)) self.assertFalse(validator.validate_concept_value(concept, 52)) self.assertTrue(validator.validate_concept_value(concept, "Arf")) self.assertTrue(validator.validate_concept_value(concept, "")) concept.id = "SomeIdentifier" self.assertFalse(validator.validate_concept_value(concept, "Arf")) self.assertTrue( validator.validate_concept_value(concept, identifier.identifier()))
def startElement(self, name, attrs): if name == "xs:element": element = taxonomy.Element() for item in attrs.items(): if item[0] == "abstract": if item[1] == "false": element.abstact = False else: element.abstract = True elif item[0] == "id": # Turn the first underscore (only the first) into # a colon. For example, the concept named # solar:InverterPowerLevel10PercentMember_1 appears # in the id field as # solar_InverterPowerLevel10PercentMember_1. We want # to replace the first underscore but not the second. element.id = item[1].replace("_", ":", 1) elif item[0] == "name": element.name = item[1] elif item[0] == "nillable": if item[1] == "false": element.nillable = False else: element.nillable = True elif item[0] == "solar:periodIndependent": element.period_independent = item[1] elif item[0] == "substitutionGroup": element.substitution_group = item[1] elif item[0] == "type": element.type_name = item[1] elif item[0] == "xbrli:periodType": element.period_type = item[1] self._elements[element.id] = element
def startElement(self, name, attrs): if name == "xs:element": element = taxonomy.Element() for item in attrs.items(): if item[0] == "abstract": if item[1] == "false": element.abstact = False else: element.abstract = True elif item[0] == "id": element.id = item[1].replace("_", ":") elif item[0] == "name": element.name = item[1] elif item[0] == "nillable": if item[1] == "false": element.nillable = False else: element.nillable = True elif item[0] == "solar:periodIndependent": element.period_independent = item[1] elif item[0] == "substitutionGroup": element.substitution_group = item[1] elif item[0] == "type": element.type_name = item[1] elif item[0] == "xbrli:periodType": element.period_type = item[1] self._elements[element.id] = element
def test_element(self): self.assertIsInstance(taxonomy.Element(), taxonomy.Element)