-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_diagnostic_snps.py
93 lines (81 loc) · 2.5 KB
/
test_diagnostic_snps.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import io
import unittest
from contextlib import redirect_stdout
from contextlib import contextmanager
import diagnostic_snps # type: ignore
@contextmanager
def redirect_stdin(new_stdin):
old_stdin = sys.stdin
sys.stdin = new_stdin
try:
yield
finally:
sys.stdin = old_stdin
def test_script(args, stdin_input=None):
sys.argv = args
f_stdout = io.StringIO()
if stdin_input is not None:
f_stdin = io.StringIO(stdin_input)
stdin_context = redirect_stdin(f_stdin)
else:
stdin_context = redirect_stdin(sys.stdin)
try:
with redirect_stdout(f_stdout), stdin_context:
diagnostic_snps.main()
except SystemExit:
# Catch SystemExit to prevent the test script from exiting
pass
return f_stdout.getvalue()
class TestDiagnosticSNPs(unittest.TestCase):
def test_simple(self):
stdout = test_script([
"diagnostic_snps.py",
"-i",
"test.aln",
"-ref",
"A",
])
expected_output = "pos\tA\tB\tC\tD\t\n5\tA\t-\tN\tN\t\n6\t-\tC\tC\tN\t\n"
self.assertEqual(stdout, expected_output)
def test_strict_neg(self):
stdout = test_script([
"diagnostic_snps.py",
"-i",
"test2.aln",
"-ref",
"A",
"--strict"
])
expected_output = "pos\tA\tB\tC\tD\tA2\tB2\tC2\tD2\t\n"
self.assertEqual(stdout, expected_output)
def test_strict_pos(self):
stdout = test_script([
"diagnostic_snps.py",
"-i",
"test.aln",
"-ref",
"A",
"--strict"
])
expected_output = "pos\tA\tB\tC\tD\t\n5\tA\t-\tN\tN\t\n6\t-\tC\tC\tN\t\n"
self.assertEqual(stdout, expected_output)
def test_ignore(self):
stdout = test_script([
"diagnostic_snps.py",
"-i",
"test.aln",
"-ref",
"A",
"--ignore",
"B"
])
expected_output = "pos\tA\tC\tD\t\n6\t-\tC\tN\t\n"
self.assertEqual(stdout, expected_output)
def test_stdin(self):
stdin_input = ">A\nACGTAA-GT\n>B\nACGT-ACGT\n>C\nACGTNACGT\n>D\nACGTNANGT"
stdout = test_script(["diagnostic_snps.py", "-ref", "A"], stdin_input)
expected_output = "pos\tA\tB\tC\tD\t\n5\tA\t-\tN\tN\t\n6\t-\tC\tC\tN\t\n"
self.assertEqual(stdout, expected_output)
if __name__ == "__main__":
unittest.main()