pdb-tools 2.5.0__py3-none-any.whl → 2.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.5.1.dist-info}/METADATA +19 -11
- pdb_tools-2.5.1.dist-info/RECORD +55 -0
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.5.1.dist-info}/WHEEL +1 -1
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.5.1.dist-info}/entry_points.txt +0 -1
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.5.1.dist-info}/top_level.txt +0 -1
- pdbtools/pdb_tidy.py +17 -9
- pdb_tools-2.5.0.dist-info/RECORD +0 -105
- tests/__init__.py +0 -38
- tests/config.py +0 -25
- tests/test_pdb_b.py +0 -161
- tests/test_pdb_chain.py +0 -160
- tests/test_pdb_chainbows.py +0 -140
- tests/test_pdb_chainxseg.py +0 -156
- tests/test_pdb_chkensemble.py +0 -191
- tests/test_pdb_delchain.py +0 -165
- tests/test_pdb_delelem.py +0 -165
- tests/test_pdb_delhetatm.py +0 -115
- tests/test_pdb_delinsertion.py +0 -226
- tests/test_pdb_delres.py +0 -241
- tests/test_pdb_delresname.py +0 -171
- tests/test_pdb_element.py +0 -151
- tests/test_pdb_fixinsert.py +0 -223
- tests/test_pdb_fromcif.py +0 -124
- tests/test_pdb_gap.py +0 -125
- tests/test_pdb_head.py +0 -142
- tests/test_pdb_intersect.py +0 -139
- tests/test_pdb_keepcoord.py +0 -115
- tests/test_pdb_merge.py +0 -106
- tests/test_pdb_mkensemble.py +0 -132
- tests/test_pdb_occ.py +0 -161
- tests/test_pdb_reatom.py +0 -243
- tests/test_pdb_reres.py +0 -281
- tests/test_pdb_rplchain.py +0 -172
- tests/test_pdb_rplresname.py +0 -172
- tests/test_pdb_seg.py +0 -160
- tests/test_pdb_segxchain.py +0 -146
- tests/test_pdb_selaltloc.py +0 -943
- tests/test_pdb_selatom.py +0 -165
- tests/test_pdb_selchain.py +0 -210
- tests/test_pdb_selelem.py +0 -165
- tests/test_pdb_selhetatm.py +0 -116
- tests/test_pdb_selmodel.py +0 -165
- tests/test_pdb_selres.py +0 -257
- tests/test_pdb_selresname.py +0 -171
- tests/test_pdb_selseg.py +0 -165
- tests/test_pdb_shiftres.py +0 -241
- tests/test_pdb_sort.py +0 -254
- tests/test_pdb_splitchain.py +0 -242
- tests/test_pdb_splitmodel.py +0 -235
- tests/test_pdb_splitseg.py +0 -251
- tests/test_pdb_tidy.py +0 -312
- tests/test_pdb_tocif.py +0 -238
- tests/test_pdb_tofasta.py +0 -158
- tests/test_pdb_uniqname.py +0 -156
- tests/test_pdb_validate.py +0 -142
- tests/test_pdb_wc.py +0 -161
- tests/utils.py +0 -56
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.5.1.dist-info/licenses}/LICENSE +0 -0
tests/test_pdb_fixinsert.py
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2018 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_fixinsert`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import os
|
|
23
|
-
import sys
|
|
24
|
-
import unittest
|
|
25
|
-
|
|
26
|
-
from config import data_dir
|
|
27
|
-
from utils import OutputCapture
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TestTool(unittest.TestCase):
|
|
31
|
-
"""
|
|
32
|
-
Generic class for testing tools.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def setUp(self):
|
|
36
|
-
# Dynamically import the module
|
|
37
|
-
name = 'pdbtools.pdb_fixinsert'
|
|
38
|
-
self.module = __import__(name, fromlist=[''])
|
|
39
|
-
|
|
40
|
-
def exec_module(self):
|
|
41
|
-
"""
|
|
42
|
-
Execs module.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
with OutputCapture() as output:
|
|
46
|
-
try:
|
|
47
|
-
self.module.main()
|
|
48
|
-
except SystemExit as e:
|
|
49
|
-
self.retcode = e.code
|
|
50
|
-
|
|
51
|
-
self.stdout = output.stdout
|
|
52
|
-
self.stderr = output.stderr
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
def test_default(self):
|
|
57
|
-
"""$ pdb_fixinsert data/dummy_insertions.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_fixinsert dummy_insertions.pdb
|
|
61
|
-
sys.argv = ['', os.path.join(data_dir, 'dummy_insertions.pdb')]
|
|
62
|
-
|
|
63
|
-
# Execute the script
|
|
64
|
-
self.exec_module()
|
|
65
|
-
|
|
66
|
-
# Validate results
|
|
67
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
68
|
-
self.assertEqual(len(self.stdout), 255) # no lines deleted
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
# Check if we do not have any insertions
|
|
72
|
-
records = (('ATOM', 'HETATM', 'TER'))
|
|
73
|
-
icodes = set(l[26] for l in self.stdout if l.startswith(records))
|
|
74
|
-
self.assertEqual(icodes, set(' '))
|
|
75
|
-
|
|
76
|
-
# Check numbering was corrected
|
|
77
|
-
resid = [int(l[22:26]) for l in self.stdout if l.startswith(records)]
|
|
78
|
-
expected = [
|
|
79
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
80
|
-
4, 4, 4, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
|
|
81
|
-
8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7,
|
|
82
|
-
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
|
|
83
|
-
9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
|
|
84
|
-
2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
85
|
-
3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
|
|
86
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
87
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1,
|
|
88
|
-
-1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
89
|
-
2, 301, 302, 303, 301, 301, 302, 303, 304, 305
|
|
90
|
-
]
|
|
91
|
-
self.assertEqual(resid, expected)
|
|
92
|
-
|
|
93
|
-
def test_select_insertion(self):
|
|
94
|
-
"""$ pdb_fixinsert -A1 data/dummy_insertions.pdb"""
|
|
95
|
-
|
|
96
|
-
sys.argv = ['', '-A1', os.path.join(data_dir, 'dummy_insertions.pdb')]
|
|
97
|
-
|
|
98
|
-
self.exec_module()
|
|
99
|
-
|
|
100
|
-
self.assertEqual(self.retcode, 0)
|
|
101
|
-
self.assertEqual(len(self.stdout), 255)
|
|
102
|
-
self.assertEqual(len(self.stderr), 0)
|
|
103
|
-
|
|
104
|
-
records = (('ATOM', 'HETATM', 'TER'))
|
|
105
|
-
|
|
106
|
-
# Check the insertions were deleted specifically
|
|
107
|
-
for line in self.stdout:
|
|
108
|
-
if line.startswith(records):
|
|
109
|
-
icode = line[26]
|
|
110
|
-
resid = int(line[22:26])
|
|
111
|
-
if line[17:26] == 'ARG B 4':
|
|
112
|
-
self.assertIn(icode, ('A', 'B'))
|
|
113
|
-
self.assertEqual(resid, 4)
|
|
114
|
-
elif line[17:26] == 'GLY B 4':
|
|
115
|
-
self.assertEqual(icode, ' ')
|
|
116
|
-
self.assertEqual(resid, 4)
|
|
117
|
-
elif line[17:26] == 'ASN A 1':
|
|
118
|
-
self.assertEqual(icode, ' ')
|
|
119
|
-
self.assertEqual(resid, 1)
|
|
120
|
-
elif line[17:26] == 'GLY A 1':
|
|
121
|
-
self.assertEqual(icode, ' ')
|
|
122
|
-
self.assertEqual(resid, 2) # should have renumbered
|
|
123
|
-
|
|
124
|
-
# Check numbering was corrected overall
|
|
125
|
-
resid = [int(l[22:26]) for l in self.stdout if l.startswith(records)]
|
|
126
|
-
expected = [
|
|
127
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
128
|
-
4, 4, 4, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
|
|
129
|
-
8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7,
|
|
130
|
-
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
|
|
131
|
-
9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
|
|
132
|
-
2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
133
|
-
3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
|
|
134
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
135
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1,
|
|
136
|
-
-1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
137
|
-
2, 301, 302, 303, 301, 301, 302, 303, 304, 305
|
|
138
|
-
]
|
|
139
|
-
|
|
140
|
-
self.assertEqual(resid, expected)
|
|
141
|
-
|
|
142
|
-
def test_file_not_found(self):
|
|
143
|
-
"""$ pdb_fixinsert not_existing.pdb"""
|
|
144
|
-
|
|
145
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
146
|
-
sys.argv = ['', afile]
|
|
147
|
-
|
|
148
|
-
self.exec_module()
|
|
149
|
-
|
|
150
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
151
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
152
|
-
self.assertEqual(self.stderr[0][:22],
|
|
153
|
-
"ERROR!! File not found") # proper error message
|
|
154
|
-
|
|
155
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
156
|
-
def test_file_missing(self):
|
|
157
|
-
"""$ pdb_fixinsert -A89"""
|
|
158
|
-
|
|
159
|
-
sys.argv = ['', '-A89']
|
|
160
|
-
|
|
161
|
-
self.exec_module()
|
|
162
|
-
|
|
163
|
-
self.assertEqual(self.retcode, 1)
|
|
164
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
165
|
-
self.assertEqual(self.stderr[0],
|
|
166
|
-
"ERROR!! No data to process!")
|
|
167
|
-
|
|
168
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
169
|
-
def test_helptext(self):
|
|
170
|
-
"""$ pdb_fixinsert"""
|
|
171
|
-
|
|
172
|
-
sys.argv = ['']
|
|
173
|
-
|
|
174
|
-
self.exec_module()
|
|
175
|
-
|
|
176
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
177
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
178
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
179
|
-
|
|
180
|
-
def test_invalid_option(self):
|
|
181
|
-
"""$ pdb_fixinsert -A data/dummy_insertions.pdb"""
|
|
182
|
-
|
|
183
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy_insertions.pdb')]
|
|
184
|
-
|
|
185
|
-
self.exec_module()
|
|
186
|
-
|
|
187
|
-
self.assertEqual(self.retcode, 1)
|
|
188
|
-
self.assertEqual(len(self.stdout), 0)
|
|
189
|
-
self.assertEqual(self.stderr[0][:27],
|
|
190
|
-
"ERROR!! Option invalid: 'A'")
|
|
191
|
-
|
|
192
|
-
def test_invalid_option_2(self):
|
|
193
|
-
"""$ pdb_fixinsert -12A data/dummy_insertions.pdb"""
|
|
194
|
-
|
|
195
|
-
sys.argv = ['', '-12A', os.path.join(data_dir, 'dummy_insertions.pdb')]
|
|
196
|
-
|
|
197
|
-
self.exec_module()
|
|
198
|
-
|
|
199
|
-
self.assertEqual(self.retcode, 1)
|
|
200
|
-
self.assertEqual(len(self.stdout), 0)
|
|
201
|
-
self.assertEqual(self.stderr[0][:39],
|
|
202
|
-
"ERROR!! Option invalid: '12A'")
|
|
203
|
-
|
|
204
|
-
def test_not_an_option(self):
|
|
205
|
-
"""$ pdb_fixinsert 20 data/dummy_insertions.pdb"""
|
|
206
|
-
|
|
207
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy_insertions.pdb')]
|
|
208
|
-
|
|
209
|
-
self.exec_module()
|
|
210
|
-
|
|
211
|
-
self.assertEqual(self.retcode, 1)
|
|
212
|
-
self.assertEqual(len(self.stdout), 0)
|
|
213
|
-
self.assertEqual(self.stderr[0],
|
|
214
|
-
"ERROR! First argument is not an option: '20'")
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if __name__ == '__main__':
|
|
218
|
-
from config import test_dir
|
|
219
|
-
|
|
220
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
221
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
222
|
-
|
|
223
|
-
unittest.main()
|
tests/test_pdb_fromcif.py
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2018 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_fromcif`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import os
|
|
23
|
-
import sys
|
|
24
|
-
import unittest
|
|
25
|
-
|
|
26
|
-
from config import data_dir
|
|
27
|
-
from utils import OutputCapture
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TestTool(unittest.TestCase):
|
|
31
|
-
"""
|
|
32
|
-
Generic class for testing tools.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def setUp(self):
|
|
36
|
-
# Dynamically import the module
|
|
37
|
-
name = 'pdbtools.pdb_fromcif'
|
|
38
|
-
self.module = __import__(name, fromlist=[''])
|
|
39
|
-
|
|
40
|
-
def exec_module(self):
|
|
41
|
-
"""
|
|
42
|
-
Execs module.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
with OutputCapture() as output:
|
|
46
|
-
try:
|
|
47
|
-
self.module.main()
|
|
48
|
-
except SystemExit as e:
|
|
49
|
-
self.retcode = e.code
|
|
50
|
-
|
|
51
|
-
self.stdout = output.stdout
|
|
52
|
-
self.stderr = output.stderr
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
def test_conversion(self):
|
|
57
|
-
"""$ pdb_fromcif data/ensemble_OK.pdb"""
|
|
58
|
-
|
|
59
|
-
fpath = os.path.join(data_dir, 'ensemble_OK.cif')
|
|
60
|
-
sys.argv = ['', fpath]
|
|
61
|
-
|
|
62
|
-
# Execute the script
|
|
63
|
-
self.exec_module()
|
|
64
|
-
|
|
65
|
-
# Validate results
|
|
66
|
-
self.assertEqual(self.retcode, 0)
|
|
67
|
-
self.assertEqual(len(self.stdout), 9)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0)
|
|
69
|
-
|
|
70
|
-
# Check order of records
|
|
71
|
-
expected = ['MODEL ', 'ATOM ', 'ATOM ', 'ENDMDL',
|
|
72
|
-
'MODEL ', 'ATOM ', 'ATOM ', 'ENDMDL', 'END ']
|
|
73
|
-
records = [l[:6] for l in self.stdout]
|
|
74
|
-
self.assertEqual(records, expected)
|
|
75
|
-
|
|
76
|
-
def test_file_not_found(self):
|
|
77
|
-
"""$ pdb_fromcif not_existing.pdb"""
|
|
78
|
-
|
|
79
|
-
# Error (file not found)
|
|
80
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
81
|
-
sys.argv = ['', afile]
|
|
82
|
-
|
|
83
|
-
# Execute the script
|
|
84
|
-
self.exec_module()
|
|
85
|
-
|
|
86
|
-
self.assertEqual(self.retcode, 1)
|
|
87
|
-
self.assertEqual(len(self.stdout), 0)
|
|
88
|
-
self.assertEqual(self.stderr[0][:22],
|
|
89
|
-
"ERROR!! File not found")
|
|
90
|
-
|
|
91
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
92
|
-
def test_helptext(self):
|
|
93
|
-
"""$ pdb_fromcif"""
|
|
94
|
-
|
|
95
|
-
sys.argv = ['']
|
|
96
|
-
|
|
97
|
-
# Execute the script
|
|
98
|
-
self.exec_module()
|
|
99
|
-
|
|
100
|
-
self.assertEqual(self.retcode, 1)
|
|
101
|
-
self.assertEqual(len(self.stdout), 0)
|
|
102
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
103
|
-
|
|
104
|
-
def test_invalid_option(self):
|
|
105
|
-
"""$ pdb_fromcif -A data/dummy.pdb"""
|
|
106
|
-
|
|
107
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
108
|
-
|
|
109
|
-
# Execute the script
|
|
110
|
-
self.exec_module()
|
|
111
|
-
|
|
112
|
-
self.assertEqual(self.retcode, 1)
|
|
113
|
-
self.assertEqual(len(self.stdout), 0)
|
|
114
|
-
self.assertEqual(self.stderr[0][:36],
|
|
115
|
-
"ERROR!! Script takes 1 argument, not")
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if __name__ == '__main__':
|
|
119
|
-
from config import test_dir
|
|
120
|
-
|
|
121
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
122
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
123
|
-
|
|
124
|
-
unittest.main()
|
tests/test_pdb_gap.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2018 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_gap`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import os
|
|
23
|
-
import sys
|
|
24
|
-
import unittest
|
|
25
|
-
|
|
26
|
-
from config import data_dir
|
|
27
|
-
from utils import OutputCapture
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TestTool(unittest.TestCase):
|
|
31
|
-
"""
|
|
32
|
-
Generic class for testing tools.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def setUp(self):
|
|
36
|
-
# Dynamically import the module
|
|
37
|
-
name = 'pdbtools.pdb_gap'
|
|
38
|
-
self.module = __import__(name, fromlist=[''])
|
|
39
|
-
|
|
40
|
-
def exec_module(self):
|
|
41
|
-
"""
|
|
42
|
-
Execs module.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
with OutputCapture() as output:
|
|
46
|
-
try:
|
|
47
|
-
self.module.main()
|
|
48
|
-
except SystemExit as e:
|
|
49
|
-
self.retcode = e.code
|
|
50
|
-
|
|
51
|
-
self.stdout = output.stdout
|
|
52
|
-
self.stderr = output.stderr
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
def test_default(self):
|
|
57
|
-
"""$ pdb_gap data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
sys.argv = ['', os.path.join(data_dir, 'dummy.pdb')]
|
|
61
|
-
|
|
62
|
-
# Execute the script
|
|
63
|
-
self.exec_module()
|
|
64
|
-
|
|
65
|
-
# Validate results
|
|
66
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
67
|
-
self.assertEqual(len(self.stdout), 5) # no lines deleted
|
|
68
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
69
|
-
|
|
70
|
-
self.assertEqual(self.stdout,
|
|
71
|
-
["B:ARG4 < Seq. Gap > B:GLU6",
|
|
72
|
-
"A:ASN1 < 9.42A > A:ASN1",
|
|
73
|
-
"C:ARG5 < Seq. Gap > C:GLU2",
|
|
74
|
-
"C:GLU2 < 95.75A > C:MET-1",
|
|
75
|
-
"Found 4 gap(s) in the structure"])
|
|
76
|
-
|
|
77
|
-
def test_file_not_found(self):
|
|
78
|
-
"""$ pdb_gap not_existing.pdb"""
|
|
79
|
-
|
|
80
|
-
# Error (file not found)
|
|
81
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
82
|
-
sys.argv = ['', afile]
|
|
83
|
-
|
|
84
|
-
# Execute the script
|
|
85
|
-
self.exec_module()
|
|
86
|
-
|
|
87
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
88
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
89
|
-
self.assertEqual(self.stderr[0][:22],
|
|
90
|
-
"ERROR!! File not found") # proper error message
|
|
91
|
-
|
|
92
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
93
|
-
def test_helptext(self):
|
|
94
|
-
"""$ pdb_gap"""
|
|
95
|
-
|
|
96
|
-
sys.argv = ['']
|
|
97
|
-
|
|
98
|
-
# Execute the script
|
|
99
|
-
self.exec_module()
|
|
100
|
-
|
|
101
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
102
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
103
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
104
|
-
|
|
105
|
-
def test_invalid_option(self):
|
|
106
|
-
"""$ pdb_gap -A data/dummy.pdb"""
|
|
107
|
-
|
|
108
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
109
|
-
|
|
110
|
-
# Execute the script
|
|
111
|
-
self.exec_module()
|
|
112
|
-
|
|
113
|
-
self.assertEqual(self.retcode, 1)
|
|
114
|
-
self.assertEqual(len(self.stdout), 0)
|
|
115
|
-
self.assertEqual(self.stderr[0][:36],
|
|
116
|
-
"ERROR!! Script takes 1 argument, not")
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if __name__ == '__main__':
|
|
120
|
-
from config import test_dir
|
|
121
|
-
|
|
122
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
123
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
124
|
-
|
|
125
|
-
unittest.main()
|
tests/test_pdb_head.py
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2018 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_head`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import os
|
|
23
|
-
import sys
|
|
24
|
-
import unittest
|
|
25
|
-
|
|
26
|
-
from config import data_dir
|
|
27
|
-
from utils import OutputCapture
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TestTool(unittest.TestCase):
|
|
31
|
-
"""
|
|
32
|
-
Generic class for testing tools.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def setUp(self):
|
|
36
|
-
# Dynamically import the module
|
|
37
|
-
name = 'pdbtools.pdb_head'
|
|
38
|
-
self.module = __import__(name, fromlist=[''])
|
|
39
|
-
|
|
40
|
-
def exec_module(self):
|
|
41
|
-
"""
|
|
42
|
-
Execs module.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
with OutputCapture() as output:
|
|
46
|
-
try:
|
|
47
|
-
self.module.main()
|
|
48
|
-
except SystemExit as e:
|
|
49
|
-
self.retcode = e.code
|
|
50
|
-
|
|
51
|
-
self.stdout = output.stdout
|
|
52
|
-
self.stderr = output.stderr
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
def test_valid_option(self):
|
|
57
|
-
"""$ pdb_head -10 data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
sys.argv = ['', '-10', os.path.join(data_dir, 'dummy.pdb')]
|
|
61
|
-
|
|
62
|
-
# Execute the script
|
|
63
|
-
self.exec_module()
|
|
64
|
-
|
|
65
|
-
# Validate results
|
|
66
|
-
self.assertEqual(self.retcode, 0)
|
|
67
|
-
self.assertEqual(len(self.stdout), 10)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0)
|
|
69
|
-
|
|
70
|
-
def test_invalid_option(self):
|
|
71
|
-
"""$ pdb_head --10 data/dummy.pdb"""
|
|
72
|
-
|
|
73
|
-
# Simulate input
|
|
74
|
-
sys.argv = ['', '--10', os.path.join(data_dir, 'dummy.pdb')]
|
|
75
|
-
|
|
76
|
-
# Execute the script
|
|
77
|
-
self.exec_module()
|
|
78
|
-
|
|
79
|
-
# Validate results
|
|
80
|
-
self.assertEqual(self.retcode, 1)
|
|
81
|
-
self.assertEqual(len(self.stdout), 0)
|
|
82
|
-
self.assertEqual(self.stderr[0][:22],
|
|
83
|
-
"ERROR!! Option must be")
|
|
84
|
-
|
|
85
|
-
def test_file_not_found(self):
|
|
86
|
-
"""$ pdb_head not_existing.pdb"""
|
|
87
|
-
|
|
88
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
89
|
-
sys.argv = ['', afile]
|
|
90
|
-
|
|
91
|
-
self.exec_module()
|
|
92
|
-
|
|
93
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
94
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
95
|
-
self.assertEqual(self.stderr[0][:22],
|
|
96
|
-
"ERROR!! File not found") # proper error message
|
|
97
|
-
|
|
98
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
99
|
-
def test_file_missing(self):
|
|
100
|
-
"""$ pdb_head -10"""
|
|
101
|
-
|
|
102
|
-
sys.argv = ['', '-10']
|
|
103
|
-
|
|
104
|
-
self.exec_module()
|
|
105
|
-
|
|
106
|
-
self.assertEqual(self.retcode, 1)
|
|
107
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
108
|
-
self.assertEqual(self.stderr[0],
|
|
109
|
-
"ERROR!! No data to process!")
|
|
110
|
-
|
|
111
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
112
|
-
def test_helptext(self):
|
|
113
|
-
"""$ pdb_head"""
|
|
114
|
-
|
|
115
|
-
sys.argv = ['']
|
|
116
|
-
|
|
117
|
-
self.exec_module()
|
|
118
|
-
|
|
119
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
120
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
121
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
122
|
-
|
|
123
|
-
def test_not_an_option(self):
|
|
124
|
-
"""$ pdb_head 20 data/dummy.pdb"""
|
|
125
|
-
|
|
126
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
|
|
127
|
-
|
|
128
|
-
self.exec_module()
|
|
129
|
-
|
|
130
|
-
self.assertEqual(self.retcode, 1)
|
|
131
|
-
self.assertEqual(len(self.stdout), 0)
|
|
132
|
-
self.assertEqual(self.stderr[0],
|
|
133
|
-
"ERROR! First argument is not an option: '20'")
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if __name__ == '__main__':
|
|
137
|
-
from config import test_dir
|
|
138
|
-
|
|
139
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
140
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
141
|
-
|
|
142
|
-
unittest.main()
|