Example #1
0
    def test_schema_model(self):
        """
        <xs:group name="schemaTop">
          <xs:choice>
            <xs:group ref="xs:redefinable"/>
            <xs:element ref="xs:element"/>
            <xs:element ref="xs:attribute"/>
            <xs:element ref="xs:notation"/>
          </xs:choice>
        </xs:group>

        <xs:group name="redefinable">
          <xs:choice>
            <xs:element ref="xs:simpleType"/>
            <xs:element ref="xs:complexType"/>
            <xs:element ref="xs:group"/>
            <xs:element ref="xs:attributeGroup"/>
          </xs:choice>
        </xs:group>
        """
        group = self.schema_class.meta_schema.groups['schemaTop']

        model = XsdModelVisitor(group)
        self.assertEqual(model.element, group[0][0][0])
        self.check_advance_false(model)                 # <simpleType> don't match
        self.assertEqual(model.element, group[0][0][1])
        self.check_advance_true(model)                  # <complexType> match
        self.assertIsNone(model.element)

        model.restart()
        self.assertEqual(model.element, group[0][0][0])
        self.check_advance_false(model)                 # <simpleType> don't match
        self.assertEqual(model.element, group[0][0][1])
        self.check_advance_false(model)                 # <complexType> don't match
        self.assertEqual(model.element, group[0][0][2])
        self.check_advance_false(model)                 # <group> don't match
        self.assertEqual(model.element, group[0][0][3])
        self.check_advance_false(model)                 # <attributeGroup> don't match
        self.assertEqual(model.element, group[1])
        self.check_advance_false(model)                 # <element> don't match
        self.assertEqual(model.element, group[2])
        self.check_advance_false(model)                 # <attribute> don't match
        self.assertEqual(model.element, group[3])
        self.check_advance_false(model, [(group, 0, group[0][0][:]+group[1:])])  # <notation> don't match

        model.restart()
        self.assertEqual(model.element, group[0][0][0])
        self.check_advance_false(model)                 # <simpleType> don't match
        self.assertEqual(model.element, group[0][0][1])
        self.check_advance_false(model)                 # <complexType> don't match
        self.assertEqual(model.element, group[0][0][2])
        self.check_advance_false(model)                 # <group> don't match
        self.assertEqual(model.element, group[0][0][3])
        self.check_advance_false(model)                 # <attributeGroup> don't match
        self.assertEqual(model.element, group[1])
        self.check_advance_false(model)                 # <element> don't match
        self.assertEqual(model.element, group[2])
        self.check_advance_true(model)                  # <attribute> match
        self.assertIsNone(model.element)
Example #2
0
    def test_model_group1(self):
        group = self.models_schema.groups['group1']

        model = XsdModelVisitor(group)
        self.assertEqual(model.element, group[0])
        self.check_stop(model)

        model.restart()
        self.assertEqual(model.element, group[0])
        for _ in range(3):
            self.check_advance_false(model)
        self.assertIsNone(model.element)

        model.restart()
        for match in [False, True, False]:
            self.check_advance(model, match)
        self.assertIsNone(model.element)
Example #3
0
    def test_complex_type_model(self):
        """
        <xs:group name="complexTypeModel">
          <xs:choice>
            <xs:element ref="xs:simpleContent"/>
            <xs:element ref="xs:complexContent"/>
            <xs:sequence>
              <xs:group ref="xs:typeDefParticle" minOccurs="0"/>
              <xs:group ref="xs:attrDecls"/>
            </xs:sequence>
          </xs:choice>
        </xs:group>

        <xs:group name="typeDefParticle">
          <xs:choice>
            <xs:element name="group" type="xs:groupRef"/>
            <xs:element ref="xs:all"/>
            <xs:element ref="xs:choice"/>
            <xs:element ref="xs:sequence"/>
          </xs:choice>
        </xs:group>
        """
        group = self.schema_class.meta_schema.groups['complexTypeModel']

        model = XsdModelVisitor(group)
        self.assertEqual(model.element, group[0])
        self.check_advance_true(model)                  # <simpleContent> match
        self.assertIsNone(model.element)

        model.restart()
        self.assertEqual(model.element, group[0])
        self.check_advance_false(model)
        self.check_advance_true(model)                  # <complexContent> match
        self.assertIsNone(model.element)

        model.restart()
        self.assertEqual(model.element, group[0])
        for match in [False, False, False, False, True]:
            self.check_advance(model, match)            # <all> match
        self.check_stop(model)
        self.assertIsNone(model.element)

        model.restart()
        self.assertEqual(model.element, group[0])
        for match in [False, False, False, False, True, False, True, False, False, False]:
            self.check_advance(model, match)            # <all> match, <attributeGroup> match
        self.assertIsNone(model.element)