Skip to content

Fix tests #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2025
Merged
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
2 changes: 1 addition & 1 deletion src/ccbr_tools/peek.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def pprint(headlist, data, linelength, fn):


def peek(filename, buffer, delim="\t"):
pargs()
# pargs()

# Getting contents of first line
try:
Expand Down
4 changes: 2 additions & 2 deletions src/ccbr_tools/pipeline/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Biowulf(Cluster):
GROUP = "CCBR_Pipeliner"
PIPELINES_HOME = pathlib.Path("/data/CCBR_Pipeliner/Pipelines")
TOOLS_HOME = pathlib.Path("/data/CCBR_Pipeliner/Tools")
CONDA_ACTIVATE = '. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311'
CONDA_ACTIVATE = ". '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311"

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -102,7 +102,7 @@ class FRCE(Cluster):
GROUP = "nci-frederick-ccbr-pipelines"
PIPELINES_HOME = pathlib.Path("/mnt/projects/CCBR-Pipelines/pipelines")
TOOLS_HOME = pathlib.Path("/mnt/projects/CCBR-Pipelines/tools")
CONDA_ACTIVATE = '. "/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh" && conda activate py311'
CONDA_ACTIVATE = ". '/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh' && conda activate py311"

def __init__(self):
super().__init__()
Expand Down
4 changes: 3 additions & 1 deletion src/ccbr_tools/pipeline/nextflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def run(
if "-preview" not in args_dict.keys():
if hpc:
hpc_modules = hpc.modules["nxf"]
preview_command = f'bash -c "module load {hpc_modules} && {hpc.env_vars} && {nextflow_command} -preview"'
preview_command = (
f'bash -c "module load {hpc_modules} && {nextflow_command} -preview"'
)
else:
preview_command = nextflow_command + " -preview"
msg_box("Pipeline Preview", errmsg=preview_command)
Expand Down
5 changes: 3 additions & 2 deletions src/ccbr_tools/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
)
if debug:
return msg
with smtplib.SMTP("localhost") as server:
server.send_message(msg)
else:
with smtplib.SMTP("localhost") as server:
server.send_message(msg)

Check warning on line 54 in src/ccbr_tools/send_email.py

View check run for this annotation

Codecov / codecov/patch

src/ccbr_tools/send_email.py#L53-L54

Added lines #L53 - L54 were not covered by tests
2 changes: 1 addition & 1 deletion src/ccbr_tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def shell_run(command_str, capture_output=True, check=True, shell=True, text=Tru
'/bin/sh: invalid_command: command not found\n'
"""
out = subprocess.run(
command_str, capture_output=capture_output, shell=shell, text=text, check=check
command_str, capture_output=capture_output, check=check, shell=shell, text=text
)
if capture_output:
return_val = concat_newline(out.stdout, out.stderr)
Expand Down
16 changes: 16 additions & 0 deletions tests/data/templates/submit_slurm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
#SBATCH --cpus-per-task=1
#SBATCH --mem=1g
#SBATCH --time=1-00:00:00
#SBATCH --parsable
#SBATCH -J "CCBR_nxf"
#SBATCH --mail-type=BEGIN,END,FAIL
#SBATCH --output "log/slurm_%j.log"
#SBATCH --error "log/slurm_%j.log"

module load nextflow

export SINGULARITY_CACHEDIR=/gpfs/gsfs10/users/CCBR_Pipeliner/Tools/ccbr_tools/tools-dev-sovacool/.singularity
if ! command -v spooker 2>&1 >/dev/null; then export PATH="$PATH:/data/CCBR_Pipeliner/Tools/ccbr_tools/v0.2/bin/"; fi

nextflow run main.nf -stub
15 changes: 12 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

import os
import pathlib
import pytest
import tempfile

is_ci = (
os.environ.get("CI", "false") == "true"
) # Set CI to false if not in a CI environment


def test_version_flag():
assert shell_run("ccbr_tools -v").startswith("ccbr_tools, version ")
version = shell_run("ccbr_tools --version")
assert version.startswith("ccbr_tools, version ")


@pytest.mark.skipif(is_ci, reason="Skip on CI")
def test_version_cmd():
assert shell_run("ccbr_tools version --debug").startswith("VERSION file path")
version = shell_run("ccbr_tools version --debug")
assert version.startswith("VERSION file path")


def test_help():
Expand Down Expand Up @@ -52,6 +60,7 @@ def test_help_peek():
assert "USAGE: peek <file.tsv> [buffer]" in shell_run("peek -h")


@pytest.mark.skipif(is_ci, reason="Skip on CI")
def test_send_email():
assert "" == shell_run("ccbr_tools send-email -d")

Expand Down Expand Up @@ -79,7 +88,7 @@ def test_install():
output = shell_run("ccbr_tools install champagne v0.3.0 --hpc biowulf", check=False)
assert (
output
== """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
== """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
pip install git+https://github.com/CCBR/CHAMPAGNE.git@v0.3.0 -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nextflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tempfile

from ccbr_tools.pipeline.nextflow import run, init
from ccbr_tools.pipeline.hpc import Biowulf, FRCE
from ccbr_tools.pipeline.hpc import Biowulf, FRCE, get_hpc
from ccbr_tools.shell import exec_in_context


Expand Down
4 changes: 2 additions & 2 deletions tests/test_pipeline_hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_hpc_biowulf():
"<class 'ccbr_tools.pipeline.hpc.Biowulf'>({'name': 'biowulf'"
),
hpc.CONDA_ACTIVATE
== '. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311',
== ". '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311",
]
)

Expand All @@ -26,7 +26,7 @@ def test_hpc_frce():
"/mnt/projects/CCBR-Pipelines/bin" in hpc.env_vars,
hpc.singularity_sif_dir == "/mnt/projects/CCBR-Pipelines/SIFs",
hpc.CONDA_ACTIVATE
== '. "/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh" && conda activate py311',
== ". '/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh' && conda activate py311",
]
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_install():
)
assert (
result
== """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
== """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
pip install git+https://github.com/CCBR/CHAMPAGNE.git@v0.3.0 -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0
Expand All @@ -67,7 +67,7 @@ def test_install_dev():
)
assert (
result
== """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
== """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
pip install git+https://github.com/CCBR/CHAMPAGNE.git@main -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev
chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev
chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev
Expand All @@ -86,7 +86,7 @@ def test_custom():
)
assert (
result
== """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
== """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311
pip install git+https://github.com/CCBR/cooltool.git@v1.0.0 -t /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0
chmod -R a+rX /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0
chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0
Expand Down
13 changes: 13 additions & 0 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile

from ccbr_tools.templates import read_template, use_template, use_quarto_ext
from ccbr_tools.pipeline.hpc import get_hpc


def test_read_template():
Expand Down Expand Up @@ -38,6 +39,18 @@ def test_use_template():
assert all(assertions)


def generate_slurm_template():
hpc = get_hpc(debug="biowulf")
use_template(
"submit_slurm.sh",
output_filepath="tests/data/templates/submit_slurm.sh",
PIPELINE="CCBR_nxf",
MODULES=hpc.modules["nxf"],
ENV_VARS=hpc.env_vars,
RUN_COMMAND="nextflow run main.nf -stub",
)


def test_use_template_blanks():
with tempfile.TemporaryDirectory() as tmp_dir:
out_filepath = pathlib.Path(tmp_dir) / "test.sh"
Expand Down
Loading