Skip to content

Commit

Permalink
feat: added unit tests for OffTargetDetector.__init__ validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ameynert committed Jan 7, 2025
1 parent 97c929e commit b5ffc86
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/offtarget/test_offtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,45 @@ class CustomPrimer(Oligo):
# 2. Return a list of the same type.
# NB: we're ignoring the unused value error because we want to check the type hint
filtered_primers: list[CustomPrimer] = detector.filter(primers) # noqa: F841


# fmt: off
@pytest.mark.parametrize(
(
"max_primer_hits,max_primer_pair_hits,min_primer_pair_hits,three_prime_region_length,"
"max_mismatches_in_three_prime_region,max_mismatches,max_amplicon_size,expected_error"
),
[
(-1, 1, 1, 20, 0, 0, 1, "'max_primer_hits' must be greater than or equal to 0. Saw -1"),
(1, -1, 1, 20, 0, 0, 1, "'max_primer_pair_hits' must be greater than or equal to 0. Saw -1"), # noqa: E501
(1, 1, -1, 20, 0, 0, 1, "'min_primer_pair_hits' must be greater than or equal to 0. Saw -1"), # noqa: E501
(1, 1, 1, 0, 0, 0, 1, "'three_prime_region_length' must be greater than 0. Saw 0"),
(1, 1, 1, 20, -1, 0, 1, "'max_mismatches_in_three_prime_region' must be between 0 and 20 inclusive. Saw -1"), # noqa: E501
(1, 1, 1, 20, 21, 0, 1, "'max_mismatches_in_three_prime_region' must be between 0 and 20 inclusive. Saw 21"), # noqa: E501
(1, 1, 1, 20, 0, -1, 1, "'max_mismatches' must be greater than or equal to 0. Saw -1"),
(1, 1, 1, 20, 0, 0, 0, "'max_amplicon_size' must be greater than 0. Saw 0"),
],
)
# fmt: on
def test_init(
ref_fasta: Path,
max_primer_hits: int,
max_primer_pair_hits: int,
min_primer_pair_hits: int,
three_prime_region_length: int,
max_mismatches_in_three_prime_region: int,
max_mismatches: int,
max_amplicon_size: int,
expected_error: str,
) -> None:
with pytest.raises(ValueError, match=expected_error):
OffTargetDetector(
ref=ref_fasta,
max_primer_hits=max_primer_hits,
max_primer_pair_hits=max_primer_pair_hits,
min_primer_pair_hits=min_primer_pair_hits,
three_prime_region_length=three_prime_region_length,
max_mismatches_in_three_prime_region=max_mismatches_in_three_prime_region,
max_mismatches=max_mismatches,
max_amplicon_size=max_amplicon_size,
)

0 comments on commit b5ffc86

Please sign in to comment.