From 9be6826824c1f1fd9e5ec525f01a8d1c404e5d3e Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Thu, 15 Feb 2024 16:37:38 -0500 Subject: [PATCH 1/3] test: setup basic cli tests with pytest --- .github/workflows/main.yaml | 39 ++++++++++++++++++++++++++++++++-- bin/redirect | 2 +- src/renee/__init__.py | 0 renee => src/renee/__main__.py | 7 ++++-- tests/test_cli.py | 17 +++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/renee/__init__.py rename renee => src/renee/__main__.py (99%) create mode 100644 tests/test_cli.py diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 671d513..7778468 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 ./renee.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 \ @@ -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 diff --git a/bin/redirect b/bin/redirect index 8f74330..824d007 100755 --- a/bin/redirect +++ b/bin/redirect @@ -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 diff --git a/src/renee/__init__.py b/src/renee/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/renee b/src/renee/__main__.py similarity index 99% rename from renee rename to src/renee/__main__.py index cb25b19..e03f445 100755 --- a/renee +++ b/src/renee/__main__.py @@ -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() @@ -1588,7 +1591,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 diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..71f5c96 --- /dev/null +++ b/tests/test_cli.py @@ -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 From efa1cf0a6a4d3d6a2952fb60430ae5ef9c7065e1 Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Fri, 16 Feb 2024 08:59:20 -0500 Subject: [PATCH 2/3] ci: fix path to main entry point --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 7778468..d38abe3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -17,7 +17,7 @@ jobs: - name: Dry-run pipeline run: | docker run -v $PWD:/opt2 -w /opt2 snakemake/snakemake:v5.24.2 \ - python ./renee.py 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 \ From 3bb35b6fa84928871bc225449d3c17c78ab074d2 Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Fri, 16 Feb 2024 09:22:12 -0500 Subject: [PATCH 3/3] fix: use corrected renee project dir path --- src/renee/__main__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/renee/__main__.py b/src/renee/__main__.py index e03f445..7996560 100755 --- a/src/renee/__main__.py +++ b/src/renee/__main__.py @@ -1104,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() @@ -1113,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 @@ -1373,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) @@ -1382,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