From de9728726cbd3107b38c600ac35e2b5dbbb04cda Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Fri, 9 Jun 2023 12:37:39 +0200 Subject: [PATCH] first attempt at adding tests --- mpsd-software-environment.py | 3 ++- tests.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mpsd-software-environment.py b/mpsd-software-environment.py index 7e17759..7669037 100755 --- a/mpsd-software-environment.py +++ b/mpsd-software-environment.py @@ -843,7 +843,7 @@ def environment_status(mpsd_release, script_dir): f"Release {mpsd_release} has not been completly installed yet" ", try reinstalling it (spack directory not found)" ) - return + return None # find all folders for all microarch in the release directory # except for the blacklisted files black_listed_files = [ @@ -873,6 +873,7 @@ def environment_status(mpsd_release, script_dir): plog.info(f"- {microarch}: \n \t {toolchains}") return toolchain_map + def main(): """Execute main entry point.""" parser = argparse.ArgumentParser(description=about_tool) diff --git a/tests.py b/tests.py index c284591..27bbad0 100644 --- a/tests.py +++ b/tests.py @@ -424,6 +424,28 @@ def test_create_log_file_names(): assert build_log_file_name is None +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 + # create a fake environment + mpsd_release = "dev-23a" + mpsd_microarch = "sandybridge" + expected_toochain_map = {"sandybridge": ["foss2021a", "intel2021a"]} + for mpsd_release in expected_toochain_map.keys(): + toolchain_files_path = ( + tmp_path / mpsd_release / mpsd_microarch / "lmod" / "Core" / "toolchains" + ) + toolchain_files_path.mkdir(parents=True) + for toolchain in expected_toochain_map[mpsd_release]: + toolchain_file = toolchain_files_path / f"{toolchain}.lua" + toolchain_file.touch() + + # check that the environment status is correct + toolchain_map = mod.environment_status(mpsd_release, tmp_path) + assert toolchain_map == expected_toochain_map + + def test_interface(tmp_path): """Test other things (not implemented yet).""" pass -- GitLab