pdb-tools 2.4.12__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.4.12.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.4.12.dist-info → pdb_tools-2.5.1.dist-info}/WHEEL +1 -1
- {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/entry_points.txt +1 -1
- {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/top_level.txt +0 -1
- pdbtools/pdb_selmodel.py +194 -0
- pdbtools/pdb_tidy.py +17 -9
- pdb_tools-2.4.12.dist-info/RECORD +0 -103
- 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_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.4.12.dist-info → pdb_tools-2.5.1.dist-info/licenses}/LICENSE +0 -0
tests/test_pdb_selres.py
DELETED
|
@@ -1,257 +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_selres`.
|
|
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_selres'
|
|
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_range_1(self):
|
|
57
|
-
"""$ pdb_selres -1:5 data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
sys.argv = ['', '-1:5', 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), 160)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0)
|
|
69
|
-
|
|
70
|
-
def test_range_2(self):
|
|
71
|
-
"""$ pdb_selres -1: data/dummy.pdb"""
|
|
72
|
-
|
|
73
|
-
# Simulate input
|
|
74
|
-
sys.argv = ['', '-1:', 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, 0)
|
|
81
|
-
self.assertEqual(len(self.stdout), 195)
|
|
82
|
-
self.assertEqual(len(self.stderr), 0)
|
|
83
|
-
|
|
84
|
-
def test_range_3(self):
|
|
85
|
-
"""$ pdb_selres -:-1 data/dummy.pdb"""
|
|
86
|
-
|
|
87
|
-
# Simulate input
|
|
88
|
-
sys.argv = ['', '-:-1', os.path.join(data_dir, 'dummy.pdb')]
|
|
89
|
-
|
|
90
|
-
# Execute the script
|
|
91
|
-
self.exec_module()
|
|
92
|
-
|
|
93
|
-
# Validate results
|
|
94
|
-
self.assertEqual(self.retcode, 0)
|
|
95
|
-
self.assertEqual(len(self.stdout), 25)
|
|
96
|
-
self.assertEqual(len(self.stderr), 0)
|
|
97
|
-
|
|
98
|
-
def test_range_4(self):
|
|
99
|
-
"""$ pdb_selres -::5 data/dummy.pdb"""
|
|
100
|
-
|
|
101
|
-
# Simulate input
|
|
102
|
-
sys.argv = ['', '-::5', os.path.join(data_dir, 'dummy.pdb')]
|
|
103
|
-
|
|
104
|
-
# Execute the script
|
|
105
|
-
self.exec_module()
|
|
106
|
-
|
|
107
|
-
# Validate results
|
|
108
|
-
self.assertEqual(self.retcode, 0)
|
|
109
|
-
self.assertEqual(len(self.stdout), 63)
|
|
110
|
-
self.assertEqual(len(self.stderr), 0)
|
|
111
|
-
|
|
112
|
-
def test_range_5(self):
|
|
113
|
-
"""$ pdb_selres -6:6 data/dummy.pdb"""
|
|
114
|
-
|
|
115
|
-
# Simulate input
|
|
116
|
-
sys.argv = ['', '-6:6', os.path.join(data_dir, 'dummy.pdb')]
|
|
117
|
-
|
|
118
|
-
# Execute the script
|
|
119
|
-
self.exec_module()
|
|
120
|
-
|
|
121
|
-
# Validate results
|
|
122
|
-
self.assertEqual(self.retcode, 0)
|
|
123
|
-
self.assertEqual(len(self.stdout), 31)
|
|
124
|
-
self.assertEqual(len(self.stderr), 0)
|
|
125
|
-
|
|
126
|
-
def test_invalid_range_1(self):
|
|
127
|
-
"""$ pdb_selres --9998:: data/dummy.pdb"""
|
|
128
|
-
|
|
129
|
-
# Simulate input
|
|
130
|
-
sys.argv = ['', '--9998::', os.path.join(data_dir, 'dummy.pdb')]
|
|
131
|
-
|
|
132
|
-
# Execute the script
|
|
133
|
-
self.exec_module()
|
|
134
|
-
|
|
135
|
-
# Validate results
|
|
136
|
-
self.assertEqual(self.retcode, 1)
|
|
137
|
-
self.assertEqual(len(self.stdout), 0)
|
|
138
|
-
self.assertEqual(self.stderr[0][:22],
|
|
139
|
-
"ERROR!! Residue number")
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def test_invalid_range_2(self):
|
|
143
|
-
"""$ pdb_selres -:10000: data/dummy.pdb"""
|
|
144
|
-
|
|
145
|
-
# Simulate input
|
|
146
|
-
sys.argv = ['', '-:10000:', os.path.join(data_dir, 'dummy.pdb')]
|
|
147
|
-
|
|
148
|
-
# Execute the script
|
|
149
|
-
self.exec_module()
|
|
150
|
-
|
|
151
|
-
# Validate results
|
|
152
|
-
self.assertEqual(self.retcode, 1)
|
|
153
|
-
self.assertEqual(len(self.stdout), 0)
|
|
154
|
-
self.assertEqual(self.stderr[0][:22],
|
|
155
|
-
"ERROR!! Residue number")
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def test_invalid_range_3(self):
|
|
159
|
-
"""$ pdb_selres -::: data/dummy.pdb"""
|
|
160
|
-
|
|
161
|
-
# Simulate input
|
|
162
|
-
sys.argv = ['', '-:::', os.path.join(data_dir, 'dummy.pdb')]
|
|
163
|
-
|
|
164
|
-
# Execute the script
|
|
165
|
-
self.exec_module()
|
|
166
|
-
|
|
167
|
-
# Validate results
|
|
168
|
-
self.assertEqual(self.retcode, 1)
|
|
169
|
-
self.assertEqual(len(self.stdout), 0)
|
|
170
|
-
self.assertEqual(self.stderr[0][:21],
|
|
171
|
-
"ERROR!! Residue range")
|
|
172
|
-
|
|
173
|
-
def test_invalid_range_4(self):
|
|
174
|
-
"""$ pdb_selres -5:1:: data/dummy.pdb"""
|
|
175
|
-
|
|
176
|
-
# Simulate input
|
|
177
|
-
sys.argv = ['', '-5:1::', os.path.join(data_dir, 'dummy.pdb')]
|
|
178
|
-
|
|
179
|
-
# Execute the script
|
|
180
|
-
self.exec_module()
|
|
181
|
-
|
|
182
|
-
# Validate results
|
|
183
|
-
self.assertEqual(self.retcode, 1)
|
|
184
|
-
self.assertEqual(len(self.stdout), 0)
|
|
185
|
-
self.assertEqual(self.stderr[0][:21],
|
|
186
|
-
"ERROR!! Residue range")
|
|
187
|
-
|
|
188
|
-
def test_file_not_found(self):
|
|
189
|
-
"""$ pdb_selres not_existing.pdb"""
|
|
190
|
-
|
|
191
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
192
|
-
sys.argv = ['', afile]
|
|
193
|
-
|
|
194
|
-
self.exec_module()
|
|
195
|
-
|
|
196
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
197
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
198
|
-
self.assertEqual(self.stderr[0][:22],
|
|
199
|
-
"ERROR!! File not found") # proper error message
|
|
200
|
-
|
|
201
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
202
|
-
def test_file_missing(self):
|
|
203
|
-
"""$ pdb_selres -1:10"""
|
|
204
|
-
|
|
205
|
-
sys.argv = ['', '-1:10']
|
|
206
|
-
|
|
207
|
-
self.exec_module()
|
|
208
|
-
|
|
209
|
-
self.assertEqual(self.retcode, 1)
|
|
210
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
211
|
-
self.assertEqual(self.stderr[0],
|
|
212
|
-
"ERROR!! No data to process!")
|
|
213
|
-
|
|
214
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
215
|
-
def test_helptext(self):
|
|
216
|
-
"""$ pdb_selres"""
|
|
217
|
-
|
|
218
|
-
sys.argv = ['']
|
|
219
|
-
|
|
220
|
-
self.exec_module()
|
|
221
|
-
|
|
222
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
223
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
224
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
225
|
-
|
|
226
|
-
def test_invalid_option(self):
|
|
227
|
-
"""$ pdb_selres -A:B data/dummy.pdb"""
|
|
228
|
-
|
|
229
|
-
sys.argv = ['', '-A:B', os.path.join(data_dir, 'dummy.pdb')]
|
|
230
|
-
|
|
231
|
-
self.exec_module()
|
|
232
|
-
|
|
233
|
-
self.assertEqual(self.retcode, 1)
|
|
234
|
-
self.assertEqual(len(self.stdout), 0)
|
|
235
|
-
self.assertEqual(self.stderr[0][:31],
|
|
236
|
-
"ERROR!! Not a valid number: 'A'")
|
|
237
|
-
|
|
238
|
-
def test_not_an_option(self):
|
|
239
|
-
"""$ pdb_selres 20 data/dummy.pdb"""
|
|
240
|
-
|
|
241
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
|
|
242
|
-
|
|
243
|
-
self.exec_module()
|
|
244
|
-
|
|
245
|
-
self.assertEqual(self.retcode, 1)
|
|
246
|
-
self.assertEqual(len(self.stdout), 0)
|
|
247
|
-
self.assertEqual(self.stderr[0],
|
|
248
|
-
"ERROR! First argument is not an option: '20'")
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if __name__ == '__main__':
|
|
252
|
-
from config import test_dir
|
|
253
|
-
|
|
254
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
255
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
256
|
-
|
|
257
|
-
unittest.main()
|
tests/test_pdb_selresname.py
DELETED
|
@@ -1,171 +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_selresname`.
|
|
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_selresname'
|
|
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_single_sele(self):
|
|
57
|
-
"""$ pdb_selresname -ARG data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
sys.argv = ['', '-ARG', 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), 92)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0)
|
|
69
|
-
|
|
70
|
-
def test_multiple_sele(self):
|
|
71
|
-
"""$ pdb_selresname -ARG,CA data/dummy.pdb"""
|
|
72
|
-
|
|
73
|
-
# Simulate input
|
|
74
|
-
sys.argv = ['', '-ARG,CA', 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, 0)
|
|
81
|
-
self.assertEqual(len(self.stdout), 93)
|
|
82
|
-
self.assertEqual(len(self.stderr), 0)
|
|
83
|
-
|
|
84
|
-
def test_empty_sele(self):
|
|
85
|
-
"""$ pdb_selresname - data/dummy.pdb"""
|
|
86
|
-
|
|
87
|
-
# Simulate input
|
|
88
|
-
sys.argv = ['', '-', os.path.join(data_dir, 'dummy.pdb')]
|
|
89
|
-
|
|
90
|
-
# Execute the script
|
|
91
|
-
self.exec_module()
|
|
92
|
-
|
|
93
|
-
# Validate results
|
|
94
|
-
self.assertEqual(self.retcode, 1)
|
|
95
|
-
self.assertEqual(len(self.stdout), 0)
|
|
96
|
-
self.assertEqual(self.stderr[0][:22],
|
|
97
|
-
"ERROR!! Residue name s")
|
|
98
|
-
|
|
99
|
-
def test_invalid_sele(self):
|
|
100
|
-
"""$ pdb_selresname -ABCD data/dummy.pdb"""
|
|
101
|
-
|
|
102
|
-
# Simulate input
|
|
103
|
-
sys.argv = ['', '-ABCD', os.path.join(data_dir, 'dummy.pdb')]
|
|
104
|
-
|
|
105
|
-
# Execute the script
|
|
106
|
-
self.exec_module()
|
|
107
|
-
|
|
108
|
-
# Validate results
|
|
109
|
-
self.assertEqual(self.retcode, 1)
|
|
110
|
-
self.assertEqual(len(self.stdout), 0)
|
|
111
|
-
self.assertEqual(self.stderr[0][:22],
|
|
112
|
-
"ERROR!! Residue name i")
|
|
113
|
-
|
|
114
|
-
def test_file_not_found(self):
|
|
115
|
-
"""$ pdb_selresname not_existing.pdb"""
|
|
116
|
-
|
|
117
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
118
|
-
sys.argv = ['', afile]
|
|
119
|
-
|
|
120
|
-
self.exec_module()
|
|
121
|
-
|
|
122
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
123
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
124
|
-
self.assertEqual(self.stderr[0][:22],
|
|
125
|
-
"ERROR!! File not found") # proper error message
|
|
126
|
-
|
|
127
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
128
|
-
def test_file_missing(self):
|
|
129
|
-
"""$ pdb_selresname -ARG"""
|
|
130
|
-
|
|
131
|
-
sys.argv = ['', '-ARG']
|
|
132
|
-
|
|
133
|
-
self.exec_module()
|
|
134
|
-
|
|
135
|
-
self.assertEqual(self.retcode, 1)
|
|
136
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
137
|
-
self.assertEqual(self.stderr[0],
|
|
138
|
-
"ERROR!! No data to process!")
|
|
139
|
-
|
|
140
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
141
|
-
def test_helptext(self):
|
|
142
|
-
"""$ pdb_selresname"""
|
|
143
|
-
|
|
144
|
-
sys.argv = ['']
|
|
145
|
-
|
|
146
|
-
self.exec_module()
|
|
147
|
-
|
|
148
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
149
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
150
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
151
|
-
|
|
152
|
-
def test_not_an_option(self):
|
|
153
|
-
"""$ pdb_selresname 20 data/dummy.pdb"""
|
|
154
|
-
|
|
155
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
|
|
156
|
-
|
|
157
|
-
self.exec_module()
|
|
158
|
-
|
|
159
|
-
self.assertEqual(self.retcode, 1)
|
|
160
|
-
self.assertEqual(len(self.stdout), 0)
|
|
161
|
-
self.assertEqual(self.stderr[0],
|
|
162
|
-
"ERROR! First argument is not an option: '20'")
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if __name__ == '__main__':
|
|
166
|
-
from config import test_dir
|
|
167
|
-
|
|
168
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
169
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
170
|
-
|
|
171
|
-
unittest.main()
|
tests/test_pdb_selseg.py
DELETED
|
@@ -1,165 +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_selseg`.
|
|
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_selseg'
|
|
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_one_option(self):
|
|
57
|
-
"""$ pdb_selseg -Z data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_selseg dummy.pdb
|
|
61
|
-
sys.argv = ['', '-Z', os.path.join(data_dir, 'dummy.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), 39) # selected Z
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
def test_multiple(self):
|
|
72
|
-
"""
|
|
73
|
-
$ pdb_selseg -A,B data/dummy.pdb
|
|
74
|
-
"""
|
|
75
|
-
|
|
76
|
-
sys.argv = ['', '-A,B', os.path.join(data_dir, 'dummy.pdb')]
|
|
77
|
-
|
|
78
|
-
self.exec_module()
|
|
79
|
-
|
|
80
|
-
self.assertEqual(self.retcode, 0)
|
|
81
|
-
self.assertEqual(len(self.stdout), 19) # segments A & B (i.e. nothing)
|
|
82
|
-
self.assertEqual(len(self.stderr), 0)
|
|
83
|
-
|
|
84
|
-
def test_file_not_found(self):
|
|
85
|
-
"""$ pdb_selseg not_existing.pdb"""
|
|
86
|
-
|
|
87
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
88
|
-
sys.argv = ['', afile]
|
|
89
|
-
|
|
90
|
-
self.exec_module()
|
|
91
|
-
|
|
92
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
93
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
94
|
-
self.assertEqual(self.stderr[0][:22],
|
|
95
|
-
"ERROR!! File not found") # proper error message
|
|
96
|
-
|
|
97
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
98
|
-
def test_file_missing(self):
|
|
99
|
-
"""$ pdb_selseg -A"""
|
|
100
|
-
|
|
101
|
-
sys.argv = ['', '-A']
|
|
102
|
-
|
|
103
|
-
self.exec_module()
|
|
104
|
-
|
|
105
|
-
self.assertEqual(self.retcode, 1)
|
|
106
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
107
|
-
self.assertEqual(self.stderr[0],
|
|
108
|
-
"ERROR!! No data to process!")
|
|
109
|
-
|
|
110
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
111
|
-
def test_helptext(self):
|
|
112
|
-
"""$ pdb_selseg"""
|
|
113
|
-
|
|
114
|
-
sys.argv = ['']
|
|
115
|
-
|
|
116
|
-
self.exec_module()
|
|
117
|
-
|
|
118
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
119
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
120
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
121
|
-
|
|
122
|
-
def test_invalid_option(self):
|
|
123
|
-
"""$ pdb_selseg data/dummy.pdb"""
|
|
124
|
-
|
|
125
|
-
sys.argv = ['', os.path.join(data_dir, 'dummy.pdb')]
|
|
126
|
-
|
|
127
|
-
self.exec_module()
|
|
128
|
-
|
|
129
|
-
self.assertEqual(self.retcode, 1)
|
|
130
|
-
self.assertEqual(len(self.stdout), 0)
|
|
131
|
-
self.assertEqual(self.stderr[0][:47],
|
|
132
|
-
"ERROR!! You must provide at least one segment i")
|
|
133
|
-
|
|
134
|
-
def test_invalid_option_2(self):
|
|
135
|
-
"""$ pdb_selseg -ABCDE data/dummy.pdb"""
|
|
136
|
-
|
|
137
|
-
sys.argv = ['', '-ABCDE', os.path.join(data_dir, 'dummy.pdb')]
|
|
138
|
-
|
|
139
|
-
self.exec_module()
|
|
140
|
-
|
|
141
|
-
self.assertEqual(self.retcode, 1)
|
|
142
|
-
self.assertEqual(len(self.stdout), 0)
|
|
143
|
-
self.assertEqual(self.stderr[0][:40],
|
|
144
|
-
"ERROR!! Segment identifier name is inval")
|
|
145
|
-
|
|
146
|
-
def test_not_an_option(self):
|
|
147
|
-
"""$ pdb_selseg 20 data/dummy.pdb"""
|
|
148
|
-
|
|
149
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
|
|
150
|
-
|
|
151
|
-
self.exec_module()
|
|
152
|
-
|
|
153
|
-
self.assertEqual(self.retcode, 1)
|
|
154
|
-
self.assertEqual(len(self.stdout), 0)
|
|
155
|
-
self.assertEqual(self.stderr[0],
|
|
156
|
-
"ERROR! First argument is not an option: '20'")
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if __name__ == '__main__':
|
|
160
|
-
from config import test_dir
|
|
161
|
-
|
|
162
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
163
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
164
|
-
|
|
165
|
-
unittest.main()
|