kiwi-el8/test/unit/markup/base_test.py
Marcus Schäfer ef05ecc36e
Add support for toplevel include directive(s)
On the toplevel of an image description you can now
specify include directive(s) like in the following
example

<image ...>
    ...
    <include from="filename_a.xml"/>
    ...
    <include from="filename_b.xml"/>
</image>

At the place of their occurrence the include statement
will be replaced with the contents of the given filename.
The implementation is based on a XSLT stylesheet and
applies very early in the process. The stylesheet reads
the contents of the given file as XML document().
Thus only valid XML documents gets accepted by this
include concept. This Fixes #1929 and is related to
Issue #1918
2021-10-07 09:50:38 +02:00

54 lines
1.7 KiB
Python

from lxml import etree
from mock import patch
from pytest import raises
from kiwi.markup.base import MarkupBase
from kiwi.exceptions import (
KiwiConfigFileFormatNotSupported,
KiwiDescriptionInvalid,
KiwiIncludFileNotFoundError
)
class TestMarkupBase:
def setup(self):
self.markup = MarkupBase('../data/example_config.xml')
def test_get_xml_description(self):
with raises(NotImplementedError):
self.markup.get_xml_description()
def test_get_yaml_description(self):
with raises(NotImplementedError):
self.markup.get_yaml_description()
def test_apply_xslt_stylesheets(self):
assert 'xslt-' in self.markup.apply_xslt_stylesheets(
'../data/example_config.xml'
)
@patch('kiwi.markup.base.etree.parse')
def test_apply_xslt_stylesheets_nonXML(self, mock_parse):
mock_parse.side_effect = etree.XMLSyntaxError('not-XML', '<', 1, 1)
with raises(KiwiConfigFileFormatNotSupported):
self.markup.apply_xslt_stylesheets(
'artificial_and_invalid_XML_markup'
)
def test_apply_xslt_stylesheets_broken_XML(self):
markup = MarkupBase('../data/example_include_config.xml')
with raises(KiwiDescriptionInvalid):
markup.apply_xslt_stylesheets(
'../data/example_include_config.xml'
)
def test_apply_xslt_stylesheets_missing_include_reference(self):
markup = MarkupBase(
'../data/example_include_config_missing_reference.xml'
)
with raises(KiwiIncludFileNotFoundError):
markup.apply_xslt_stylesheets(
'../data/example_include_config_missing_reference.xml'
)