kiwi-el8/test/unit/disk_format_test.py
Marcus Schäfer 40e6308aa9 Port application from python 2.7 to 3.4
For new applications like this kiwi version and its use cases
it is better to base it on a more recent python version
2016-02-17 22:38:38 +01:00

73 lines
2.4 KiB
Python

from nose.tools import *
from mock import patch
import mock
from . import nose_helper
from kiwi.exceptions import *
from kiwi.disk_format import DiskFormat
class TestDiskFormat(object):
@raises(KiwiDiskFormatSetupError)
def test_format_not_implemented(self):
DiskFormat('foo', mock.Mock(), 'root_dir', 'target_dir')
@patch('kiwi.disk_format.DiskFormatQcow2')
def test_disk_format_qcow2(self, mock_qcow2):
xml_state = mock.Mock()
DiskFormat('qcow2', xml_state, 'root_dir', 'target_dir')
mock_qcow2.assert_called_once_with(
xml_state, 'root_dir', 'target_dir'
)
@patch('kiwi.disk_format.DiskFormatVhd')
def test_disk_format_vhd(self, mock_vhd):
xml_state = mock.Mock()
DiskFormat('vhd', xml_state, 'root_dir', 'target_dir')
mock_vhd.assert_called_once_with(
xml_state, 'root_dir', 'target_dir'
)
@patch('kiwi.disk_format.DiskFormatVhdFixed')
def test_disk_format_vhdfixed(self, mock_vhdfixed):
xml_state = mock.Mock()
xml_state.build_type.get_vhdfixedtag = mock.Mock(
return_value='disk-tag'
)
DiskFormat('vhdfixed', xml_state, 'root_dir', 'target_dir')
mock_vhdfixed.assert_called_once_with(
xml_state, 'root_dir', 'target_dir', {'--tag': 'disk-tag'}
)
@patch('kiwi.disk_format.DiskFormatGce')
def test_disk_format_gce(self, mock_gce):
xml_state = mock.Mock()
xml_state.build_type.get_gcelicense = mock.Mock(
return_value='gce_license_tag'
)
DiskFormat('gce', xml_state, 'root_dir', 'target_dir')
mock_gce.assert_called_once_with(
xml_state, 'root_dir', 'target_dir', {'--tag': 'gce_license_tag'}
)
@patch('kiwi.disk_format.DiskFormatVmdk')
def test_disk_format_vmdk(self, mock_vmdk):
xml_state = mock.Mock()
vmdisk = mock.Mock()
vmdisk.get_controller = mock.Mock(
return_value='controller'
)
vmdisk.get_diskmode = mock.Mock(
return_value='disk-mode'
)
xml_state.get_build_type_vmdisk_section = mock.Mock(
return_value=vmdisk
)
DiskFormat('vmdk', xml_state, 'root_dir', 'target_dir')
mock_vmdk.assert_called_once_with(
xml_state, 'root_dir', 'target_dir',
{'adapter_type=controller': None, 'subformat=disk-mode': None}
)