From 73e422620484d0c731c172bf0f05e2a7cd7d15a8 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 3 May 2023 10:01:05 +0200 Subject: [PATCH] add test for prepare_env --- tests.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 7336b8e..ae2a327 100644 --- a/tests.py +++ b/tests.py @@ -1,13 +1,15 @@ import os import pytest import importlib +import subprocess mod = importlib.import_module("install-mpsd-software-environment") + def test_os_chdir(): # create a temporary directory for testing temp_dir = "/tmp/test_os_chdir" os.mkdir(temp_dir) - + # initial current working directory initial_cwd = os.getcwd() @@ -20,3 +22,24 @@ def test_os_chdir(): # clean up the temporary directory os.rmdir(temp_dir) + + +def test_prepare_env(): + # simulate running ./install-software-environment.py --release dev-23a --target-directory /tmp/test_prepare_env + mod.prepare_env("dev-23a", "/tmp/test_prepare_env", False) + # check if the directory exists + assert os.path.exists("/tmp/test_prepare_env") + # check for spack-environments directory + assert os.listdir("/tmp/test_prepare_env") == ["spack-environments"] + # check if the git branch is correctl checked out + assert ( + subprocess.run( + "cd /tmp/test_prepare_env/spack-environments && git branch", + shell=True, + capture_output=True, + ).stdout.decode("utf-8") + == "* dev-23a\n" + ) + # make sure running the command again raises ValueError + with pytest.raises(ValueError): + mod.prepare_env("dev-23a", "/tmp/test_prepare_env", False) -- GitLab