Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard committed Dec 11, 2023
1 parent 2f34f6d commit 79feb5c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cg/meta/workflow/microsalt/quality_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ def is_qc_required(self, case_run_dir: Path | None, case_id: str) -> bool:
LOG.info(f"Performing QC on case {case_id}")
return True

def sample_total_reads_qc(self, sample: Sample) -> bool:
def sample_total_reads_qc(self, sample_id: str) -> bool:
pass
2 changes: 1 addition & 1 deletion cg/meta/workflow/microsalt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def is_total_reads_above_failure_threshold(sample_reads: int, target_reads: int) -> bool:
return sample_reads <= target_reads * MicrosaltQC.TARGET_READS_FAIL_THRESHOLD
return sample_reads > target_reads * MicrosaltQC.TARGET_READS_FAIL_THRESHOLD
Empty file.
52 changes: 33 additions & 19 deletions tests/meta/workflow/microsalt/test_quality_control.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
import pytest

from cg.constants.constants import MicrosaltQC
from cg.meta.workflow.microsalt.utils import is_total_reads_above_failure_threshold

TARGET_READS_FAIL_THRESHOLD = MicrosaltQC.TARGET_READS_FAIL_THRESHOLD

test_cases = [
(TARGET_READS_FAIL_THRESHOLD * 100, 100, False, "sufficient_reads"),
(TARGET_READS_FAIL_THRESHOLD * 100 - 1, 100, True, "just_below_threshold"),
(0, 100, True, "edge_case_no_reads"),
(TARGET_READS_FAIL_THRESHOLD * 100, 0, False, "edge_case_no_target_reads"),
]
def test_sample_total_reads_passing():
# GIVEN a sample with sufficient reads
sample_reads = 100
target_reads = 100

# WHEN checking if the sample has sufficient reads
passes_reads_threshold = is_total_reads_above_failure_threshold(
sample_reads=sample_reads, target_reads=target_reads
)

# THEN it passes
assert passes_reads_threshold


def test_sample_total_reads_failing():
# GIVEN a sample with insufficient reads
sample_reads = 50
target_reads = 100

# WHEN checking if the sample has sufficient reads
passes_reads_threshold = is_total_reads_above_failure_threshold(
sample_reads=sample_reads, target_reads=target_reads
)

# THEN it fails
assert not passes_reads_threshold


@pytest.mark.parametrize(
"sample_reads, target_reads, expected_result, test_id", test_cases, ids=lambda x: x[-1]
)
def test_is_total_reads_above_failure_threshold(
sample_reads, target_reads, expected_result, test_id
):
# GIVEN a sample with a number of reads and a target number of reads
def test_sample_total_reads_failing_without_reads():
# GIVEN a sample without reads
sample_reads = 0
target_reads = 100

# WHEN checking if the sample has sufficient reads
result = is_total_reads_above_failure_threshold(
passes_reads_threshold = is_total_reads_above_failure_threshold(
sample_reads=sample_reads, target_reads=target_reads
)

# THEN the result should be as expected
assert result == expected_result, f"Test failed for {test_id}"
# THEN it fails
assert not passes_reads_threshold

0 comments on commit 79feb5c

Please sign in to comment.