forked from kyclark/tiny_python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·109 lines (71 loc) · 2.1 KB
/
Copy pathtest.py
File metadata and controls
executable file
·109 lines (71 loc) · 2.1 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""tests for dna.py"""
import os
import random
import re
import string
from subprocess import getstatusoutput, getoutput
prg = './dna.py'
# --------------------------------------------------
def test_exists():
"""exists"""
assert os.path.isfile(prg)
# --------------------------------------------------
def test_no_arg_and_usage():
"""usage"""
for flag in ['', '-h', '--help']:
out = getoutput(f'{prg} {flag}')
assert out.lower().startswith('usage')
# --------------------------------------------------
def run_single(base):
"""Run a single base test"""
num = random.randint(1, 10)
given = base * num
rv, out = getstatusoutput(f'{prg} {given}')
assert rv == 0
cmp = base.upper()
expected = f'{num} 0 0 0' if cmp == 'A' else \
f'0 {num} 0 0' if cmp == 'C' else \
f'0 0 {num} 0' if cmp == 'G' else \
f'0 0 0 {num}'
assert out == expected
# --------------------------------------------------
def test_a_upper():
"""A"""
run_single('A')
# --------------------------------------------------
def test_a_lower():
"""a"""
run_single('a')
# --------------------------------------------------
def test_c_upper():
"""C"""
run_single('C')
# --------------------------------------------------
def test_c_lower():
"""c"""
run_single('c')
# --------------------------------------------------
def test_g_upper():
"""G"""
run_single('G')
# --------------------------------------------------
def test_g_lower():
"""g"""
run_single('g')
# --------------------------------------------------
def test_t_upper():
"""T"""
run_single('T')
# --------------------------------------------------
def test_t_lower():
"""t"""
run_single('t')
# --------------------------------------------------
def test_rosalind_example():
"""From http://rosalind.info/problems/dna/"""
dna = ('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATT'
'AAAAAAAGAGTGTCTGATAGCAGC')
rv, out = getstatusoutput(f'{prg} {dna}')
assert rv == 0
assert out == '20 12 17 21'