def test_property_raw_type(self): obj = Element(ns_map={"xs": Namespace.XS.uri}) self.assertEqual("xs:anyType", obj.raw_type) obj.type = "foo" self.assertEqual("foo", obj.raw_type) obj.type = None obj.complex_type = ComplexType() self.assertIsNone(obj.raw_type)
def test_property_bases(self): obj = Element() obj.ns_map["xs"] = Namespace.XS.uri self.assertEqual(["xs:anyType"], list(obj.bases)) obj.type = "foo" self.assertEqual(["foo"], list(obj.bases)) obj.type = None obj.complex_type = ComplexType() self.assertEqual([], list(obj.bases))
def test_get_restrictions(self): obj = Element(min_occurs=1, max_occurs=1) expected = {"min_occurs": 1, "max_occurs": 1} self.assertEqual(expected, obj.get_restrictions()) obj.simple_type = SimpleType(restriction=Restriction(length=Length(value=9))) expected["length"] = 9 self.assertEqual(expected, obj.get_restrictions()) obj.nillable = False self.assertEqual(expected, obj.get_restrictions()) obj.nillable = True expected["nillable"] = True self.assertEqual(expected, obj.get_restrictions()) obj.type = "NMTOKENS" expected["tokens"] = True self.assertEqual(expected, obj.get_restrictions())
def test_property_real_type(self): obj = Element() self.assertEqual("", obj.real_type) # Inner classes depend on the this to be None obj.complex_type = ComplexType() self.assertEqual("", obj.real_type) restriction = Restriction(base="xs:int") obj.simple_type = SimpleType(restriction=restriction) self.assertEqual(restriction.base, obj.real_type) obj.ref = "foo" self.assertEqual(obj.ref, obj.real_type) obj.type = "bar" self.assertEqual(obj.type, obj.real_type) obj.alternatives.append(Alternative(type="foo")) obj.alternatives.append(Alternative(type="bar")) obj.alternatives.append(Alternative(type="thug")) self.assertEqual("bar foo thug", obj.real_type)
def test_property_attr_types(self): obj = Element() self.assertEqual([], list(obj.attr_types)) # Inner classes depend on the this to be None obj.complex_type = ComplexType() self.assertEqual([], list(obj.attr_types)) restriction = Restriction(base="xs:int") obj.simple_type = SimpleType(restriction=restriction) self.assertEqual([restriction.base], list(obj.attr_types)) obj.ref = "foo" self.assertEqual([obj.ref], list(obj.attr_types)) obj.type = "bar" self.assertEqual([obj.type], list(obj.attr_types)) obj.alternatives.append(Alternative(type="foo")) obj.alternatives.append(Alternative(type="bar")) obj.alternatives.append(Alternative(type="thug")) self.assertEqual(["bar", "foo", "bar", "thug"], list(obj.attr_types))