From c6e26258113a29e8a993bf5b216e720a7fecddda Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Mon, 8 May 2023 14:13:22 +0200 Subject: [PATCH] test prepare_environment --- tests.py | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/tests.py b/tests.py index f85c0b4..d0a4912 100644 --- a/tests.py +++ b/tests.py @@ -24,58 +24,36 @@ def test_os_chdir(tmp_path): assert os.getcwd() == initial_cwd -def test_prepare_env(tmp_path): +def test_prepare_environment(tmp_path): # simulate running ./install-software-environment.py --release dev-23a --target-directory /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 + script_dir = tmp_path / "test_prepare_env" + spack_environments = "spack-environments" + mpsd_release_to_test = "dev-23a" + release_base_dir = script_dir / mpsd_release_to_test # check that the test directory does not exist - assert not (tmp_path / "test_prepare_env").exists() + assert not script_dir.exists() - run = mod.builder( - release="dev-23a", - cmd="prepare", - target_dir=str(tmp_path / "test_prepare_env"), - skip_build_cache=False, - ) - run.run() + mod.prepare_environment(mpsd_release=mpsd_release_to_test, script_dir=str(script_dir)) # wait for 20 seconds for the git clone to finish # time.sleep(20) # check if the directory now is created - assert (tmp_path / "test_prepare_env").exists() + assert release_base_dir.exists() # check for spack-environments directory - assert os.listdir(str(tmp_path / "test_prepare_env")) == ["spack-environments"] - # check if the git branch is correctl checked out + assert spack_environments in os.listdir(str(release_base_dir)) + # check if the git branch is correctly checked out assert ( subprocess.run( - f"cd {str(tmp_path / 'test_prepare_env/spack-environments')} && git branch", + f"cd {str(release_base_dir/spack_environments)} && git branch", shell=True, capture_output=True, ) .stdout.decode("utf-8") .split("\n")[0] - == "* dev-23a" + == f"* {mpsd_release_to_test}" ) - # make sure running the command again raises ValueError - with pytest.raises(ValueError): - run = mod.builder( - release="dev-23a", - cmd=None, - target_dir=str(tmp_path / "test_prepare_env"), - 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=str(tmp_path / "test_prepare_env"), - skip_build_cache=False, - ) - run.skip_dir_check = True - run.run() - # clean up the temporary directory - shutil.rmtree(str(tmp_path / "test_prepare_env")) def test_setup_log_cmd(tmp_path): -- GitLab