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
·130 lines (99 loc) · 5.37 KB
/
Copy pathtest.py
File metadata and controls
executable file
·130 lines (99 loc) · 5.37 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""tests for transcribe.py"""
from subprocess import getstatusoutput
import os.path
import re
import string
import random
from shutil import rmtree
prg = './transcribe.py'
input1 = './inputs/input1.txt'
input2 = './inputs/input2.txt'
# --------------------------------------------------
def random_filename():
"""generate a random filename"""
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=5))
# --------------------------------------------------
def test_exists():
"""usage"""
assert os.path.isfile(prg)
# --------------------------------------------------
def test_usage():
"""usage"""
for flag in ['-h', '--help']:
rv, out = getstatusoutput('{} {}'.format(prg, flag))
assert rv == 0
assert re.match("usage", out, re.IGNORECASE)
# --------------------------------------------------
def test_no_args():
"""die on no args"""
rv, out = getstatusoutput(prg)
assert rv != 0
assert re.match("usage", out, re.IGNORECASE)
# --------------------------------------------------
def test_bad_file():
"""die on missing input"""
bad = random_filename()
rv, out = getstatusoutput(f'{prg} {bad}')
assert rv != 0
assert re.match('usage:', out, re.I)
assert re.search(f"No such file or directory: '{bad}'", out)
# --------------------------------------------------
def test_good_input1():
"""runs on good input"""
out_dir = 'out'
try:
if os.path.isdir(out_dir):
rmtree(out_dir)
rv, out = getstatusoutput(f'{prg} {input1}')
assert rv == 0
assert out == 'Done, wrote 1 sequence in 1 file to directory "out".'
assert os.path.isdir(out_dir)
out_file = os.path.join(out_dir, 'input1.txt')
assert os.path.isfile(out_file)
assert open(out_file).read().rstrip() == 'GAUGGAACUUGACUACGUAAAUU'
finally:
if os.path.isdir(out_dir):
rmtree(out_dir)
# --------------------------------------------------
def test_good_input2():
"""runs on good input"""
out_dir = random_filename()
try:
if os.path.isdir(out_dir):
rmtree(out_dir)
rv, out = getstatusoutput(f'{prg} -o {out_dir} {input2}')
assert rv == 0
assert out == f'Done, wrote 2 sequences in 1 file to directory "{out_dir}".'
assert os.path.isdir(out_dir)
out_file = os.path.join(out_dir, 'input2.txt')
assert os.path.isfile(out_file)
assert open(out_file).read().rstrip() == output2().rstrip()
finally:
if os.path.isdir(out_dir):
rmtree(out_dir)
# --------------------------------------------------
def test_good_multiple_inputs():
"""runs on good input"""
out_dir = random_filename()
try:
if os.path.isdir(out_dir):
rmtree(out_dir)
rv, out = getstatusoutput(f'{prg} --outdir {out_dir} {input1} {input2}')
assert rv == 0
assert out == f'Done, wrote 3 sequences in 2 files to directory "{out_dir}".'
assert os.path.isdir(out_dir)
out_file1 = os.path.join(out_dir, 'input1.txt')
out_file2 = os.path.join(out_dir, 'input2.txt')
assert os.path.isfile(out_file1)
assert os.path.isfile(out_file2)
assert open(out_file1).read().rstrip() == 'GAUGGAACUUGACUACGUAAAUU'
assert open(out_file2).read().rstrip() == output2().rstrip()
finally:
if os.path.isdir(out_dir):
rmtree(out_dir)
# --------------------------------------------------
def output2():
return """CUUAGGUCAGUGGUCUCUAAACUUUCGGUUCUGUCGUCUUCAUAGGCAAAUUUUUGAACCGGCAGACAAGCUAAUCCCUGUGCGGUUAGCUCAAGCAACAGAAUGUCCGAUCUUUGAACUUCCUAACGAACCGAACCUACUAUAAUUACAUACGAAUAAUGUAUGGGCUAGCGUUGGCUCAUCAUCAAGUCUGCGGUGAAAUGGGAACAUAUUCGCAUUGCAUAUAGGGCGUAUCUGACGAUCGAUUCGAGUUGGCUAGUCGUACCAAAUGAUUAUGGGCUGG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