Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farchaab committed Apr 24, 2024
1 parent cd4dba0 commit 1f5f8bd
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/unit-tests.yml
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
55 changes: 55 additions & 0 deletions tests/test_assembly_finder.py
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)

0 comments on commit 1f5f8bd

Please sign in to comment.