From f8ed169e1ddb4954f92c33cf9ca22f815dc36d07 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 30 Aug 2023 14:08:46 +0200 Subject: [PATCH] check_for_valid_spec_syntax of status command --- tests/test_mpsd_software.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index c900b25..64bf891 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -501,7 +501,25 @@ def create_fake_environment(tmp_path, mpsd_release, expected_toolchain_map=None) return expected_toolchain_map -def test_environment_status(tmp_path): +def check_for_valid_spec_syntax(spec: str, package_name: str): + """Check if the spec is valid. + + Assuming the format of the spec as: + {name}{@versions}{%compiler.name}{@compiler.versions}{compiler_flags}{variants}{arch=architecture} + we ensure that: + - package name is correct + - there are atleast 2 @ symbols (version for package and compiler) + - there is atleast 1 % symbol (compiler specification) + - there is atleast 1 arch= + """ + assert len(spec.split("@")) >= 2 + assert len(spec.split("%")) >= 1 + assert "build_system=" in spec + assert "arch=" in spec + assert spec.split("@")[0] == package_name + + +def test_environment_status(tmp_path, simple_toolchain): """Test that the environment status is correct. The status command has the following three usage: @@ -533,7 +551,15 @@ def test_environment_status(tmp_path): assert set(toolchain_map[microarch]) == set(expected_toolchain_map[microarch]) # 3) If mpsd_release and toolchain, list available packages - # TODO this test has to be written after the MR from remove mcd is merged + install_test_release(tmp_path / "test_case3", simple_toolchain) + package_list = mod.environment_status( + mpsd_release, tmp_path / "test_case3", "toolchain2" + ) + assert len(package_list) == 2 # we installed zlib and zstd only + check_for_valid_spec_syntax( + package_list[0], "zlib" + ) # the list is always in alphabetical order + check_for_valid_spec_syntax(package_list[1], "zstd") def test_initialise_environment(tmp_path): -- GitLab