Skip to content
Snippets Groups Projects
Commit a7d40965 authored by Adrian Ciu's avatar Adrian Ciu
Browse files

esd: added test stage in CI/CD pipeline

parent de485ef1
No related branches found
No related tags found
1 merge request!1feat: restructure repo into a proper Python tool/library
Pipeline #58130 passed with stages
in 32 seconds
stages:
- build
- test
variables:
BUILD_ENV_DOCKER_IMAGE: docker-registry.ebrains.eu/esd/tmp:latest
......@@ -7,7 +8,7 @@ variables:
build-spack-env-on-runner:
stage: build
tags:
- esd_image
- docker-runner # esd_image
image: $BUILD_ENV_DOCKER_IMAGE
script:
- /usr/sbin/sysctl user.max_user_namespaces
......@@ -18,3 +19,19 @@ build-spack-env-on-runner:
# mkdir -p apptainer-install/
# curl -s https://raw.githubusercontent.com/apptainer/apptainer/main/tools/install-unprivileged.sh | bash -s - apptainer-install/
- apptainer version
testing:
stage: test
tags:
- docker-runner
image: python:latest # $BUILD_ENV_DOCKER_IMAGE
script:
- pip install -e .
- pytest ./esd/tests/ --junitxml=test-results.xml
artifacts:
when: always
reports:
junit: test-results.xml
paths:
- test-results.xml
expire_in: 1 week
\ No newline at end of file
import pytest
from pathlib import Path
from esd.utils.utils import clean_up
@pytest.fixture
def temp_directories(tmp_path):
"""
Create temporary directories with files and subdirectories for testing.
"""
test_dirs = []
for i in range(3):
dir_path = tmp_path / f"test_dir_{i}"
dir_path.mkdir()
test_dirs.append(str(dir_path))
# Add a file to the directory
file_path = dir_path / f"file_{i}.txt"
file_path.write_text(f"This is a test file in {dir_path}")
# Add a subdirectory with a file
sub_dir = dir_path / f"subdir_{i}"
sub_dir.mkdir()
sub_file = sub_dir / f"sub_file_{i}.txt"
sub_file.write_text(f"This is a sub file in {sub_dir}")
return test_dirs
def test_clean_up(temp_directories, mocker):
"""
Test the clean_up function to ensure directories and contents are removed.
"""
# Mock the logger using pytest-mock's mocker fixture
mock_logger = mocker.MagicMock()
# Ensure directories exist before calling clean_up
for dir_path in temp_directories:
assert Path(dir_path).exists()
clean_up(temp_directories, mock_logger)
for dir_path in temp_directories:
assert not Path(dir_path).exists()
for dir_path in temp_directories:
mock_logger.info.assert_any_call(f"Removing {Path(dir_path).resolve()}")
def test_clean_up_nonexistent_dirs(mocker):
"""
Test the clean_up function with nonexistent directories.
"""
# Mock the logger using pytest-mock's mocker fixture
mock_logger = mocker.MagicMock()
nonexistent_dirs = ["nonexistent_dir_1", "nonexistent_dir_2"]
clean_up(nonexistent_dirs, mock_logger)
for dir_path in nonexistent_dirs:
mock_logger.info.assert_any_call(f"{Path(dir_path).resolve()} does not exist")
def depends(ctx):
ctx("spack", branch="visionary")
def options(opt):
pass
def configure(cfg):
pass
def build(bld):
# install /bin
for bin in bld.path.ant_glob('bin/**/*'):
bld.install_as('${PREFIX}/%s' % bin.path_from(bld.path), bin)
# install /lib
for lib in bld.path.ant_glob('lib/**/*'):
bld.install_as('${PREFIX}/%s' % lib.path_from(bld.path), lib)
# install /share
for share in bld.path.ant_glob('share/**/*'):
bld.install_as('${PREFIX}/%s' % share.path_from(bld.path), share)
......@@ -15,5 +15,7 @@ requires-python = ">=3.10"
dependencies = [
"oras",
"spack",
"ruamel.yaml"
"ruamel.yaml",
"pytest",
"pytest-mock",
]
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment