diff --git a/kiwi/bootloader/config/__init__.py b/kiwi/bootloader/config/__init__.py index daa651f9fb9..db94efd8259 100644 --- a/kiwi/bootloader/config/__init__.py +++ b/kiwi/bootloader/config/__init__.py @@ -15,13 +15,8 @@ # You should have received a copy of the GNU General Public License # along with kiwi. If not, see # -import sys -from typing import TYPE_CHECKING, Dict, Union, overload +from typing import TYPE_CHECKING, Dict, Literal, Union, overload -if sys.version_info >= (3, 8): - from typing import Literal # pragma: no cover -else: # pragma: no cover - from typing_extensions import Literal # pragma: no cover from kiwi.exceptions import ( KiwiBootLoaderConfigSetupError diff --git a/kiwi/builder/disk.py b/kiwi/builder/disk.py index 5c7b9a07bc4..d7443f089e7 100644 --- a/kiwi/builder/disk.py +++ b/kiwi/builder/disk.py @@ -17,15 +17,8 @@ # from contextlib import ExitStack import os -import sys import logging -from typing import ( - Dict, List, Optional, Tuple, Union -) -if sys.version_info >= (3, 8): - from typing import TypedDict # pragma: no cover -else: # pragma: no cover - from typing_extensions import TypedDict # pragma: no cover +from typing import Dict, List, Optional, Tuple, TypedDict, Union # project import kiwi.defaults as defaults diff --git a/kiwi/command.py b/kiwi/command.py index 54e857e326c..c6242ce7a23 100644 --- a/kiwi/command.py +++ b/kiwi/command.py @@ -15,17 +15,11 @@ # You should have received a copy of the GNU General Public License # along with kiwi. If not, see # -from typing import IO, Callable, List, MutableMapping, NamedTuple, Optional, overload +from typing import IO, Callable, Literal, List, MutableMapping, NamedTuple, Optional, overload import logging import os import select import subprocess -import sys - -if sys.version_info >= (3, 8): - from typing import Literal # pragma: no cover -else: # pragma: no cover - from typing_extensions import Literal # pragma: no cover # project from kiwi.utils.codec import Codec diff --git a/kiwi/container/oci.py b/kiwi/container/oci.py index 34405cb475e..22ae5aa15df 100644 --- a/kiwi/container/oci.py +++ b/kiwi/container/oci.py @@ -17,12 +17,7 @@ # import os import logging -import sys -from typing import Dict, List, Optional -if sys.version_info >= (3, 8): - from typing import TypedDict # pragma: no cover -else: # pragma: no cover - from typing_extensions import TypedDict # pragma: no cover +from typing import Dict, List, Optional, TypedDict # project from kiwi.utils.compress import Compress diff --git a/kiwi/system/root_import/oci.py b/kiwi/system/root_import/oci.py index 86ac55a5603..9824efa98a1 100644 --- a/kiwi/system/root_import/oci.py +++ b/kiwi/system/root_import/oci.py @@ -101,11 +101,7 @@ def _get_image_urls(self) -> List[str]: uncompressed_image = compressor.uncompressed_filename else: uncompressed_image = image_file - image_urls.append( - '{0}:{1}'.format( - self.archive_transport, uncompressed_image - ) - ) + image_urls.append(f"{self.archive_transport}:{uncompressed_image}") return image_urls else: log.warning('Bypassing base image URI to OCI tools') diff --git a/test/unit/conftest.py b/test/unit/conftest.py new file mode 100644 index 00000000000..f52df51e94d --- /dev/null +++ b/test/unit/conftest.py @@ -0,0 +1,24 @@ +import pytest + + +@pytest.fixture(autouse=True) +def dont_use_kiwi_yml_from_host( + request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch +) -> None: + """kiwi will by default read runtime config files, which influence which + utilities get chosen. The users config file leaks into the test environment, + which is undesirable as certain tests assume that the default tool is XYZ + and assert that. This fixture prevents the loading of the runtime config + files by setting all paths to falsy values that hence are ignored. + + This behavior can be turned off by adding the ``no_kiwi_yml_mock`` marker. + + """ + if request.node.get_closest_marker("no_kiwi_yml_mock"): + return + + monkeypatch.setattr("kiwi.defaults.ETC_RUNTIME_CONFIG_DIR", "") + monkeypatch.setattr("kiwi.defaults.ETC_RUNTIME_CONFIG_FILE", "") + monkeypatch.setattr("kiwi.defaults.USR_RUNTIME_CONFIG_DIR", "") + monkeypatch.setattr("kiwi.defaults.USR_RUNTIME_CONFIG_FILE", "") + monkeypatch.setattr("kiwi.defaults.CUSTOM_RUNTIME_CONFIG_FILE", None) diff --git a/test/unit/runtime_config_test.py b/test/unit/runtime_config_test.py index d57bdfad985..07588fe1a20 100644 --- a/test/unit/runtime_config_test.py +++ b/test/unit/runtime_config_test.py @@ -5,6 +5,7 @@ from pytest import ( raises, fixture ) +import pytest from kiwi.runtime_config import RuntimeConfig from kiwi.defaults import Defaults @@ -50,6 +51,7 @@ def test_reading_custom_config_file(self, mock_yaml): ] ) + @pytest.mark.no_kiwi_yml_mock @patch('os.path.exists') @patch('yaml.safe_load') @patch('os.path.isdir') @@ -82,6 +84,7 @@ def os_path_isdir(config): call('/etc/kiwi.yml.d/some.yml', 'r') ] + @pytest.mark.no_kiwi_yml_mock @patch('os.path.exists') @patch('yaml.safe_load') @patch('os.path.isdir')