From 5f0e57c1660e9cac64b23d3acd906c3e121649a5 Mon Sep 17 00:00:00 2001
From: adrianciu <adrian.ciu@codemart.ro>
Date: Tue, 1 Apr 2025 14:32:24 +0300
Subject: [PATCH] VT-101: fixed warnings from tests

---
 .../spack_from_cache_test.py                  | 47 ++++++++++++++++---
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/dedal/tests/integration_tests/spack_from_cache_test.py b/dedal/tests/integration_tests/spack_from_cache_test.py
index 9bf2991a..206fdbfe 100644
--- a/dedal/tests/integration_tests/spack_from_cache_test.py
+++ b/dedal/tests/integration_tests/spack_from_cache_test.py
@@ -9,8 +9,8 @@ from dedal.utils.utils import file_exists_and_not_empty, count_files_in_folder
 from dedal.utils.variables import test_spack_env_git, ebrains_spack_builds_git
 
 
-def test_spack_from_cache_setup(tmp_path):
-    install_dir = tmp_path
+def setup(path):
+    install_dir = path
     env = SpackDescriptor('test-spack-env', install_dir, test_spack_env_git)
     repo = SpackDescriptor('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
     concretization_dir = install_dir / 'concretize'
@@ -19,6 +19,11 @@ def test_spack_from_cache_setup(tmp_path):
                                buildcache_dir=buildcache_dir)
     spack_config.add_repo(repo)
     spack_operation = SpackOperationCreator.get_spack_operator(spack_config, use_cache=True)
+    return spack_operation, concretization_dir, buildcache_dir
+
+
+def test_spack_from_cache_setup(tmp_path):
+    spack_operation, concretization_dir, buildcache_dir = setup(tmp_path)
     assert isinstance(spack_operation, SpackOperationUseCache)
     spack_operation.install_spack(bashrc_path=str(tmp_path / Path('.bashrc')))
     spack_operation.setup_spack_env()
@@ -27,26 +32,54 @@ def test_spack_from_cache_setup(tmp_path):
     assert file_exists_and_not_empty(concretization_download_file_path) == True
     assert count_files_in_folder(buildcache_dir) == num_tags
     assert 'local_cache' in spack_operation.mirror_list()
-    return spack_operation
 
 
 def test_spack_from_cache_concretize(tmp_path):
-    spack_operation = test_spack_from_cache_setup(tmp_path)
+    spack_operation, concretization_dir, buildcache_dir = setup(tmp_path)
+    assert isinstance(spack_operation, SpackOperationUseCache)
+    spack_operation.install_spack(bashrc_path=str(tmp_path / Path('.bashrc')))
+    spack_operation.setup_spack_env()
+    num_tags = len(spack_operation.build_cache.list_tags())
+    concretization_download_file_path = concretization_dir / 'spack.lock'
+    assert file_exists_and_not_empty(concretization_download_file_path) == True
+    assert count_files_in_folder(buildcache_dir) == num_tags
+    assert 'local_cache' in spack_operation.mirror_list()
     assert spack_operation.concretize_spack_env() == False
     concretization_file_path = spack_operation.env_path / 'spack.lock'
     assert file_exists_and_not_empty(concretization_file_path) == True
-    return spack_operation
 
 
 def test_spack_from_cache_install_1(tmp_path):
-    spack_operation = test_spack_from_cache_concretize(tmp_path)
+    spack_operation, concretization_dir, buildcache_dir = setup(tmp_path)
+    assert isinstance(spack_operation, SpackOperationUseCache)
+    spack_operation.install_spack(bashrc_path=str(tmp_path / Path('.bashrc')))
+    spack_operation.setup_spack_env()
+    num_tags = len(spack_operation.build_cache.list_tags())
+    concretization_download_file_path = concretization_dir / 'spack.lock'
+    assert file_exists_and_not_empty(concretization_download_file_path) == True
+    assert count_files_in_folder(buildcache_dir) == num_tags
+    assert 'local_cache' in spack_operation.mirror_list()
+    assert spack_operation.concretize_spack_env() == False
+    concretization_file_path = spack_operation.env_path / 'spack.lock'
+    assert file_exists_and_not_empty(concretization_file_path) == True
     install_result = spack_operation.install_packages(jobs=2, signed=True, debug=False)
     assert install_result.returncode == 0
     check_installed_spack_packages(spack_operation, tmp_path)
 
 
 def test_spack_from_cache_install_2(tmp_path):
-    spack_operation = test_spack_from_cache_concretize(tmp_path)
+    spack_operation, concretization_dir, buildcache_dir = setup(tmp_path)
+    assert isinstance(spack_operation, SpackOperationUseCache)
+    spack_operation.install_spack(bashrc_path=str(tmp_path / Path('.bashrc')))
+    spack_operation.setup_spack_env()
+    num_tags = len(spack_operation.build_cache.list_tags())
+    concretization_download_file_path = concretization_dir / 'spack.lock'
+    assert file_exists_and_not_empty(concretization_download_file_path) == True
+    assert count_files_in_folder(buildcache_dir) == num_tags
+    assert 'local_cache' in spack_operation.mirror_list()
+    assert spack_operation.concretize_spack_env() == False
+    concretization_file_path = spack_operation.env_path / 'spack.lock'
+    assert file_exists_and_not_empty(concretization_file_path) == True
     install_result = spack_operation.install_packages(jobs=2, signed=True, debug=False, test='root')
     assert install_result.returncode == 0
     check_installed_spack_packages(spack_operation, tmp_path)
-- 
GitLab