kiwi-el8/test/unit/system_identifier_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

38 lines
1.1 KiB
Python

from mock import patch
import mock
from .test_helper import *
from kiwi.system.identifier import SystemIdentifier
class TestSystemIdentifier(object):
def setup(self):
self.identifier = SystemIdentifier()
def test_get_id(self):
pass
@patch('random.randrange')
def test_calculate_id(self, mock_rand):
mock_rand.return_value = 15
self.identifier.calculate_id()
assert self.identifier.get_id() == '0x0f0f0f0f'
@patch('builtins.open')
def test_write(self, mock_open):
self.identifier.image_id = 'some-id'
context_manager_mock = mock.Mock()
mock_open.return_value = context_manager_mock
file_mock = mock.Mock()
enter_mock = mock.Mock()
exit_mock = mock.Mock()
enter_mock.return_value = file_mock
setattr(context_manager_mock, '__enter__', enter_mock)
setattr(context_manager_mock, '__exit__', exit_mock)
self.identifier.write('mbrid-file')
mock_open.assert_called_once_with('mbrid-file', 'w')
file_mock.write.assert_called_once_with('some-id\n')