Debian Codegraph @

test/unit/markup/base_test.py

raw
1 from lxml import etree
2 from unittest.mock import patch
3 from pytest import raises
4
5 from kiwi.markup.base import MarkupBase
6 from kiwi.xml_description import XMLDescription
7 from kiwi.xml_state import XMLState
8
9 from kiwi.exceptions import (
10 KiwiConfigFileFormatNotSupported,
11 KiwiDescriptionInvalid,
12 KiwiIncludFileNotFoundError
13 )
14
15
16 class TestMarkupBase:
17 def setup(self):
18 self.markup = MarkupBase('../data/example_config.xml')
19
20 def setup_method(self, cls):
21 self.setup()
22
23 def test_get_xml_description(self):
24 with raises(NotImplementedError):
25 self.markup.get_xml_description()
26
27 def test_get_yaml_description(self):
28 with raises(NotImplementedError):
29 self.markup.get_yaml_description()
30
31 def test_apply_xslt_stylesheets(self):
32 assert 'xslt-' in self.markup.apply_xslt_stylesheets(
33 '../data/example_config.xml'
34 )
35
36 @patch('kiwi.markup.base.etree.parse')
37 def test_apply_xslt_stylesheets_nonXML(self, mock_parse):
38 mock_parse.side_effect = etree.XMLSyntaxError('not-XML', '<', 1, 1)
39 with raises(KiwiConfigFileFormatNotSupported):
40 self.markup.apply_xslt_stylesheets(
41 'artificial_and_invalid_XML_markup'
42 )
43
44 def test_apply_xslt_stylesheets_broken_XML(self):
45 markup = MarkupBase('../data/example_include_config.xml')
46 with raises(KiwiDescriptionInvalid):
47 markup.apply_xslt_stylesheets(
48 '../data/example_include_config.xml'
49 )
50
51 def test_apply_xslt_stylesheets_deprecated(self):
52 markup = MarkupBase('../data/example_deprecated_schema.xml')
53 with raises(KiwiDescriptionInvalid):
54 markup.apply_xslt_stylesheets(
55 '../data/example_deprecated_schema.xml'
56 )
57
58 def test_apply_xslt_stylesheets_missing_include_reference(self):
59 markup = MarkupBase(
60 '../data/example_include_config_missing_reference.xml'
61 )
62 with raises(KiwiIncludFileNotFoundError):
63 markup.apply_xslt_stylesheets(
64 '../data/example_include_config_missing_reference.xml'
65 )
66
67 def test_apply_xslt_stylesheets_include_from_image_description_dir(self):
68 markup = MarkupBase(
69 '../data/example_include_config_from_description_dir.xml'
70 )
71 xml_description = markup.apply_xslt_stylesheets(
72 '../data/example_include_config_from_description_dir.xml'
73 )
74 description = XMLDescription(xml_description)
75 xml_data = description.load()
76 state = XMLState(xml_data)
77 assert state.xml_data.get_repository()[0].get_source().get_path() == \
78 'http://example.com'