本文整理汇总了Python中kiwi.xml_description.XMLDescription.get_extension_xml_data方法的典型用法代码示例。如果您正苦于以下问题:Python XMLDescription.get_extension_xml_data方法的具体用法?Python XMLDescription.get_extension_xml_data怎么用?Python XMLDescription.get_extension_xml_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.xml_description.XMLDescription
的用法示例。
在下文中一共展示了XMLDescription.get_extension_xml_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSchema
# 需要导入模块: from kiwi.xml_description import XMLDescription [as 别名]
# 或者: from kiwi.xml_description.XMLDescription import get_extension_xml_data [as 别名]
#.........这里部分代码省略.........
mock_validation_report.xpath = mock.Mock(
return_value=[
validation_report(text='wrong attribute 1'),
validation_report(text='wrong attribute 2')
]
)
mock_sch_validate.validation_report = mock_validation_report
mock_relax.return_value = mock_rng_validate
mock_schematron.return_value = mock_sch_validate
command_run = namedtuple(
'command', ['output', 'error', 'returncode']
)
mock_command.return_value = command_run(
output='jing output\n',
error='',
returncode=1
)
self.description_from_data.load()
@raises(KiwiDescriptionInvalid)
@patch('lxml.isoschematron.Schematron')
@patch('lxml.etree.RelaxNG')
@patch('lxml.etree.parse')
@patch('kiwi.system.setup.Command.run')
@patch.object(XMLDescription, '_xsltproc')
def test_load_schema_description_from_data_invalid_no_jing(
self, mock_xslt, mock_command, mock_parse, mock_relax, mock_schematron
):
mock_rng_validate = mock.Mock()
mock_rng_validate.validate = mock.Mock(
return_value=False
)
mock_sch_validate = mock.Mock()
mock_sch_validate.validate = mock.Mock(
return_value=True
)
mock_relax.return_value = mock_rng_validate
mock_schematron.return_value = mock_sch_validate
mock_command.side_effect = KiwiCommandNotFound('No jing command')
self.description_from_data.load()
@raises(KiwiDataStructureError)
@patch('lxml.isoschematron.Schematron')
@patch('lxml.etree.RelaxNG')
@patch('lxml.etree.parse')
@patch('kiwi.xml_parse.parse')
@patch.object(XMLDescription, '_xsltproc')
def test_load_data_structure_error(
self, mock_xsltproc, mock_xml_parse,
mock_etree_parse, mock_relax, mock_schematron
):
mock_rng_validate = mock.Mock()
mock_rng_validate.validate = mock.Mock(
return_value=True
)
mock_sch_validate = mock.Mock()
mock_sch_validate.validate = mock.Mock(
return_value=True
)
mock_relax.return_value = mock_rng_validate
mock_schematron.return_value = mock_sch_validate
mock_xml_parse.side_effect = KiwiDataStructureError(
'DataStructureError'
)
self.description_from_file.load()
@patch('kiwi.xml_description.Command.run')
def test_load_extension(self, mock_command):
command_output = mock.Mock()
command_output.output = 'file://../data/my_plugin.rng'
mock_command.return_value = command_output
self.extension_description_from_data.load()
mock_command.assert_called_once_with(
['xmlcatalog', '/etc/xml/catalog', 'http://www.my_plugin.com']
)
xml_data = self.extension_description_from_data.get_extension_xml_data(
'my_plugin'
)
assert xml_data.getroot()[0].get('name') == 'cool stuff'
@raises(KiwiExtensionError)
def test_load_extension_multiple_toplevel_error(self):
self.extension_multiple_toplevel_description_from_data.load()
@raises(KiwiExtensionError)
@patch('kiwi.xml_description.Command.run')
def test_load_extension_schema_error(self, mock_command):
mock_command.side_effect = Exception
self.extension_description_from_data.load()
@patch('kiwi.xml_description.Command.run')
@raises(KiwiExtensionError)
def test_load_extension_validation_error(self, mock_command):
command_output = mock.Mock()
command_output.output = 'file://../data/my_plugin.rng'
mock_command.return_value = command_output
self.extension_invalid_description_from_data.load()