Skip to content
Snippets Groups Projects
Commit dd65166d authored by Hugo Madge Leon's avatar Hugo Madge Leon
Browse files

first draft of tests + CI/CD

parent f72db0c0
No related branches found
No related tags found
3 merge requests!45Hugo new,!41I still don't know how this works,!40CI/CD, tests, and complete linting
default: # Set default
tags:
- docker
image: python:3.10-slim-buster
stages: # List of stages for jobs, and their order of execution
- build
- test
build-job: # This job runs in the build stage, which runs first.
stage: build
script:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install -e .
unit-test-job: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
script:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install -e .
- coverage run --source term_frag_sel -m pytest
- coverage report -m
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
script:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install -e .
#- flake8 --docstring-convention google readsequencer/ tests/
#- pylint readsequencer/ tests/
File moved
......@@ -6,8 +6,8 @@ import numpy as np
import pandas as pd
from pathlib import Path
from fragmentation import fragmentation
from utils import check_positive, check_prob
from term_frag_sel.fragmentation import fragmentation
from term_frag_sel.utils import check_positive, check_prob
def main(args: argparse.Namespace):
......@@ -62,7 +62,7 @@ def file_validation(fasta_file: str,
with open(fasta_file, "r") as handle:
fasta = SeqIO.parse(handle, "fasta")
if not any(fasta):
logger.exception("Input FASTA file is either empty or \
raise ValueError("Input FASTA file is either empty or \
incorrect file type.")
count_path = Path(counts_file)
......
......@@ -42,6 +42,6 @@ def check_prob(value: str) -> float:
"""
pvalue = float(value)
if pvalue <= 0 or pvalue > 1:
raise argparse.ArgumentTypeError("""%s is an invalid positive int
value""" % value)
raise argparse.ArgumentTypeError("""Expected a positive float between
0 and 1, but got {value}""")
return pvalue
"""Test cli.py functions."""
import pytest
from Bio import SeqIO
from term_frag_sel.cli import file_validation
with open("./test_files/test.fasta", "r") as handle:
fasta = SeqIO.parse(handle, "fasta")
def test_file():
"""Test check_positive function."""
assert file_validation(fasta, "", ",") == 1
with pytest.raises(FileNotFoundError):
file_validation("", "", ",")
This diff is collapsed.
"""Test utils.py functions."""
import pytest
from Bio import SeqIO
from term_frag_sel.fragmentation import fragmentation
with open("./test_files/test.fasta", "r") as handle:
fasta = SeqIO.parse(handle, "fasta")
# have to create the counts file
mu = 100
std = 10
a_prob = 0.22
c_prob = 0.28
t_prob = 0.25
g_prob = 0.25
def test_frag():
"""Test fragmentation function."""
with pytest.raises(TypeError):
fragmentation()
"""Test utils.py functions."""
import pytest
import argparse
from
from term_frag_sel.utils import check_positive, check_prob
def test_positive():
"""Test check_positive function."""
assert check_positive("1") == 1
assert check_positive("100") == 100
assert check_positive("0") == 100
assert check_positive("2.2") == 2
assert check_positive("2.6") == 3
with pytest.raises(argparse.ArgumentTypeError):
check_positive("-1")
with pytest.raises(argparse.ArgumentTypeError):
check_positive("string")
with pytest.raises(argparse.ArgumentTypeError):
check_positive("")
def test_prob():
"""Test check_prob function."""
assert check_prob("0.1") == 0.1
assert check_prob("1") == 1.0
with pytest.raises(argparse.ArgumentTypeError):
check_prob("0")
with pytest.raises(argparse.ArgumentTypeError):
check_prob("10")
with pytest.raises(argparse.ArgumentTypeError):
check_prob("-1")
with pytest.raises(argparse.ArgumentTypeError):
check_prob("string")
with pytest.raises(argparse.ArgumentTypeError):
check_prob("")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment