@@ -182,14 +182,13 @@ def test_runtime_install_role(
182
182
runtime .cache_dir = tmp_dir
183
183
184
184
185
- def test_prepare_environment_with_collections (tmp_path : pathlib . Path ) -> None :
185
+ def test_prepare_environment_with_collections (runtime_tmp : Runtime ) -> None :
186
186
"""Check that collections are correctly installed."""
187
- runtime = Runtime (isolated = True , project_dir = tmp_path )
188
- runtime .prepare_environment (
187
+ runtime_tmp .prepare_environment (
189
188
required_collections = {"community.molecule" : "0.1.0" },
190
189
install_local = True ,
191
190
)
192
- assert "community.molecule" in runtime .collections
191
+ assert "community.molecule" in runtime_tmp .collections
193
192
194
193
195
194
def test_runtime_install_requirements_missing_file () -> None :
@@ -442,14 +441,13 @@ def test_require_collection_invalid_collections_path(runtime: Runtime) -> None:
442
441
runtime .require_collection ("community.molecule" )
443
442
444
443
445
- def test_require_collection_preexisting_broken (tmp_path : pathlib . Path ) -> None :
444
+ def test_require_collection_preexisting_broken (runtime_tmp : Runtime ) -> None :
446
445
"""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 ]
449
447
dest = pathlib .Path (dest_path ) / "ansible_collections" / "foo" / "bar"
450
448
dest .mkdir (parents = True , exist_ok = True )
451
449
with pytest .raises (InvalidPrerequisiteError , match = "missing MANIFEST.json" ):
452
- runtime .require_collection ("foo.bar" )
450
+ runtime_tmp .require_collection ("foo.bar" )
453
451
454
452
455
453
def test_require_collection (runtime_tmp : Runtime ) -> None :
@@ -958,7 +956,17 @@ def test_is_url(name: str, result: bool) -> None:
958
956
assert is_url (name ) == result
959
957
960
958
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 ,
962
970
caplog : pytest .LogCaptureFixture ,
963
971
) -> None :
964
972
"""Ensure avalid symlinks to collections are properly detected."""
@@ -970,30 +978,9 @@ def test_prepare_environment_valid_symlink(
970
978
goodies = acme / "minimal"
971
979
rmtree (goodies , ignore_errors = True )
972
980
goodies .unlink (missing_ok = True )
973
- goodies .symlink_to (Path . cwd () )
981
+ goodies .symlink_to (dest )
974
982
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
997
984
998
985
999
986
def test_get_galaxy_role_name_invalid () -> None :
0 commit comments