Skip to content
Snippets Groups Projects

Try remove cmd

Merged Ashwin Kumar Karnad requested to merge try-remove-cmd into main
+ 57
13
@@ -344,6 +344,14 @@ def test_install_environment_zlib():
@@ -344,6 +344,14 @@ def test_install_environment_zlib():
)
)
assert len(build_log) == 4
assert len(build_log) == 4
 
# test that the removal now works
 
# mod.remove_environment(
 
# mpsd_release=mpsd_release_to_test,
 
# package_sets=[package_set_to_test],
 
# root_dir=root_dir,
 
# )
 
# # ensure that the module files are removed
 
def test_metadata_logging(tmp_path):
def test_metadata_logging(tmp_path):
"""Test that metadata is logged and read correctly."""
"""Test that metadata is logged and read correctly."""
@@ -446,32 +454,68 @@ def test_create_log_file_names():
@@ -446,32 +454,68 @@ def test_create_log_file_names():
assert build_log_file_name is None
assert build_log_file_name is None
def test_environment_status(tmp_path):
def create_fake_environment(tmp_path, mpsd_release, expected_toolchain_map=None):
"""Test that the environment status is correct."""
"""Create a fake environment with toolchains for testing."""
toolchain_map = mod.environment_status("fake-release", tmp_path)
if not expected_toolchain_map:
assert toolchain_map is None
test_microarch = mod.get_native_microarchitecture()
# create a fake environment
expected_toolchain_map = {test_microarch: ["foss2021a", "intel2021a"]}
mpsd_release = "dev-23a"
test_microarch = mod.get_native_microarchitecture()
expected_toolchain_map = {test_microarch: ["foss2021a", "intel2021a"]}
for microarch in expected_toolchain_map.keys():
for microarch in expected_toolchain_map.keys():
toolchain_lmod_folder = (
toolchain_lmod_folder = (
tmp_path / mpsd_release / microarch / "lmod" / "Core" / "toolchains"
tmp_path / mpsd_release / microarch / "lmod" / "Core" / "toolchains"
)
)
toolchain_lmod_folder.mkdir(parents=True)
toolchain_lmod_folder.mkdir(parents=True, exist_ok=True)
spack_folder = tmp_path / mpsd_release / microarch / "spack"
spack_folder = tmp_path / mpsd_release / microarch / "spack"
spack_folder.mkdir(parents=True)
spack_folder.mkdir(parents=True, exist_ok=True)
 
logs_folder = tmp_path / mpsd_release / microarch / "logs"
 
logs_folder.mkdir(parents=True, exist_ok=True)
for toolchain in expected_toolchain_map[microarch]:
for toolchain in expected_toolchain_map[microarch]:
toolchain_file = toolchain_lmod_folder / f"{toolchain}.lua"
toolchain_lua_file = toolchain_lmod_folder / f"{toolchain}.lua"
toolchain_file.touch()
toolchain_lua_file.touch()
# check that the environment status is correct
return expected_toolchain_map
 
 
 
def test_environment_status(tmp_path):
 
"""Test that the environment status is correct."""
 
toolchain_map = mod.environment_status("fake-release", tmp_path)
 
assert toolchain_map is None
 
mpsd_release = "dev-23a"
 
expected_toolchain_map = create_fake_environment(tmp_path, mpsd_release)
 
# check that the environment statuxis is correct
toolchain_map = mod.environment_status(mpsd_release, tmp_path)
toolchain_map = mod.environment_status(mpsd_release, tmp_path)
# convert each list to a set to ensure that the order doesn't matter
# convert each list to a set to ensure that the order doesn't matter
for microarch in expected_toolchain_map.keys():
for microarch in expected_toolchain_map.keys():
assert set(toolchain_map[microarch]) == set(expected_toolchain_map[microarch])
assert set(toolchain_map[microarch]) == set(expected_toolchain_map[microarch])
 
@pytest.mark.skip(reason="not implemented yet")
 
def test_remove_environment(tmp_path):
 
"""Test that the remove_environment works as expected."""
 
mpsd_release = "dev-23a"
 
# create a fake environment
 
create_fake_environment(tmp_path, mpsd_release)
 
# check that the environment status is correct
 
toolchain_map = mod.environment_status(mpsd_release, tmp_path)
 
assert toolchain_map is not None
 
 
# test removal without arguments (should sys.exit(1))
 
create_fake_environment(tmp_path, mpsd_release)
 
with pytest.raises(SystemExit):
 
mod.remove_environment(mpsd_release, tmp_path, force_remove=True)
 
 
# test removal of the complete environment
 
mod.remove_environment(mpsd_release, tmp_path, ["ALL"], force_remove=True)
 
toolchain_map = mod.environment_status(mpsd_release, tmp_path)
 
assert toolchain_map is None
 
# ensure that logs folder remains
 
logs_folder = tmp_path / mpsd_release / "logs"
 
assert logs_folder.exists()
 
 
# test removal of a single toolchain
 
# done in test_install_environment_zlib
 
 
def test_interface(tmp_path):
def test_interface(tmp_path):
"""Test other things (not implemented yet)."""
"""Test other things (not implemented yet)."""
pass
pass
Loading