Пример #1
0
    def test_property_real_type(self):
        obj = Attribute()
        self.assertEqual("", obj.real_type)

        obj.ref = "foo"
        self.assertEqual(obj.ref, obj.real_type)

        obj.type = "bar"
        self.assertEqual(obj.type, obj.real_type)

        obj.simple_type = SimpleType()
        self.assertEqual("", obj.real_type)

        obj.simple_type.restriction = Restriction(base="thug")
        self.assertEqual(obj.simple_type.restriction.base, obj.real_type)
Пример #2
0
    def test_property_attr_types(self):
        obj = Attribute()
        self.assertEqual([], 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.simple_type = SimpleType()
        self.assertEqual([], list(obj.attr_types))

        obj.simple_type.restriction = Restriction(base="thug")
        self.assertEqual([obj.simple_type.restriction.base],
                         list(obj.attr_types))
Пример #3
0
    def test_get_restrictions(self):
        obj = Attribute()
        self.assertEqual({}, obj.get_restrictions())

        obj.use = UseType.REQUIRED
        expected = {"max_occurs": 1, "min_occurs": 1, "required": True}
        self.assertEqual(expected, obj.get_restrictions())

        obj.use = UseType.PROHIBITED
        expected = {"prohibited": True}
        self.assertEqual(expected, obj.get_restrictions())

        obj.simple_type = SimpleType(restriction=Restriction(length=Length(
            value=1)))
        expected["length"] = 1
        self.assertEqual(expected, obj.get_restrictions())

        obj.type = "NMTOKENS"
        expected["tokens"] = True
        self.assertEqual(expected, obj.get_restrictions())
Пример #4
0
    def test_property_bases(self):
        obj = Attribute()
        self.assertEqual([], list(obj.bases))

        obj.type = "foo"
        self.assertEqual(["foo"], list(obj.bases))