kiwi-el8/test/unit/oci_tools/init_test.py
Marcus Schäfer 9c9250ebc4
Support nose and xunit style tests
The modifications in this commit allows the unit tests
to run on both, pytest 6.x (nose test layout) and the new
pytest 7.x (xunit test layout). This Fixes #2072 in a
much nicer way. Thanks much to @smarlowucf
2022-02-26 20:26:18 +01:00

47 lines
1.4 KiB
Python

from pytest import raises
from mock import (
patch, Mock
)
from kiwi.oci_tools import OCI
from kiwi.exceptions import (
KiwiOCIArchiveToolError
)
class TestOCI:
def setup(self):
self.runtime_config = Mock()
self.runtime_config.get_oci_archive_tool = Mock()
def setup_method(self, cls):
self.setup()
@patch('kiwi.oci_tools.umoci.OCIUmoci')
@patch('kiwi.oci_tools.RuntimeConfig')
def test_oci_tool_umoci(
self, mock_RuntimeConfig, mock_OCIUmoci
):
self.runtime_config.get_oci_archive_tool.return_value = 'umoci'
mock_RuntimeConfig.return_value = self.runtime_config
OCI.new()
mock_OCIUmoci.assert_called_once_with()
@patch('kiwi.oci_tools.buildah.OCIBuildah')
@patch('kiwi.oci_tools.RuntimeConfig')
def test_oci_tool_buildah(
self, mock_RuntimeConfig, mock_OCIBuildah
):
self.runtime_config.get_oci_archive_tool.return_value = 'buildah'
mock_RuntimeConfig.return_value = self.runtime_config
OCI.new()
mock_OCIBuildah.assert_called_once_with()
@patch('kiwi.oci_tools.RuntimeConfig')
def test_oci_tool_not_supported(self, mock_RuntimeConfig):
self.runtime_config.get_oci_archive_tool.return_value = 'foo'
mock_RuntimeConfig.return_value = self.runtime_config
with raises(KiwiOCIArchiveToolError):
OCI.new()