Exemplo n.º 1
0
    def test_xml_resource_from_file(self):
        with open(self.vh_schema_file) as schema_file:
            resource = XMLResource(schema_file)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag,
                             '{http://www.w3.org/2001/XMLSchema}schema')
            self.assertEqual(resource.url.lower(),
                             FILE_SCHEME.format(self.vh_schema_file).lower())
            self.assertIsNone(resource.document)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))

        with open(self.vh_schema_file) as schema_file:
            resource = XMLResource(schema_file, lazy=False)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag,
                             '{http://www.w3.org/2001/XMLSchema}schema')
            if not IS_WIN_PLATFORM:
                self.assertEqual(resource.url,
                                 FILE_SCHEME.format(self.vh_schema_file))
            self.assertIsInstance(resource.document, ElementTree.ElementTree)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))
Exemplo n.º 2
0
 def test_xml_resource_from_resource(self):
     xml_file = urlopen('file://{}'.format(add_leading_slash(self.vh_xml_file)))
     try:
         resource = XMLResource(xml_file)
         self.assertEqual(resource.source, xml_file)
         self.assertEqual(resource.root.tag, '{http://example.com/vehicles}vehicles')
         self.check_url(resource.url, self.vh_xml_file)
         self.assertIsNone(resource.document)
         self.assertIsNone(resource.text)
         resource.load()
         self.assertTrue(resource.text.startswith('<?xml'))
     finally:
         xml_file.close()
Exemplo n.º 3
0
    def test_xml_resource_copy(self):
        resource = XMLResource(self.vh_xml_file)
        resource2 = resource.copy(defuse='never')
        self.assertEqual(resource2.defuse, 'never')
        resource2 = resource.copy(timeout=30)
        self.assertEqual(resource2.timeout, 30)
        resource2 = resource.copy(lazy=False)
        self.assertFalse(resource2.is_lazy())

        self.assertIsNone(resource2.text)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNotNone(resource.text)
        resource2 = resource.copy()
        self.assertEqual(resource.text, resource2.text)
Exemplo n.º 4
0
 def test_xml_resource_from_resource(self):
     xml_file = urlopen('file://{}'.format(
         add_leading_slash(self.vh_xml_file)))
     try:
         resource = XMLResource(xml_file)
         self.assertEqual(resource.source, xml_file)
         self.assertEqual(resource.root.tag,
                          '{http://example.com/vehicles}vehicles')
         self.check_url(resource.url, self.vh_xml_file)
         self.assertIsNone(resource.document)
         self.assertIsNone(resource.text)
         resource.load()
         self.assertTrue(resource.text.startswith('<?xml'))
     finally:
         xml_file.close()
Exemplo n.º 5
0
    def test_xml_resource_copy(self):
        resource = XMLResource(self.vh_xml_file)
        resource2 = resource.copy(defuse='never')
        self.assertEqual(resource2.defuse, 'never')
        resource2 = resource.copy(timeout=30)
        self.assertEqual(resource2.timeout, 30)
        resource2 = resource.copy(lazy=False)
        self.assertFalse(resource2.is_lazy())

        self.assertIsNone(resource2.text)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNotNone(resource.text)
        resource2 = resource.copy()
        self.assertEqual(resource.text, resource2.text)
Exemplo n.º 6
0
 def test_xml_resource_from_resource(self):
     xml_file = urlopen(FILE_SCHEME.format(self.vh_xml_file))
     try:
         resource = XMLResource(xml_file)
         self.assertEqual(resource.source, xml_file)
         self.assertEqual(resource.root.tag,
                          '{http://example.com/vehicles}vehicles')
         self.assertEqual(resource.url,
                          FILE_SCHEME.format(self.vh_xml_file))
         self.assertIsNone(resource.document)
         self.assertIsNone(resource.text)
         resource.load()
         self.assertTrue(resource.text.startswith('<?xml'))
     finally:
         xml_file.close()
Exemplo n.º 7
0
    def test_xml_resource_from_url(self):
        resource = XMLResource(self.vh_xml_file)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag, '{http://example.com/vehicles}vehicles')
        self.check_url(resource.url, self.vh_xml_file)
        self.assertIsNone(resource.document)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))

        resource = XMLResource(self.vh_xml_file, lazy=False)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag, '{http://example.com/vehicles}vehicles')
        self.check_url(resource.url, self.vh_xml_file)
        self.assertIsInstance(resource.document, ElementTree.ElementTree)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))
Exemplo n.º 8
0
    def test_xml_resource_from_url(self):
        resource = XMLResource(self.vh_xml_file)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        self.check_url(resource.url, self.vh_xml_file)
        self.assertIsNone(resource.document)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))

        resource = XMLResource(self.vh_xml_file, lazy=False)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        self.check_url(resource.url, self.vh_xml_file)
        self.assertIsInstance(resource.document, ElementTree.ElementTree)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))
Exemplo n.º 9
0
    def test_xml_resource_from_file(self):
        with open(self.vh_xsd_file) as schema_file:
            resource = XMLResource(schema_file)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag, '{http://www.w3.org/2001/XMLSchema}schema')
            self.check_url(resource.url, self.vh_xsd_file)
            self.assertIsNone(resource.document)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))

        with open(self.vh_xsd_file) as schema_file:
            resource = XMLResource(schema_file, lazy=False)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag, '{http://www.w3.org/2001/XMLSchema}schema')
            self.check_url(resource.url, self.vh_xsd_file)
            self.assertIsInstance(resource.document, ElementTree.ElementTree)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))
Exemplo n.º 10
0
    def test_xml_resource_from_lxml(self):
        vh_etree = lxml_etree.parse(self.vh_xml_file)
        vh_root = vh_etree.getroot()

        resource = XMLResource(vh_etree)
        self.assertEqual(resource.source, vh_etree)
        self.assertEqual(resource.document, vh_etree)
        self.assertEqual(resource.root.tag, '{http://example.com/vehicles}vehicles')
        self.assertIsNone(resource.url)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNone(resource.text)

        resource = XMLResource(vh_root)
        self.assertEqual(resource.source, vh_root)
        self.assertEqual(resource.root.tag, '{http://example.com/vehicles}vehicles')
        self.assertIsNone(resource.url)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNone(resource.text)
Exemplo n.º 11
0
    def test_xml_resource_from_file(self):
        with open(self.vh_xsd_file) as schema_file:
            resource = XMLResource(schema_file)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag,
                             '{http://www.w3.org/2001/XMLSchema}schema')
            self.check_url(resource.url, self.vh_xsd_file)
            self.assertIsNone(resource.document)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))

        with open(self.vh_xsd_file) as schema_file:
            resource = XMLResource(schema_file, lazy=False)
            self.assertEqual(resource.source, schema_file)
            self.assertEqual(resource.root.tag,
                             '{http://www.w3.org/2001/XMLSchema}schema')
            self.check_url(resource.url, self.vh_xsd_file)
            self.assertIsInstance(resource.document, ElementTree.ElementTree)
            self.assertIsNone(resource.text)
            resource.load()
            self.assertTrue(resource.text.startswith('<xs:schema'))
Exemplo n.º 12
0
    def test_xml_resource_from_lxml(self):
        vh_etree = lxml_etree_parse(self.vh_xml_file)
        vh_root = vh_etree.getroot()

        resource = XMLResource(vh_etree)
        self.assertEqual(resource.source, vh_etree)
        self.assertEqual(resource.document, vh_etree)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        self.assertIsNone(resource.url)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNone(resource.text)

        resource = XMLResource(vh_root)
        self.assertEqual(resource.source, vh_root)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        self.assertIsNone(resource.url)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertIsNone(resource.text)
Exemplo n.º 13
0
    def test_xml_resource_from_url(self):
        resource = XMLResource(self.vh_xml_file)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        self.assertEqual(resource.url.lower(),
                         FILE_SCHEME.format(self.vh_xml_file).lower())
        self.assertIsNone(resource.document)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))

        resource = XMLResource(self.vh_xml_file, lazy=False)
        self.assertEqual(resource.source, self.vh_xml_file)
        self.assertEqual(resource.root.tag,
                         '{http://example.com/vehicles}vehicles')
        if not IS_WIN_PLATFORM:
            self.assertEqual(resource.url,
                             FILE_SCHEME.format(self.vh_xml_file))
        self.assertIsInstance(resource.document, ElementTree.ElementTree)
        self.assertIsNone(resource.text)
        resource.load()
        self.assertTrue(resource.text.startswith('<?xml'))
Exemplo n.º 14
0
 def test_xml_resource_is_loaded(self):
     resource = XMLResource(self.vh_xml_file)
     self.assertFalse(resource.is_loaded())
     resource.load()
     self.assertTrue(resource.is_loaded())
Exemplo n.º 15
0
 def test_xml_resource_is_loaded(self):
     resource = XMLResource(self.vh_xml_file)
     self.assertFalse(resource.is_loaded())
     resource.load()
     self.assertTrue(resource.is_loaded())