Make a factory out of the task and allow to have e.g a dracut boot image task at a later point in time. The BootImageBase class creates an interface for this implementation. So far only BootImageKiwi is implemented
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from nose.tools import *
|
|
from mock import patch
|
|
from mock import call
|
|
import mock
|
|
|
|
import nose_helper
|
|
|
|
from kiwi.exceptions import *
|
|
from kiwi.boot_image_base import BootImageBase
|
|
|
|
|
|
class TestBootImageBase(object):
|
|
@patch('kiwi.boot_image_base.mkdtemp')
|
|
@patch('kiwi.boot_image_base.os.path.exists')
|
|
def setup(self, mock_exists, mock_mkdtemp):
|
|
self.xml_state = mock.Mock()
|
|
mock_mkdtemp.return_value = 'boot-root-directory'
|
|
mock_exists.return_value = True
|
|
self.task = BootImageBase(
|
|
self.xml_state, 'some-target-dir'
|
|
)
|
|
mock_mkdtemp.assert_called_once_with(
|
|
prefix='boot-image.', dir='some-target-dir'
|
|
)
|
|
|
|
@raises(KiwiTargetDirectoryNotFound)
|
|
def test_boot_image_task_raises(self):
|
|
BootImageBase(
|
|
mock.Mock(), 'target-dir-does-not-exist', 'some-root-dir'
|
|
)
|
|
|
|
@raises(NotImplementedError)
|
|
def test_prepare(self):
|
|
self.task.prepare()
|
|
|
|
@raises(NotImplementedError)
|
|
def test_create_initrd(self):
|
|
self.task.create_initrd()
|
|
|
|
@patch('os.listdir')
|
|
def test_is_prepared(self, mock_listdir):
|
|
mock_listdir.return_value = True
|
|
assert self.task.is_prepared() == mock_listdir.return_value
|
|
|
|
@patch('kiwi.boot_image_base.Command.run')
|
|
@patch('os.path.exists')
|
|
def test_destructor(self, mock_path, mock_command):
|
|
mock_path.return_value = True
|
|
self.task.__del__()
|
|
print mock_command.call_args_list
|
|
assert mock_command.call_args_list == [
|
|
call(['rm', '-r', '-f', 'boot-root-directory']),
|
|
]
|