-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_count_coverage.py
More file actions
executable file
·65 lines (54 loc) · 1.75 KB
/
test_count_coverage.py
File metadata and controls
executable file
·65 lines (54 loc) · 1.75 KB
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
#!/usr/bin/env pypy3
# test_count_coverage.py
# ----------------------
# Unit tests for count_coverage.py
import io
import pytest
from count_coverage import count_coverage
def test_count_coverage_basic(capsys):
"""
Test that count_coverage correctly counts samples with nonzero coverage.
"""
# Simulated input (tab-separated)
input_data = io.StringIO(
"chrM\t1\t0\t88\t65\n"
"chrM\t2\t55\t77\t8\n"
"chrM\t3\t58\t64\t0\n"
)
# Run the function
count_coverage(input_data)
# Capture printed output
captured = capsys.readouterr()
# Expected output: zero-based, half-open intervals
expected_output = (
"chrM\t0\t1\t2\n"
"chrM\t1\t2\t3\n"
"chrM\t2\t3\t2\n"
)
assert captured.out == expected_output
def test_count_coverage_noninteger(capsys):
"""
Test that non-integer coverage values cause the script to exit with an error.
"""
input_data = io.StringIO("chr1\t1\t10\tnan\t5\n")
with pytest.raises(SystemExit):
count_coverage(input_data)
captured = capsys.readouterr()
assert "non-integer value" in captured.err.lower()
def test_count_coverage_too_few_fields(capsys):
"""
Test that lines with fewer than 2 fields cause the script to exit with an error.
"""
input_data = io.StringIO("chr1\n")
with pytest.raises(SystemExit):
count_coverage(input_data)
captured = capsys.readouterr()
assert "fewer than 2 fields" in captured.err.lower()
def test_count_coverage_zero_only(capsys):
"""
Test that positions with zero coverage across all samples are skipped.
"""
input_data = io.StringIO("chr2\t1\t0\t0\t0\n")
count_coverage(input_data)
captured = capsys.readouterr()
assert captured.out == ""