-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths: | ||
- ".github/workflows/unit-tests.yaml" | ||
- "tests/**" | ||
- "assembly_finder/**" | ||
- "setup.py" | ||
pull_request: | ||
branches: ["main"] | ||
paths: | ||
- ".github/workflows/unit-tests.yaml" | ||
- "tests/**" | ||
- "assembly_finder/**" | ||
- "setup.py" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
|
||
defaults: | ||
run: | ||
shell: bash -el {0} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos-latest, ubuntu-latest] | ||
python-version: ["3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: "actions/checkout@v3" | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: conda-incubator/setup-miniconda@v3 | ||
with: | ||
auto-update-conda: true | ||
miniforge-version: "latest" | ||
miniforge-variant: Mambaforge | ||
use-mamba: true | ||
mamba-version: "*" | ||
channels: conda-forge,bioconda,defaults | ||
channel-priority: strict | ||
activate-environment: assembly_finder | ||
python-version: ${{ matrix.python-version }} | ||
auto-activate-base: false | ||
|
||
- name: "Test and generate coverage report on ${{ matrix.os }} for Python ${{ matrix.python-version }}" | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install pytest coverage | ||
python -m pip install . | ||
coverage run -m pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import subprocess | ||
from pathlib import Path | ||
import pytest | ||
import shutil | ||
import os | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def tmp_dir(tmpdir_factory): | ||
return tmpdir_factory.mktemp("tmp") | ||
|
||
|
||
test_data_path = Path("assembly_finder/test_data") | ||
outdir = Path("test_out") | ||
|
||
|
||
def remove_directory(dir_path): | ||
if os.path.exists(dir_path): | ||
shutil.rmtree(dir_path) | ||
|
||
|
||
def exec_command(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE): | ||
"""executes shell command and returns stdout if completes exit code 0 | ||
Parameters | ||
---------- | ||
cmnd : str | ||
shell command to be executed | ||
stdout, stderr : streams | ||
Default value (PIPE) intercepts process output, setting to None | ||
blocks this.""" | ||
|
||
proc = subprocess.Popen(cmnd, shell=True, stdout=stdout, stderr=stderr) | ||
out, err = proc.communicate() | ||
if proc.returncode != 0: | ||
raise RuntimeError(f"FAILED: {cmnd}\n{err}") | ||
return out.decode("utf8") if out is not None else None | ||
|
||
|
||
def test_cli(): | ||
exec_command("assembly_finder -h") | ||
exec_command("assembly_finder -v") | ||
|
||
|
||
def test_taxons(): | ||
"""download genomes from taxons""" | ||
exec_command(f"assembly_finder -i {test_data_path}/taxons.tsv --output {outdir}") | ||
remove_directory(outdir) | ||
|
||
|
||
def test_accessions(): | ||
"""download genomes from accessions""" | ||
exec_command( | ||
f"assembly_finder -i {test_data_path}/accessions.txt --accession --output {outdir}" | ||
) | ||
remove_directory(outdir) |