| 1 |
from unittest.mock import ( |
| 2 |
Mock, patch |
| 3 |
) |
| 4 |
from pytest import raises |
| 5 |
|
| 6 |
from kiwi.exceptions import KiwiBootImageSetupError |
| 7 |
from kiwi.boot.image import BootImage |
| 8 |
|
| 9 |
|
| 10 |
class TestBootImage: |
| 11 |
def setup(self): |
| 12 |
self.xml_state = Mock() |
| 13 |
self.xml_state.get_initrd_system = Mock( |
| 14 |
return_value='kiwi' |
| 15 |
) |
| 16 |
|
| 17 |
def setup_method(self, cls): |
| 18 |
self.setup() |
| 19 |
|
| 20 |
def test_boot_image_not_implemented(self): |
| 21 |
self.xml_state.get_initrd_system.return_value = 'foo' |
| 22 |
with raises(KiwiBootImageSetupError): |
| 23 |
BootImage.new(self.xml_state, 'target_dir') |
| 24 |
|
| 25 |
@patch('kiwi.boot.image.builtin_kiwi.BootImageKiwi') |
| 26 |
def test_boot_image_task_kiwi(self, mock_kiwi): |
| 27 |
self.xml_state.get_initrd_system.return_value = 'kiwi' |
| 28 |
BootImage.new(self.xml_state, 'target_dir') |
| 29 |
mock_kiwi.assert_called_once_with( |
| 30 |
self.xml_state, 'target_dir', None, None |
| 31 |
) |
| 32 |
|
| 33 |
@patch('kiwi.boot.image.dracut.BootImageDracut') |
| 34 |
def test_boot_image_task_dracut(self, mock_dracut): |
| 35 |
self.xml_state.get_initrd_system.return_value = 'dracut' |
| 36 |
BootImage.new(self.xml_state, 'target_dir', 'root_dir') |
| 37 |
mock_dracut.assert_called_once_with( |
| 38 |
self.xml_state, 'target_dir', 'root_dir', None |
| 39 |
) |