コード例 #1
0
    def test_parse_error(self):
        # test document that is loaded but can't be parsed as a schema
        # valid xml non-schema doc
        xmldoc = path.join(path.dirname(path.abspath(__file__)), 'fixtures', 'heaney653.xml')
        # confirm an exception is raised
        self.assertRaises(etree.XMLSchemaParseError, xmlmap.loadSchema, xmldoc)
        # inspect the exception for expected detail in error messages
        try:
            xmlmap.loadSchema(xmldoc)
        except etree.XMLSchemaParseError as parse_err:
            self.assert_('Failed to parse schema %s' % xmldoc in str(parse_err),
                'schema parse exception includes detail about schema document that failed')
            self.assert_('not a schema document' in str(parse_err),
                'schema parse exception includes detail about why parsing failed')

        # schema that attempts to import something inaccessible
        xsd = '''<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:import namespace="http://www.w3.org/1999/xlink"
                schemaLocation="file://cant/catch/me/xlink.xsd"/>
            <xsd:element name="a" type="xlink:simpleLink"/>
        </xsd:schema>
        '''
        FILE = tempfile.NamedTemporaryFile(mode="w")
        FILE.write(xsd)
        FILE.flush()
        # assert this causes the expected exception
        self.assertRaises(etree.XMLSchemaParseError, xmlmap.loadSchema,
                          FILE.name)
        # use try/except to inspect the error message
        try:
            xmlmap.loadSchema(FILE.name)
        except etree.XMLSchemaParseError as parse_err:
            self.assert_('Failed to parse' in str(parse_err),
                'schema parse exception includes detail about what went wrong')
コード例 #2
0
 def test_load_after_parsestring(self):
     # lxml 2.2.7 (used internally by xmlmap) has a bug that causes
     # lxml.etree.parse() to fail after a call to
     # lxml.etree.fromstring(). this causes the second call below to fail
     # unless we work around that bug in xmlmap.
     xmlmap.parseString('<foo/>') # has global side effects in lxml
     xmlmap.loadSchema('http://www.w3.org/2001/xml.xsd') # fails
コード例 #3
0
 def test_ioerror(self):
     # IO error - file path is wrong/incorrect OR network-based schema unavailable
     self.assertRaises(IOError, xmlmap.loadSchema, '/bogus.xsd')
     try:
         xmlmap.loadSchema('/bogus.xsd')
     except IOError as io_err:
         self.assert_('bogus.xsd' in str(io_err),
             'exception message indicates load error on specific document')
     self.assertRaises(IOError, xmlmap.loadSchema, '/bogus.xsd', 'file://some/dir')
コード例 #4
0
 def test_load_schema(self):
     schema = xmlmap.loadSchema('http://www.w3.org/2001/xml.xsd')
     self.assert_(isinstance(schema, etree.XMLSchema),
         'loadSchema should return an etree.XMLSchema object when successful')