kiwi-el8/test/unit/root_init_test.py
Marcus Schäfer e6cc5bfa09 Move from nose to pytest
nose is no longer maintained, thus we have to move to another
testing system. This commit updates the tox setup and all tests
to use pytest instead of nose.
2016-03-14 12:23:14 +01:00

50 lines
1.3 KiB
Python

from mock import patch
import mock
from .test_helper import *
from kiwi.exceptions import (
KiwiRootDirExists,
KiwiRootInitCreationError
)
from kiwi.system.root_init import RootInit
class TestRootInit(object):
@raises(KiwiRootDirExists)
@patch('os.path.exists')
def test_init_raises_error(self, mock_path):
mock_path.return_value = True
RootInit('root_dir')
@raises(KiwiRootInitCreationError)
@patch('kiwi.command.Command.run')
@patch('os.path.exists')
def test_create_raises_error(self, mock_path, mock_command):
mock_path.return_value = False
mock_command.side_effect = KiwiRootInitCreationError('some-error')
root = RootInit('root_dir')
root.create()
@patch('kiwi.command.Command.run')
@patch('os.path.exists')
def test_create(self, mock_path, mock_command):
mock_path.return_value = False
root = RootInit('root_dir')
mock_path.return_value = True
root.create()
assert mock_command.called
@patch('kiwi.command.Command.run')
@patch('os.path.exists')
def test_delete(self, mock_path, mock_command):
mock_path.return_value = False
root = RootInit('root_dir')
root.delete()
mock_command.assert_called_once_with(
['rm', '-r', '-f', 'root_dir']
)