Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ jobs:
name: pytest of BABS
no_output_timeout: 1h
command: |
docker build \
-t pennlinc/slurm-docker-ci:unstable \
-f Dockerfile_testing .

# Make a directory that will hold the test artifacts
mkdir -p ${HOME}/e2e-testing
docker run -it \
-v ${PWD}:/tests \
-v ${PWD}:/babs \
-v ${HOME}/e2e-testing:/test-temp:rw \
-w /babs \
-h slurmctl --cap-add sys_admin \
--privileged \
pennlinc/slurm-docker-ci:unstable \
pennlinc/slurm-docker-ci:0.14 \
bash -c "pip install -e .[tests] && \
pytest -n 4 -sv \
--durations=0 \
--timeout=300 \
--junitxml=/test-temp/junit.xml \
--cov-report term-missing \
--cov-report xml:/test-temp/coverage.xml \
--cov=babs \
/babs
/babs/tests/"

- store_test_results:
path: /home/circleci/e2e-testing/junit.xml
Expand All @@ -54,22 +51,10 @@ jobs:
- checkout:
path: /home/circleci/src/babs
- run:
name: pytest of BABS
name: e2e SLURM tests
no_output_timeout: 1h
command: |
docker build \
-t pennlinc/slurm-docker-ci:unstable \
-f Dockerfile_testing .

# Make a directory that will hold the test artifacts
mkdir -p ${HOME}/e2e-testing
docker run -it \
-v ${PWD}:/tests \
-v ${HOME}/e2e-testing:/test-temp:rw \
-h slurmctl --cap-add sys_admin \
--privileged \
pennlinc/slurm-docker-ci:unstable \
/tests/tests/e2e-slurm/container/walkthrough-tests.sh
E2E_DIR=${HOME}/e2e-testing bash tests/e2e_in_docker.sh

- run:
name: clean up test artifacts
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile_testing

This file was deleted.

21 changes: 19 additions & 2 deletions docs/developer_how_to_test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ Manually run pytest

The easiest way to run pytest is to run the ``tests/pytest_in_docker.sh`` script
from the root directory of BABS.
This will build a docker container that has a running SLURM job scheduler system.
It will also install the local copy of BABS and run the pytests in the container.
This runs the tests inside a Docker container that has a running SLURM job scheduler system,
and installs the local copy of BABS at runtime via volume mount.

.. code-block:: bash

bash tests/pytest_in_docker.sh

To run the end-to-end walkthrough tests (``babs init`` → ``submit`` → ``merge``):

.. code-block:: bash

bash tests/e2e_in_docker.sh

By default, e2e test artifacts go to a temporary directory under ``/tmp``.
To specify a location (e.g., for inspection after the run):

.. code-block:: bash

E2E_DIR=/path/to/output bash tests/e2e_in_docker.sh

-----------------------------
Automatic pytest via CircleCI
Expand Down
19 changes: 7 additions & 12 deletions tests/e2e_in_docker.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/bin/bash
mkdir -p "${HOME}"/projects/e2e-testing
docker build --platform linux/amd64 \
-t pennlinc/slurm-docker-ci:unstable \
-f Dockerfile_testing .
E2E_DIR="${E2E_DIR:-$(mktemp -d /tmp/babs-e2e-XXXXXX)}"
mkdir -p "${E2E_DIR}"
echo "E2E_DIR=${E2E_DIR}"
docker run -it \
--platform linux/amd64 \
-v "${HOME}"/projects/babs:/tests \
-v "${HOME}"/projects/e2e-testing:/test-temp:rw \
-v "$(pwd)":/tests \
-v "${E2E_DIR}":/test-temp:rw \
-h slurmctl --cap-add sys_admin \
--privileged \
pennlinc/slurm-docker-ci:unstable #\
#/babs/tests/e2e-slurm/container/walkthrough-tests.sh


#pytest -svx --pdb \
#/babs/tests
pennlinc/slurm-docker-ci:0.14 \
/tests/tests/e2e-slurm/container/walkthrough-tests.sh
13 changes: 6 additions & 7 deletions tests/pytest_in_docker.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/bash
docker build --platform linux/amd64 -t pennlinc/slurm-docker-ci:unstable -f Dockerfile_testing .
docker run -it \
--platform linux/amd64 \
-h slurmctl --cap-add sys_admin \
--privileged \
-v "${HOME}"/projects/babs:/babs \
pennlinc/slurm-docker-ci:unstable \
pytest -svx \
-v "$(pwd)":/babs \
-w /babs \
pennlinc/slurm-docker-ci:0.14 \
bash -c "pip install -e .[tests] && pytest -svx \
--cov-report=term-missing \
--cov-report=xml \
--cov-report=xml:/tmp/coverage.xml \
--cov=babs \
--pdb \
/babs/tests/

/babs/tests/"
8 changes: 4 additions & 4 deletions tests/test_generate_bidsapp_runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_get_input_unipping_cmds():


@pytest.mark.parametrize(('input_datasets', 'config_file', 'processing_level'), testing_pairs)
def test_generate_bidsapp_runscript(input_datasets, config_file, processing_level):
def test_generate_bidsapp_runscript(input_datasets, config_file, processing_level, tmp_path):
"""Test that the bidsapp runscript is generated correctly."""
config_path = NOTEBOOKS_DIR / config_file
container_name = config_file.split('_')[1]
Expand All @@ -130,7 +130,7 @@ def test_generate_bidsapp_runscript(input_datasets, config_file, processing_leve
templateflow_home='/path/to/templateflow_home',
)

out_fn = Path('.') / f'{config_path.name}_{processing_level}.sh'
out_fn = tmp_path / f'{config_path.name}_{processing_level}.sh'
with open(out_fn, 'w') as f:
f.write(script_content)
passed, status = run_shellcheck(str(out_fn))
Expand Down Expand Up @@ -164,7 +164,7 @@ def run_shellcheck(script_path):
return False, str(e)


def test_generate_pipeline_runscript():
def test_generate_pipeline_runscript(tmp_path):
"""Test that the pipeline runscript is generated correctly."""
config_path = NOTEBOOKS_DIR / 'eg_nordic-fmriprep_pipeline.yaml'
config = read_yaml(config_path)
Expand All @@ -180,7 +180,7 @@ def test_generate_pipeline_runscript():
final_zip_foldernames=config.get('zip_foldernames', {}),
)

out_fn = Path('.') / f'{config_path.name}_pipeline.sh'
out_fn = tmp_path / f'{config_path.name}_pipeline.sh'
with open(out_fn, 'w') as f:
f.write(script_content)
passed, status = run_shellcheck(str(out_fn))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generate_submit_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@


@pytest.mark.parametrize(('input_datasets', 'config_file', 'processing_level'), testing_pairs)
def test_generate_submit_script(input_datasets, config_file, processing_level):
def test_generate_submit_script(input_datasets, config_file, processing_level, tmp_path):
"""Test that the bidsapp runscript is generated correctly."""
config_path = NOTEBOOKS_DIR / config_file
container_name = config_file.split('_')[1]
Expand All @@ -107,7 +107,7 @@ def test_generate_submit_script(input_datasets, config_file, processing_level):
zip_foldernames=config['zip_foldernames'],
)

out_fn = Path('.') / f'participant_job_{config_path.name}_{processing_level}.sh'
out_fn = tmp_path / f'participant_job_{config_path.name}_{processing_level}.sh'
with open(out_fn, 'w') as f:
f.write(script_content)
passed, status = run_shellcheck(str(out_fn))
Expand Down
Loading