From 156ac595e68587ece09a0b0b2e1e876f1e7836e6 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 1 Oct 2026 17:45:34 +0200 Subject: [PATCH] test: hold three tests against the code they are supposed to cover All three failed on behaviour that is correct, which is why they had to move rather than the code. Two date from aa48981, which moved the default configs into the package. The loader test still wrote them beside it, into site-packages, and read its own stale comment as proof that the loader looks there. The cli-update test demanded a fallback onto that same directory; on a wheel install it belongs to other packages, so the test now pins the opposite and keeps the boundary. The third read a config.yaml in the destination to show the source one was not copied over it. The code never writes that file, so the read died before it could show anything; the absence is the assertion. The debian installer test stubbed which() for apt-get and dpkg-buildpackage but not for sudo, so _privileged_prefix returned None and the installer warned and left before reaching the apt-get calls the test was waiting for. Co-Authored-By: Claude Opus 5 (1M context) --- .../installers/os_packages/test_debian_control.py | 2 ++ tests/unit/pkgmgr/core/config/test_cli_update.py | 12 ++++-------- tests/unit/pkgmgr/core/config/test_load.py | 4 +--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/unit/pkgmgr/actions/install/installers/os_packages/test_debian_control.py b/tests/unit/pkgmgr/actions/install/installers/os_packages/test_debian_control.py index a6a07a8..199f42a 100644 --- a/tests/unit/pkgmgr/actions/install/installers/os_packages/test_debian_control.py +++ b/tests/unit/pkgmgr/actions/install/installers/os_packages/test_debian_control.py @@ -72,6 +72,8 @@ class TestDebianControlInstaller(unittest.TestCase): return "/usr/bin/dpkg-buildpackage" if name == "apt-get": return "/usr/bin/apt-get" + if name == "sudo": + return "/usr/bin/sudo" return None mock_which.side_effect = which_side_effect diff --git a/tests/unit/pkgmgr/core/config/test_cli_update.py b/tests/unit/pkgmgr/core/config/test_cli_update.py index c535ede..ed1a5bc 100644 --- a/tests/unit/pkgmgr/core/config/test_cli_update.py +++ b/tests/unit/pkgmgr/core/config/test_cli_update.py @@ -29,22 +29,19 @@ class FindDefaultsSourceDirTests(unittest.TestCase): self.assertEqual(Path(found).resolve(), (pkg_root / "config").resolve()) - def test_falls_back_to_project_root_config(self): + def test_a_config_dir_beside_the_package_is_not_taken(self): with tempfile.TemporaryDirectory() as td: root = Path(td) pkg_root = root / "site-packages" / "pkgmgr" pkg_root.mkdir(parents=True) - # only project_root config exists (pkg_root.parent / "config").mkdir(parents=True) fake_pkgmgr = types.SimpleNamespace(__file__=str(pkg_root / "__init__.py")) with patch.dict(sys.modules, {"pkgmgr": fake_pkgmgr}): found = config_cmd._find_defaults_source_dir() - self.assertEqual( - Path(found).resolve(), (pkg_root.parent / "config").resolve() - ) + self.assertIsNone(found) def test_returns_none_when_no_config_dirs_exist(self): with tempfile.TemporaryDirectory() as td: @@ -88,9 +85,8 @@ class UpdateDefaultConfigsTests(unittest.TestCase): self.assertTrue((dest_cfg_dir / "a.yaml").is_file()) self.assertTrue((dest_cfg_dir / "b.yml").is_file()) self.assertFalse( - (dest_cfg_dir / "config.yaml") - .read_text(encoding="utf-8") - .startswith("should_not_copy") + (dest_cfg_dir / "config.yaml").exists(), + "the source config.yaml must not be copied over the user's own", ) # Ensure config.yaml was not overwritten (it may exist, but should remain original if we create it) diff --git a/tests/unit/pkgmgr/core/config/test_load.py b/tests/unit/pkgmgr/core/config/test_load.py index 8bb3c25..4ff0198 100644 --- a/tests/unit/pkgmgr/core/config/test_load.py +++ b/tests/unit/pkgmgr/core/config/test_load.py @@ -242,9 +242,7 @@ class LoadConfigIntegrationUnitTests(unittest.TestCase): # Provide package defaults via fake pkgmgr + pkg_root/config root = Path(td) / "site-packages" pkg_root = root / "pkgmgr" - cfg_dir = ( - root / "config" - ) # NOTE: load.py checks multiple roots, including pkg_root.parent (=site-packages) + cfg_dir = pkg_root / "config" pkg_root.mkdir(parents=True) cfg_dir.mkdir(parents=True)