def test_xml_resource_iter(self):
        resource = XMLResource(self.schema_class.meta_schema.source.url,
                               lazy=False)
        self.assertFalse(resource.is_lazy())
        lazy_resource = XMLResource(self.schema_class.meta_schema.source.url)
        self.assertTrue(lazy_resource.is_lazy())

        tags = [x.tag for x in resource.iter()]
        self.assertEqual(len(tags), 1390)
        self.assertEqual(tags[0], '{%s}schema' % XSD_NAMESPACE)

        lazy_tags = [x.tag for x in lazy_resource.iter()]
        self.assertEqual(len(lazy_tags), 1390)
        self.assertEqual(lazy_tags[-1], '{%s}schema' % XSD_NAMESPACE)
        self.assertNotEqual(tags, lazy_tags)

        tags = [
            x.tag for x in resource.iter('{%s}complexType' % XSD_NAMESPACE)
        ]
        self.assertEqual(len(tags), 56)
        self.assertEqual(tags[0], '{%s}complexType' % XSD_NAMESPACE)
        self.assertListEqual(tags, [
            x.tag
            for x in lazy_resource.iter('{%s}complexType' % XSD_NAMESPACE)
        ])
Beispiel #2
0
    def test_xml_resource_iterfind(self):
        namespaces = {'xs': XSD_NAMESPACE}
        resource = XMLResource(self.schema_class.meta_schema.source.url,
                               lazy=False)
        self.assertFalse(resource.is_lazy())
        lazy_resource = XMLResource(self.schema_class.meta_schema.source.url)
        self.assertTrue(lazy_resource.is_lazy())

        # Note: Element change with lazy resource so compare only tags

        tags = [x.tag for x in resource.iterfind()]
        self.assertEqual(len(tags), 1)
        self.assertEqual(tags[0], '{%s}schema' % XSD_NAMESPACE)
        self.assertListEqual(tags, [x.tag for x in lazy_resource.iterfind()])

        tags = [x.tag for x in resource.iterfind(path='.')]
        self.assertEqual(len(tags), 1)
        self.assertEqual(tags[0], '{%s}schema' % XSD_NAMESPACE)
        self.assertListEqual(tags,
                             [x.tag for x in lazy_resource.iterfind(path='.')])

        tags = [x.tag for x in resource.iterfind(path='*')]
        self.assertEqual(len(tags), 156)
        self.assertEqual(tags[0], '{%s}annotation' % XSD_NAMESPACE)
        self.assertListEqual(tags,
                             [x.tag for x in lazy_resource.iterfind(path='*')])

        tags = [x.tag for x in resource.iterfind('xs:complexType', namespaces)]
        self.assertEqual(len(tags), 35)
        self.assertTrue(
            all(t == '{%s}complexType' % XSD_NAMESPACE for t in tags))
        self.assertListEqual(tags, [
            x.tag for x in lazy_resource.iterfind('xs:complexType', namespaces)
        ])

        tags = [
            x.tag
            for x in resource.iterfind('. /. / xs:complexType', namespaces)
        ]
        self.assertEqual(len(tags), 35)
        self.assertTrue(
            all(t == '{%s}complexType' % XSD_NAMESPACE for t in tags))
        self.assertListEqual(tags, [
            x.tag for x in lazy_resource.iterfind('. /. / xs:complexType',
                                                  namespaces)
        ])
Beispiel #3
0
 def test_xml_resource_is_lazy(self):
     resource = XMLResource(self.vh_xml_file)
     self.assertTrue(resource.is_lazy())
     resource = XMLResource(self.vh_xml_file, lazy=False)
     self.assertFalse(resource.is_lazy())
Beispiel #4
0
 def test_xml_resource_is_lazy(self):
     resource = XMLResource(self.vh_xml_file)
     self.assertTrue(resource.is_lazy())
     resource = XMLResource(self.vh_xml_file, lazy=False)
     self.assertFalse(resource.is_lazy())