Skip to content
Snippets Groups Projects
Commit 0bed5756 authored by Ashwin Kumar Karnad's avatar Ashwin Kumar Karnad
Browse files

fix tests

parent 73e42262
No related branches found
No related tags found
2 merge requests!19Move linux-debian11 into main,!1Resolve "First draft for user interface for top level install command"
......@@ -2,6 +2,8 @@ import os
import pytest
import importlib
import subprocess
import time
import shutil
mod = importlib.import_module("install-mpsd-software-environment")
......@@ -26,20 +28,55 @@ def test_os_chdir():
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")
# prepare_env is run when cmd is not specified, we can test cmd='prepare' and cmd=None to check both cases
test_release_path = "/tmp/test_prepare_env"
# if the directory exists, remove it
if os.path.exists(test_release_path):
shutil.rmtree(test_release_path)
# check that the test directory does not exist
assert not os.path.exists(test_release_path)
run = mod.builder(
release="dev-23a",
cmd="prepare",
target_dir=test_release_path,
skip_build_cache=False,
)
run.run()
# wait for 20 seconds for the git clone to finish
# time.sleep(20)
# check if the directory now is created
assert os.path.exists(test_release_path)
# check for spack-environments directory
assert os.listdir("/tmp/test_prepare_env") == ["spack-environments"]
assert os.listdir(test_release_path) == ["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"
).stdout.decode("utf-8").split("\n")[0]
== "* dev-23a"
)
# make sure running the command again raises ValueError
with pytest.raises(ValueError):
mod.prepare_env("dev-23a", "/tmp/test_prepare_env", False)
run = mod.builder(
release="dev-23a",
cmd=None,
target_dir=test_release_path,
skip_build_cache=False,
)
run.run()
# check that ValueError is not raised if skip_dir_check is True
run = mod.builder(
release="dev-23a",
cmd=None,
target_dir=test_release_path,
skip_build_cache=False,
)
run.skip_dir_check = True
run.run()
# clean up the temporary directory
shutil.rmtree(test_release_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment