Skip to content

Commit 820bc02

Browse files
committed
Reduce size of test_runtime
1 parent 36a6fbf commit 820bc02

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

test/test_runtime.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,13 @@ def test_runtime_install_role(
182182
runtime.cache_dir = tmp_dir
183183

184184

185-
def test_prepare_environment_with_collections(tmp_path: pathlib.Path) -> None:
185+
def test_prepare_environment_with_collections(runtime_tmp: Runtime) -> None:
186186
"""Check that collections are correctly installed."""
187-
runtime = Runtime(isolated=True, project_dir=tmp_path)
188-
runtime.prepare_environment(
187+
runtime_tmp.prepare_environment(
189188
required_collections={"community.molecule": "0.1.0"},
190189
install_local=True,
191190
)
192-
assert "community.molecule" in runtime.collections
191+
assert "community.molecule" in runtime_tmp.collections
193192

194193

195194
def test_runtime_install_requirements_missing_file() -> None:
@@ -442,14 +441,13 @@ def test_require_collection_invalid_collections_path(runtime: Runtime) -> None:
442441
runtime.require_collection("community.molecule")
443442

444443

445-
def test_require_collection_preexisting_broken(tmp_path: pathlib.Path) -> None:
444+
def test_require_collection_preexisting_broken(runtime_tmp: Runtime) -> None:
446445
"""Check that require_collection raise with broken pre-existing collection."""
447-
runtime = Runtime(isolated=True, project_dir=tmp_path)
448-
dest_path: str = runtime.config.collections_paths[0]
446+
dest_path: str = runtime_tmp.config.collections_paths[0]
449447
dest = pathlib.Path(dest_path) / "ansible_collections" / "foo" / "bar"
450448
dest.mkdir(parents=True, exist_ok=True)
451449
with pytest.raises(InvalidPrerequisiteError, match="missing MANIFEST.json"):
452-
runtime.require_collection("foo.bar")
450+
runtime_tmp.require_collection("foo.bar")
453451

454452

455453
def test_require_collection(runtime_tmp: Runtime) -> None:
@@ -958,7 +956,17 @@ def test_is_url(name: str, result: bool) -> None:
958956
assert is_url(name) == result
959957

960958

961-
def test_prepare_environment_valid_symlink(
959+
@pytest.mark.parametrize(
960+
("dest", "message"),
961+
(
962+
("/invalid/destination", "Collection is symlinked, but not pointing to"),
963+
(Path.cwd(), "Found symlinked collection, skipping its installation."),
964+
),
965+
ids=["broken", "valid"],
966+
)
967+
def test_prepare_environment_symlink(
968+
dest: str | Path,
969+
message: str,
962970
caplog: pytest.LogCaptureFixture,
963971
) -> None:
964972
"""Ensure avalid symlinks to collections are properly detected."""
@@ -970,30 +978,9 @@ def test_prepare_environment_valid_symlink(
970978
goodies = acme / "minimal"
971979
rmtree(goodies, ignore_errors=True)
972980
goodies.unlink(missing_ok=True)
973-
goodies.symlink_to(Path.cwd())
981+
goodies.symlink_to(dest)
974982
runtime.prepare_environment(install_local=True)
975-
assert "Found symlinked collection, skipping its installation." in caplog.text
976-
977-
978-
def test_prepare_environment_repair_broken_symlink(
979-
caplog: pytest.LogCaptureFixture,
980-
) -> None:
981-
"""Ensure we can deal with broken symlinks in collections."""
982-
caplog.set_level(logging.INFO)
983-
project_dir = Path(__file__).parent / "collections" / "acme.minimal"
984-
runtime = Runtime(isolated=True, project_dir=project_dir)
985-
assert runtime.cache_dir
986-
acme = runtime.cache_dir / "collections" / "ansible_collections" / "acme"
987-
acme.mkdir(parents=True, exist_ok=True)
988-
goodies = acme / "minimal"
989-
rmtree(goodies, ignore_errors=True)
990-
goodies.unlink(missing_ok=True)
991-
goodies.symlink_to("/invalid/destination")
992-
runtime.prepare_environment(install_local=True)
993-
assert any(
994-
msg.startswith("Collection is symlinked, but not pointing to")
995-
for msg in caplog.messages
996-
)
983+
assert message in caplog.text
997984

998985

999986
def test_get_galaxy_role_name_invalid() -> None:

0 commit comments

Comments
 (0)