forked from naturalis/barcode_validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_result_ranks.py
78 lines (64 loc) · 3.44 KB
/
test_result_ranks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from barcode_validator.result import DNAAnalysisResult
@pytest.fixture
def dna_result():
return DNAAnalysisResult("test_process_id")
@pytest.mark.parametrize(
"seq_length,ambiguities,full_length,full_ambiguities,expected_barcode_rank,expected_full_rank,expected_messages", [
(650, 0, 1501, 0, 1, 1,
["\U0001F947\U0001F31F BIN compliant, perfect", "\U0001F947 Excellent full length, no ambiguities"]),
(500, 0, 1001, 0, 2, 2, ["\U0001F947 BIN compliant", "\U0001F948 Good full length, no ambiguities"]),
(650, 3, 1501, 3, 3, 3, ["\U0001F948 BIN compliant", "\u2753 Marker may be chimeric",
"\U0001F947 Excellent full length", "\u2757 Some ambiguities in full sequence"]),
(500, 3, 1001, 3, 4, 4,
["\U0001F949 BIN compliant", "\u2753 Marker may be chimeric", "\U0001F948 Good full length",
"\u2757 Some ambiguities in full sequence"]),
(450, 0, 1000, 3, 5, 4, ["\u26A0 Useful marker sequence", "\u2757 Not BIN compliant",
"\U0001F948 Good full length", "\u2757 Some ambiguities in full sequence"]),
(350, 0, 900, 0, 6, 5, ["\u26A0 Useful marker sequence", "\u203C Not BIN compliant",
"\U0001F949 Acceptable full length"]),
(250, 0, 800, 5, 7, 5, ["\u26A0 Useful marker sequence", "\u203C Not BIN compliant",
"\U0001F949 Acceptable full length", "\u2757 Some ambiguities in full sequence"]),
(200, 10, 700, 20, 8, 6, ["\u26D4 Unacceptable marker sequence", "\u26D4 Unacceptable full sequence"]),
])
def test_ranks_and_messages(dna_result, seq_length, ambiguities, full_length, full_ambiguities,
expected_barcode_rank, expected_full_rank, expected_messages):
dna_result.seq_length = seq_length
dna_result.ambiguities = ambiguities
dna_result.full_length = full_length
dna_result.full_ambiguities = full_ambiguities
barcode_rank, full_rank, messages = dna_result.calculate_ranks(verbosity=3)
assert barcode_rank == expected_barcode_rank
assert full_rank == expected_full_rank
for message in expected_messages:
assert message in messages
@pytest.mark.parametrize("verbosity,expected_message_count", [
(1, 1), # Only errors
(2, 2), # Errors and warnings
(3, 4), # Errors, warnings, and info
])
def test_verbosity_levels(dna_result, verbosity, expected_message_count):
dna_result.seq_length = 650
dna_result.ambiguities = 3
dna_result.full_length = 1501
dna_result.full_ambiguities = 3
_, _, messages = dna_result.calculate_ranks(verbosity=verbosity)
assert len(messages.split('\n')) == expected_message_count
def test_edge_case_marker(dna_result):
# Test when seq_length or ambiguities are None
dna_result.full_length = 1500
dna_result.full_ambiguities = 0
barcode_rank, full_rank, messages = dna_result.calculate_ranks(verbosity=1)
assert barcode_rank == 8
assert full_rank == 1
assert "\u26D4 Unacceptable marker sequence" in messages
def test_edge_case_full(dna_result):
# Test when full_length or full_ambiguities are None
dna_result.seq_length = 650
dna_result.ambiguities = 0
barcode_rank, full_rank, messages = dna_result.calculate_ranks(verbosity=1)
assert barcode_rank == 1
assert full_rank == 6
assert "\u26D4 Unacceptable full sequence" in messages
if __name__ == '__main__':
pytest.main()