Debian Codegraph @

test/unit/storage/subformat/vhdx_test.py

raw
1 from unittest.mock import (
2 patch, Mock
3 )
4
5 import kiwi
6
7 from kiwi.defaults import Defaults
8 from kiwi.storage.subformat.vhdx import DiskFormatVhdx
9
10
11 class TestDiskFormatVhdx:
12 def setup(self):
13 Defaults.set_platform_name('x86_64')
14 xml_data = Mock()
15 xml_data.get_name = Mock(
16 return_value='some-disk-image'
17 )
18 self.xml_state = Mock()
19 self.xml_state.xml_data = xml_data
20 self.xml_state.get_image_version = Mock(
21 return_value='1.2.3'
22 )
23 self.runtime_config = Mock()
24 self.runtime_config.get_bundle_compression.return_value = False
25 kiwi.storage.subformat.base.RuntimeConfig = Mock(
26 return_value=self.runtime_config
27 )
28 self.disk_format = DiskFormatVhdx(
29 self.xml_state, 'root_dir', 'target_dir'
30 )
31
32 def setup_method(self, cls):
33 self.setup()
34
35 def test_post_init(self):
36 self.disk_format.post_init({'option': 'value'})
37 assert self.disk_format.options == [
38 '-o', 'option=value', '-o', 'subformat=dynamic'
39 ]
40
41 @patch('kiwi.storage.subformat.vhdx.Command.run')
42 def test_create_image_format(self, mock_command):
43 self.disk_format.create_image_format()
44 mock_command.assert_called_once_with(
45 [
46 'qemu-img', 'convert', '-f', 'raw',
47 'target_dir/some-disk-image.x86_64-1.2.3.raw', '-O', 'vhdx',
48 '-o', 'subformat=dynamic',
49 'target_dir/some-disk-image.x86_64-1.2.3.vhdx'
50 ]
51 )