Skip to content

Commit

Permalink
Merge pull request CCBR#114 from CCBR/pytest
Browse files Browse the repository at this point in the history
test: setup basic cli tests with pytest
  • Loading branch information
slsevilla authored Feb 28, 2024
2 parents 3975071 + 3bb35b6 commit 2175dc5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
Dryrun_Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: docker://snakemake/snakemake:v5.24.2
- name: Dry-run pipeline
run: |
docker run -v $PWD:/opt2 -w /opt2 snakemake/snakemake:v5.24.2 \
python ./renee run \
python ./src/renee/__main__.py run \
--input .tests/KO_S3.R1.fastq.gz .tests/KO_S3.R2.fastq.gz .tests/KO_S4.R1.fastq.gz .tests/KO_S4.R2.fastq.gz .tests/WT_S1.R1.fastq.gz .tests/WT_S1.R2.fastq.gz .tests/WT_S2.R1.fastq.gz .tests/WT_S2.R2.fastq.gz \
--output output \
--genome config/genomes/biowulf/hg38_30.json \
Expand All @@ -29,3 +29,38 @@ jobs:
run: |
docker run -v $PWD:/opt2 snakemake/snakemake:v5.24.2 snakemake --lint -s /opt2/output/workflow/Snakefile -d /opt2/output || \
echo 'There may have been a few warnings or errors. Please read through the log to determine if its harmless.'
Test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: pip
run: |
python -m pip install --upgrade pip setuptools pytest
- name: check CLI basics
run: |
./bin/renee --help
./bin/renee --version
- name: Test
run: |
python -m pytest
build-status: # https://github.com/orgs/community/discussions/4324#discussioncomment-3477871
runs-on: ubuntu-latest
needs: [Dryrun_Lint, Test]
if: always()
steps:
- name: Successful build
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Failing build
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
2 changes: 1 addition & 1 deletion bin/redirect
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ elif [[ $ISFRCE == true ]];then
export PATH="/mnt/projects/CCBR-Pipelines/bin:$PATH"
fi

${TOOLDIR}/${TOOLNAME} "$@" || true
${TOOLDIR}/src/renee/__main__.py "$@" || true
Empty file added src/renee/__init__.py
Empty file.
15 changes: 8 additions & 7 deletions renee → src/renee/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

# Pipeline Metadata and globals
# __version__ = "v2.5.2"
RENEE_PATH = os.path.dirname(os.path.abspath(__file__))
RENEE_PATH = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)

vfile = open(os.path.join(RENEE_PATH, "VERSION"), "r")
__version__ = "v" + vfile.read()
__version__ = __version__.strip()
Expand Down Expand Up @@ -1101,7 +1104,6 @@ def run(sub_args):
Parsed arguments for run sub-command
"""
# Get PATH to RENEE git repository for copying over pipeline resources
git_repo = os.path.dirname(os.path.abspath(__file__))

# hpcname is either biowulf, frce, or blank
hpcname = get_hpcname()
Expand All @@ -1110,14 +1112,14 @@ def run(sub_args):
):
# Initialize working directory, copy over required pipeline resources
input_files = initialize(
sub_args, repo_path=git_repo, output_path=sub_args.output
sub_args, repo_path=RENEE_PATH, output_path=sub_args.output
)

# Step pipeline for execution, create config.json config file from templates
config = setup(
sub_args,
ifiles=input_files,
repo_path=git_repo,
repo_path=RENEE_PATH,
output_path=sub_args.output,
)
# load config from existing file
Expand Down Expand Up @@ -1370,7 +1372,6 @@ def build(sub_args):
"""
# Get PATH to RENEE git repository
# for copying over pipeline resources
git_repo = os.path.dirname(os.path.abspath(__file__))

# Build Output directory
output_path = os.path.abspath(sub_args.output)
Expand All @@ -1379,7 +1380,7 @@ def build(sub_args):
# initialize, copy resources, and
# generate config file
additional_bind_paths = configure_build(
sub_args=sub_args, git_repo=git_repo, output_path=output_path
sub_args=sub_args, git_repo=RENEE_PATH, output_path=output_path
)

# Add any additional bindpaths
Expand Down Expand Up @@ -1588,7 +1589,7 @@ def parsed_arguments(name, description):

# Adding Version information
parser.add_argument(
"--version", action="version", version="%(prog)s {}".format(__version__)
"--version", action="version", version="renee {}".format(__version__)
)

# Create sub-command parser
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
import subprocess
from src.renee.__main__ import exists


def test_help():
output = subprocess.run(
"src/renee/__main__.py --help", capture_output=True, shell=True, text=True
).stdout
assert "RENEE" in output


def test_version():
output = subprocess.run(
"src/renee/__main__.py --version", capture_output=True, shell=True, text=True
).stdout
assert "renee v" in output

0 comments on commit 2175dc5

Please sign in to comment.