Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hmenke/mpsd-software-manager
  • mpsd-cs/mpsd-software-manager
2 results
Show changes
Commits on Source (44)
......@@ -81,7 +81,7 @@ style:
- ruff .
- black --check --diff .
- pydocstyle mpsd-software.py
- pydocstyle tests.py
- pydocstyle test_mpsd-software.py
# we could also use `ruff --select D` for pycodestyle. But the behaviour is not exactly the same.
- ./mpsd-software.py --version
......@@ -91,12 +91,12 @@ test-bullseye:
image: debian:bullseye-slim
script:
- *prepare_debian
- pytest -v -l tests.py
- pytest -v -l test_mpsd-software.py
test-bookworm:
stage: test
image: debian:bookworm-slim
script:
- *prepare_debian
- pytest -v -l tests.py
- pytest -v -l test_mpsd-software.py
This diff is collapsed.
......@@ -7,6 +7,7 @@ import subprocess
from pathlib import Path
import logging
import datetime
import sys
import pytest
......@@ -168,8 +169,7 @@ def test_record_script_execution_summary(tmp_path):
root_dir = tmp_path / "test_prepare_env"
mpsd_release_to_test = "dev-23a"
release_base_dir = root_dir / mpsd_release_to_test
if os.path.exists(release_base_dir / cmd_log_file):
if os.path.exists(root_dir / cmd_log_file):
initial_bytes = os.path.getsize(cmd_log_file)
else:
initial_bytes = 0
......@@ -179,22 +179,22 @@ def test_record_script_execution_summary(tmp_path):
mod.prepare_environment(mpsd_release=mpsd_release_to_test, root_dir=(root_dir))
# check that logs/install-software-environment.log is updated
assert os.path.exists(release_base_dir / cmd_log_file)
assert os.path.getsize(release_base_dir / cmd_log_file) > initial_bytes
assert os.path.exists(root_dir / cmd_log_file)
assert os.path.getsize(root_dir / cmd_log_file) > initial_bytes
# Check that the log file has "Spack environments branch: dev-23a " in the last line
with open(release_base_dir / cmd_log_file, "r") as f:
with open(root_dir / cmd_log_file, "r") as f:
last_line = f.readlines()[-1]
assert "Spack environments branch: dev-23a " in last_line
def test_install_environment_wrong_toolchain(tmp_path):
"""Test exception is raised for non-existing toolchain."""
# Expect an Exception when wrong toolchains are provided
def test_install_environment_wrong_package_set(tmp_path):
"""Test exception is raised for non-existing package_set."""
# Expect an Exception when wrong package_sets are provided
with pytest.raises(Exception):
mod.install_environment(
mpsd_release="dev-23a",
toolchains=["wrong-toolchain"],
package_sets=["wrong-package_set"],
root_dir=(tmp_path),
)
......@@ -206,13 +206,14 @@ def test_install_environment_wrong_mpsd_release(tmp_path):
with pytest.raises(Exception):
mod.install_environment(
mpsd_release="wrong-mpsd-release",
toolchains=["foss2021a-mpi"],
package_sets=["foss2021a-mpi"],
root_dir=(tmp_path),
)
@pytest.mark.skipif(sys.platform == "darwin", reason="install not working on OSX")
def test_install_environment_zlib():
"""Test installation of toolchain."""
"""Test installation of package_set."""
# Prepare a test installation of global generic
# with only zlib to test the installation
# This is a long test,
......@@ -226,21 +227,23 @@ def test_install_environment_zlib():
shutil.rmtree(root_dir)
root_dir.mkdir(exist_ok=True, parents=True)
mpsd_release_to_test = "dev-23a"
toolchain_to_test = "global_generic"
package_set_to_test = "global_generic"
cmd_log_file = mod.config_vars["cmd_log_file"]
microarch = mod.get_native_microarchitecture()
release_base_dir = root_dir / mpsd_release_to_test
create_mock_git_repository(target_directory=root_dir, create_directory=False)
mod.prepare_environment(mpsd_release=mpsd_release_to_test, root_dir=(root_dir))
# Patch the spack environments to create a fake global_generic
# create a test toolchain
toolchain_src_dir = release_base_dir / "spack-environments" / "toolchains"
# with mod.os_chdir(toolchain_src_dir):
# create a test package_set
package_set_src_dir = release_base_dir / "spack-environments" / "toolchains"
# with mod.os_chdir(package_set_src_dir):
# subprocess.run(
# "cp -r foss2021a-mpi fuss1999a", shell=True, capture_output=True
# )
# add zlib as a spec to global_generic
with open(toolchain_src_dir / "global_generic" / "global_packages.list", "w") as f:
with open(
package_set_src_dir / "global_generic" / "global_packages.list", "w"
) as f:
f.write("zlib@1.2.13 \n")
# add zlib to whitelist of module creation file by replacing anaconda3%gcc@10.2.1
......@@ -270,14 +273,14 @@ def test_install_environment_zlib():
with open(setup_file, "w") as f:
f.write(lines)
# install global_generic toolchain
# install global_generic package_set
mod.set_up_logging(
"WARNING",
mod.get_installer_log_file_path(mpsd_release_to_test, "install", root_dir),
)
mod.install_environment(
mpsd_release=mpsd_release_to_test,
toolchains=[toolchain_to_test],
package_sets=[package_set_to_test],
root_dir=root_dir,
enable_build_cache=False,
)
......@@ -302,14 +305,14 @@ def test_install_environment_zlib():
os.path.basename(build_log)
# assert that install log files exists
assert os.path.exists(release_base_dir / cmd_log_file)
assert os.path.exists(root_dir / cmd_log_file)
# assert that the build log is written to the install log file
os.path.basename(build_log)
with open(release_base_dir / cmd_log_file, "r") as f:
with open(root_dir / cmd_log_file, "r") as f:
lines = f.read()
assert (
f"installing {toolchain_to_test} and logging at {str(build_log)}" in lines
f"installing {package_set_to_test} and logging at {str(build_log)}" in lines
)
# assert that the module files are created correctly
assert os.path.exists(release_base_dir / microarch)
......@@ -330,7 +333,7 @@ def test_install_environment_zlib():
)
mod.install_environment(
mpsd_release=mpsd_release_to_test,
toolchains=[toolchain_to_test],
package_sets=[package_set_to_test],
root_dir=root_dir,
enable_build_cache=False,
)
......@@ -381,14 +384,14 @@ def test_metadata_logging(tmp_path):
assert len(read_dict) == len(keys)
def test_get_available_toolchains():
def test_get_available_package_sets():
"""
Test that available toolchains are reported correctly.
Test that available package_sets are reported correctly.
Needs internet access to succeed.
"""
toolchains = mod.get_available_toolchains("dev-23a")
assert sorted(toolchains) == sorted(
package_sets = mod.get_available_package_sets("dev-23a")
assert sorted(package_sets) == sorted(
[
"foss2021a-cuda-mpi",
"foss2021a-mpi",
......@@ -409,18 +412,18 @@ def test_create_log_file_names():
microarch = "sandybridge"
date = datetime.datetime.now().replace(microsecond=0).isoformat()
action = "install"
toolchain = "foss2021a"
package_set = "foss2021a"
# test build_log_file_name generation
build_log_file_name = create_log_file_names(
microarch=microarch,
mpsd_release=mpsd_release,
date=date,
action=action,
toolchain=toolchain,
package_set=package_set,
)
assert (
build_log_file_name
== f"{mpsd_release}_{microarch}_{date}_BUILD_{toolchain}_{action}.log"
== f"{mpsd_release}_{microarch}_{date}_BUILD_{package_set}_{action}.log"
)
installer_log_file_name = create_log_file_names(
microarch=microarch,
......@@ -438,7 +441,7 @@ def test_create_log_file_names():
mpsd_release=mpsd_release,
date=date,
action="status",
toolchain=toolchain,
package_set=package_set,
)
assert build_log_file_name is None
......@@ -472,7 +475,7 @@ def test_environment_status(tmp_path):
def test_interface(tmp_path):
"""Test other things (not implemented yet)."""
pass
# ensure that installing without toolchains only passes the available toolchains
# ensure that installing without package_sets only passes the available package_sets
# check that the script branch and hash are correct when running the script
# check that the help message is printed when no arguments are provided
# check that the help message is printed when -h is provided
......