From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:59:29 +0000 (+0200) Subject: Always set distribution in tests X-Git-Tag: v17~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ad1a8bd8cb4f1e5ff7dceaa397746101e3e60c8;p=thirdparty%2Fmkosi.git Always set distribution in tests This enables executing the tests on distributions that aren't targeted by mkosi. Before, the tests would fail as the detected distribution was None. Co-authored-by: Malte Poll --- diff --git a/mkosi/config.py b/mkosi/config.py index f5c61e08b..13c30fca7 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -292,6 +292,15 @@ def config_default_compression(namespace: argparse.Namespace) -> Compression: return Compression.none +def config_default_distribution(namespace: argparse.Namespace) -> Distribution: + detected = detect_distribution()[0] + + if not detected: + die("Distribution of your host can't be detected or isn't a supported target. Please set Distribution= in your config.") + + return detected + + def config_default_release(namespace: argparse.Namespace) -> str: # If the configured distribution matches the host distribution, use the same release as the host. hd, hr = detect_distribution() @@ -899,7 +908,7 @@ SETTINGS = ( section="Distribution", parse=config_make_enum_parser(Distribution), match=config_make_enum_matcher(Distribution), - default=detect_distribution()[0], + default_factory=config_default_distribution, choices=Distribution.values(), help="Distribution to install", ), diff --git a/tests/test_config.py b/tests/test_config.py index 0250da1f6..082759c7e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -171,6 +171,7 @@ def test_parse_config(tmp_path: Path) -> None: def test_parse_load_verb(tmp_path: Path) -> None: + (tmp_path / "mkosi.conf").write_text("[Distribution]\nDistribution=fedora") with chdir(tmp_path): assert parse_config(["build"])[0].verb == Verb.build assert parse_config(["clean"])[0].verb == Verb.clean @@ -209,8 +210,24 @@ def test_parse_config_files_filter(tmp_path: Path) -> None: confd = Path("mkosi.conf.d") confd.mkdir() - (confd / "10-file.conf").write_text("[Content]\nPackages=yes") - (confd / "20-file.noconf").write_text("[Content]\nPackages=nope") + (confd / "10-file.conf").write_text( + """\ + [Distribution] + Distribution=fedora + + [Content] + Packages=yes + """ + ) + (confd / "20-file.noconf").write_text( + """\ + [Distribution] + Distribution=fedora + + [Content] + Packages=yes + """ + ) _, [config] = parse_config() assert config.packages == ["yes"] @@ -218,7 +235,7 @@ def test_parse_config_files_filter(tmp_path: Path) -> None: def test_compression(tmp_path: Path) -> None: with chdir(tmp_path): - _, [config] = parse_config(["--format", "disk", "--compress-output", "False"]) + _, [config] = parse_config(["--format", "disk", "--compress-output", "False", "--distribution", "fedora"]) assert config.compress_output == Compression.none @@ -424,6 +441,7 @@ def test_match_imageversion(tmp_path: Path, op: str, version: str) -> None: parent.write_text( """\ [Distribution] + Distribution=fedora ImageId=testimage ImageVersion=123 """ @@ -479,11 +497,24 @@ def test_package_manager_tree(tmp_path: Path, skel: Optional[Path], pkgmngr: Opt with chdir(tmp_path): config = Path("mkosi.conf") with config.open("w") as f: - f.write("[Content]\n") + f.write( + """ + [Distribution] + Distribution=fedora + + [Content] + """ + ) if skel is not None: - f.write(f"SkeletonTrees={skel}\n") + f.write(f""" + SkeletonTrees={skel} + """ + ) if pkgmngr is not None: - f.write(f"PackageManagerTrees={pkgmngr}\n") + f.write(f""" + PackageManagerTrees={pkgmngr} + """ + ) _, [conf] = parse_config()