]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Revert "config: Test last assignment wins with defaults"
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 09:32:54 +0000 (11:32 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 09:32:54 +0000 (11:32 +0200)
This reverts commit 2fe014bc643dcc1442d0b057e20451f46345be9d.

tests/test-config/mkosi.conf [deleted file]
tests/test-config/mkosi.conf.d/00-dropin.conf [deleted file]
tests/test-config/mkosi.conf.d/01-dropin.conf [deleted file]
tests/test-config/mkosi.conf.d/02-dropin.conf [deleted file]
tests/test-config/mkosi.presets/00-test-preset/mkosi.conf [deleted file]
tests/test_config.py

diff --git a/tests/test-config/mkosi.conf b/tests/test-config/mkosi.conf
deleted file mode 100644 (file)
index 0cfdb69..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-[Distribution]
-
-@Distribution = ubuntu
-Architecture  = arm64
-
-[Output]
-@Format = cpio
-ImageId = base
diff --git a/tests/test-config/mkosi.conf.d/00-dropin.conf b/tests/test-config/mkosi.conf.d/00-dropin.conf
deleted file mode 100644 (file)
index 905fb2e..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Distribution]
-@Architecture = x86-64
-
-[Output]
-ImageId = 00-dropin
-ImageVersion = 0
diff --git a/tests/test-config/mkosi.conf.d/01-dropin.conf b/tests/test-config/mkosi.conf.d/01-dropin.conf
deleted file mode 100644 (file)
index a95f1df..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-[Distribution]
-Architecture         = x86-64
-@RepositoryKeyCheck  = no
-
-[Output]
-ImageId      = 01-dropin
-ImageVersion = 1
-Format       = disk
diff --git a/tests/test-config/mkosi.conf.d/02-dropin.conf b/tests/test-config/mkosi.conf.d/02-dropin.conf
deleted file mode 100644 (file)
index 3070d05..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-[Distribution]
-Distribution  = debian
-
-[Output]
-ImageId      = 02-dropin
-ImageVersion = 2
-@Format      = directory
diff --git a/tests/test-config/mkosi.presets/00-test-preset/mkosi.conf b/tests/test-config/mkosi.presets/00-test-preset/mkosi.conf
deleted file mode 100644 (file)
index 9fb615a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-[Output]
-ImageId = test-preset
-
index 290c2618c79ee54adf335a3f215f09efa1978aab..2a70ae3002a66930420a3115aee5354a575cb2d9 100644 (file)
@@ -1,73 +1,9 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import contextlib
 import tempfile
-from argparse import Namespace
-from os import chdir
 from pathlib import Path
-from typing import Iterator
 
-import pytest
-
-from mkosi.architecture import Architecture
-from mkosi.config import Compression, MkosiConfig, MkosiConfigParser, OutputFormat, parse_ini
-
-CONF_DIR = Path(__file__).parent.absolute() / "test-config"
-
-
-def parse_paths(paths: list[Path]) -> MkosiConfig:
-    """Process these paths stacked together"""
-
-    parser = MkosiConfigParser()
-    namespace = Namespace()
-    defaults = Namespace()
-    setattr(namespace, "preset", None)
-
-    for path in paths:
-        parser.parse_config(path, namespace, defaults)
-
-    parser.finalize_defaults(namespace, defaults)
-    return MkosiConfig.from_namespace(namespace)
-
-
-def parse_dropins() -> list[MkosiConfig]:
-    """Return the configuration for the base config and each processed drop-in"""
-
-    # The configuration is processed this way so that each drop-in can be tested
-    # individually to confirm what occurs at each step. This emulates normal
-    # drop-in processing but can separate out the steps for testing.
-
-    paths = [CONF_DIR / "mkosi.conf"] + sorted((CONF_DIR / "mkosi.conf.d").iterdir())
-
-    configs = list()
-    for i in range(len(paths)):
-        configs.append(parse_paths(paths[:i+1]))
-
-    return configs
-
-
-#TODO: Can be removed once we drop Python <3.11 support
-@contextlib.contextmanager
-def cd_new_dir(path: Path) -> Iterator[None]:
-    cwd = Path().cwd()
-    chdir(str(path))
-    yield
-    chdir(str(cwd))
-
-
-@pytest.fixture(scope="module")
-def get_config() -> dict[str, list[MkosiConfig]]:
-    dropins = parse_dropins()
-    configs = {
-        'drop-ins': dropins[1:],
-        'presets': [dropins[0]]
-    }
-
-    with cd_new_dir(CONF_DIR):
-        args, presets = MkosiConfigParser().parse("")
-        configs['presets'].extend(presets)
-
-    return configs
+from mkosi.config import Compression, parse_ini
 
 
 def test_compression_enum_creation() -> None:
@@ -100,98 +36,6 @@ def test_compression_enum_str() -> None:
     assert str(Compression.lzma) == "lzma"
 
 
-def test_get_config(get_config : dict[str, list[MkosiConfig]]) -> None:
-    assert get_config['drop-ins'][0].image_id == "00-dropin"
-    assert get_config['drop-ins'][1].image_id == "01-dropin"
-    assert get_config['drop-ins'][2].image_id == "02-dropin"
-    assert get_config['presets'][0].image_id == "base"
-    assert get_config['presets'][1].image_id == "test-preset"
-
-
-def test_dropin_default(get_config : dict[str, list[MkosiConfig]]) -> None:
-    # Default set
-    assert get_config['drop-ins'][0].repository_key_check == True
-    # Default changed
-    assert get_config['drop-ins'][1].repository_key_check == False
-
-
-def test_default_overridden(get_config : dict[str, list[MkosiConfig]]) -> None:
-    assert get_config['drop-ins'][0].architecture == Architecture.arm64
-    assert get_config['drop-ins'][1].architecture == Architecture.x86_64
-    assert get_config['drop-ins'][2].architecture == Architecture.x86_64
-
-
-def test_def_nondef_def(get_config : dict[str, list[MkosiConfig]]) -> None:
-    assert get_config['drop-ins'][0].output_format == OutputFormat.cpio
-    assert get_config['drop-ins'][1].output_format == OutputFormat.disk
-    assert get_config['drop-ins'][2].output_format == OutputFormat.disk
-
-
-def test_default_generation(get_config : dict[str, list[MkosiConfig]]) -> None:
-    assert get_config['drop-ins'][0].mirror == "http://ports.ubuntu.com"
-    assert get_config['drop-ins'][1].mirror == "http://archive.ubuntu.com/ubuntu"
-    assert get_config['drop-ins'][2].mirror == "http://deb.debian.org/debian"
-
-
-def write_config(dir: Path) -> None:
-    with open(dir / "mkosi.conf", "w") as f:
-        # We need something in the file to parse
-        f.write("[Output]\n")
-        f.write("ImageId=base\n")
-
-
-def test_sorted_dropins() -> None:
-    def write_dropin(dir: Path, name: str, version: int) -> None:
-        with open(dir / name, "w") as f:
-            f.write("[Output]\n")
-            f.write(f"ImageVersion={version}\n")
-
-    with tempfile.TemporaryDirectory() as tmpdir:
-        tmp_path = Path(tmpdir)
-        write_config(tmp_path)
-
-        (tmp_path / "mkosi.conf.d").mkdir()
-        # A roughly random order to save files in
-        dropin_ids = [0,5,1,4,2,3]
-        for i in dropin_ids:
-            write_dropin(tmp_path / "mkosi.conf.d", f"0{i}-dropin.conf", i)
-
-        with cd_new_dir(tmp_path):
-            args, presets = MkosiConfigParser().parse("")
-
-        assert presets[0].image_version == str(max(dropin_ids))
-
-
-def test_path_inheritence() -> None:
-    with tempfile.TemporaryDirectory() as tmpdir:
-        tmp_path = Path(tmpdir)
-        write_config(tmp_path)
-        (tmp_path / "mkosi.output").mkdir()
-        with cd_new_dir(tmp_path):
-            args, presets = MkosiConfigParser().parse("")
-
-        # Confirm output directory is processed
-        assert presets[0].output_dir == Path(tmpdir) / "mkosi.output"
-
-        # Add a preset
-        (tmp_path / "mkosi.presets" / "00-test-preset").mkdir(parents=True)
-        write_config(tmp_path / "mkosi.presets" / "00-test-preset")
-        with cd_new_dir(tmp_path):
-            args, presets = MkosiConfigParser().parse("")
-
-        # Confirm output directory remains the same
-        assert presets[0].preset == "00-test-preset"
-        assert presets[0].output_dir == Path(tmpdir) / "mkosi.output"
-
-        (tmp_path / "mkosi.presets" / "00-test-preset" / "mkosi.output").mkdir()
-        with cd_new_dir(tmp_path):
-            args, presets = MkosiConfigParser().parse("")
-
-        # Confirm output directory changes
-        assert presets[0].preset == "00-test-preset"
-        assert presets[0].output_dir == Path(tmpdir) / "mkosi.presets" / "00-test-preset" / "mkosi.output"
-
-
 def test_parse_ini() -> None:
     with tempfile.TemporaryDirectory() as d:
         p = Path(d) / "ini"