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_tocif.py
DELETED
|
@@ -1,238 +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_tocif`.
|
|
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_tocif'
|
|
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_model_run_iterable(self):
|
|
57
|
-
"""$ pdb_tocif.run(iterable)"""
|
|
58
|
-
from pdbtools import pdb_tocif
|
|
59
|
-
|
|
60
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
61
|
-
with open(fpath, 'r') as fin:
|
|
62
|
-
lines = fin.readlines()
|
|
63
|
-
|
|
64
|
-
newlines = list(pdb_tocif.run(lines))
|
|
65
|
-
|
|
66
|
-
# Check no of records
|
|
67
|
-
n_ATOM = sum(1 for l in newlines if l.startswith('ATOM'))
|
|
68
|
-
n_HETATM = sum(1 for l in newlines if l.startswith('HETATM'))
|
|
69
|
-
n_coord = n_ATOM + n_HETATM
|
|
70
|
-
self.assertEqual(n_ATOM, 176)
|
|
71
|
-
self.assertEqual(n_HETATM, 9)
|
|
72
|
-
self.assertEqual(n_coord, 185)
|
|
73
|
-
|
|
74
|
-
# check name
|
|
75
|
-
self.assertEqual(newlines[2], 'data_cell\n')
|
|
76
|
-
|
|
77
|
-
def test_single_model_run_iterable_with_name(self):
|
|
78
|
-
"""$ pdb_tocif.run(iterable)"""
|
|
79
|
-
from pdbtools import pdb_tocif
|
|
80
|
-
|
|
81
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
82
|
-
with open(fpath, 'r') as fin:
|
|
83
|
-
lines = fin.readlines()
|
|
84
|
-
|
|
85
|
-
newlines = list(pdb_tocif.run(lines, outname='newcif'))
|
|
86
|
-
|
|
87
|
-
# Check no of records
|
|
88
|
-
n_ATOM = sum(1 for l in newlines if l.startswith('ATOM'))
|
|
89
|
-
n_HETATM = sum(1 for l in newlines if l.startswith('HETATM'))
|
|
90
|
-
n_coord = n_ATOM + n_HETATM
|
|
91
|
-
self.assertEqual(n_ATOM, 176)
|
|
92
|
-
self.assertEqual(n_HETATM, 9)
|
|
93
|
-
self.assertEqual(n_coord, 185)
|
|
94
|
-
|
|
95
|
-
# check name
|
|
96
|
-
self.assertEqual(newlines[2], 'data_newcif\n')
|
|
97
|
-
|
|
98
|
-
def test_single_model_run_fhandler(self):
|
|
99
|
-
"""$ pdb_tocif.run(fhandler)"""
|
|
100
|
-
from pdbtools import pdb_tocif
|
|
101
|
-
|
|
102
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
103
|
-
with open(fpath, 'r') as fin:
|
|
104
|
-
newlines = list(pdb_tocif.run(fin))
|
|
105
|
-
|
|
106
|
-
# Check no of records
|
|
107
|
-
n_ATOM = sum(1 for l in newlines if l.startswith('ATOM'))
|
|
108
|
-
n_HETATM = sum(1 for l in newlines if l.startswith('HETATM'))
|
|
109
|
-
n_coord = n_ATOM + n_HETATM
|
|
110
|
-
self.assertEqual(n_ATOM, 176)
|
|
111
|
-
self.assertEqual(n_HETATM, 9)
|
|
112
|
-
self.assertEqual(n_coord, 185)
|
|
113
|
-
|
|
114
|
-
# check name
|
|
115
|
-
self.assertEqual(newlines[2], 'data_dummy\n')
|
|
116
|
-
|
|
117
|
-
def test_single_model_run_fhandler_name(self):
|
|
118
|
-
"""$ pdb_tocif.run(fhandler)"""
|
|
119
|
-
from pdbtools import pdb_tocif
|
|
120
|
-
|
|
121
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
122
|
-
with open(fpath, 'r') as fin:
|
|
123
|
-
newlines = list(pdb_tocif.run(fin, outname='newname'))
|
|
124
|
-
|
|
125
|
-
# Check no of records
|
|
126
|
-
n_ATOM = sum(1 for l in newlines if l.startswith('ATOM'))
|
|
127
|
-
n_HETATM = sum(1 for l in newlines if l.startswith('HETATM'))
|
|
128
|
-
n_coord = n_ATOM + n_HETATM
|
|
129
|
-
self.assertEqual(n_ATOM, 176)
|
|
130
|
-
self.assertEqual(n_HETATM, 9)
|
|
131
|
-
self.assertEqual(n_coord, 185)
|
|
132
|
-
|
|
133
|
-
# check name
|
|
134
|
-
self.assertEqual(newlines[2], 'data_newname\n')
|
|
135
|
-
|
|
136
|
-
def test_single_model(self):
|
|
137
|
-
"""$ pdb_tocif data/dummy.pdb"""
|
|
138
|
-
|
|
139
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
140
|
-
sys.argv = ['', fpath]
|
|
141
|
-
|
|
142
|
-
# Execute the script
|
|
143
|
-
self.exec_module()
|
|
144
|
-
|
|
145
|
-
# Validate results
|
|
146
|
-
self.assertEqual(self.retcode, 0)
|
|
147
|
-
self.assertEqual(len(self.stdout), 212)
|
|
148
|
-
self.assertEqual(len(self.stderr), 0)
|
|
149
|
-
|
|
150
|
-
# Check no of records
|
|
151
|
-
n_ATOM = len([l for l in self.stdout if l.startswith('ATOM')])
|
|
152
|
-
n_HETATM = len([l for l in self.stdout if l.startswith('HETATM')])
|
|
153
|
-
n_coord = n_ATOM + n_HETATM
|
|
154
|
-
self.assertEqual(n_ATOM, 176)
|
|
155
|
-
self.assertEqual(n_HETATM, 9)
|
|
156
|
-
self.assertEqual(n_coord, 185)
|
|
157
|
-
|
|
158
|
-
def test_multi_model(self):
|
|
159
|
-
"""$ pdb_tocif data/ensemble_OK.pdb"""
|
|
160
|
-
|
|
161
|
-
fpath = os.path.join(data_dir, 'ensemble_OK.pdb')
|
|
162
|
-
sys.argv = ['', fpath]
|
|
163
|
-
|
|
164
|
-
# Execute the script
|
|
165
|
-
self.exec_module()
|
|
166
|
-
|
|
167
|
-
# Validate results
|
|
168
|
-
self.assertEqual(self.retcode, 0)
|
|
169
|
-
self.assertEqual(len(self.stdout), 31)
|
|
170
|
-
self.assertEqual(len(self.stderr), 0)
|
|
171
|
-
|
|
172
|
-
# Check no of records
|
|
173
|
-
n_ATOM = len([l for l in self.stdout if l.startswith('ATOM')])
|
|
174
|
-
n_HETATM = len([l for l in self.stdout if l.startswith('HETATM')])
|
|
175
|
-
n_coord = n_ATOM + n_HETATM
|
|
176
|
-
self.assertEqual(n_ATOM, 4)
|
|
177
|
-
self.assertEqual(n_HETATM, 0)
|
|
178
|
-
self.assertEqual(n_coord, 4)
|
|
179
|
-
|
|
180
|
-
# Check model numbers
|
|
181
|
-
records = (('ATOM', 'HETATM'))
|
|
182
|
-
models = [l.split()[-1] for l in self.stdout if l.startswith(records)]
|
|
183
|
-
self.assertEqual(models, ['1', '1', '2', '2'])
|
|
184
|
-
|
|
185
|
-
# Check number of fields
|
|
186
|
-
atom_lines = [l for l in self.stdout if l.startswith(records)]
|
|
187
|
-
n_fields = list(set(map(lambda x: len(x.split()), atom_lines)))
|
|
188
|
-
self.assertEqual(n_fields, [21])
|
|
189
|
-
|
|
190
|
-
def test_file_not_found(self):
|
|
191
|
-
"""$ pdb_tocif not_existing.pdb"""
|
|
192
|
-
|
|
193
|
-
# Error (file not found)
|
|
194
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
195
|
-
sys.argv = ['', afile]
|
|
196
|
-
|
|
197
|
-
# Execute the script
|
|
198
|
-
self.exec_module()
|
|
199
|
-
|
|
200
|
-
self.assertEqual(self.retcode, 1)
|
|
201
|
-
self.assertEqual(len(self.stdout), 0)
|
|
202
|
-
self.assertEqual(self.stderr[0][:22],
|
|
203
|
-
"ERROR!! File not found")
|
|
204
|
-
|
|
205
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
206
|
-
def test_helptext(self):
|
|
207
|
-
"""$ pdb_tocif"""
|
|
208
|
-
|
|
209
|
-
sys.argv = ['']
|
|
210
|
-
|
|
211
|
-
# Execute the script
|
|
212
|
-
self.exec_module()
|
|
213
|
-
|
|
214
|
-
self.assertEqual(self.retcode, 1)
|
|
215
|
-
self.assertEqual(len(self.stdout), 0)
|
|
216
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
217
|
-
|
|
218
|
-
def test_invalid_option(self):
|
|
219
|
-
"""$ pdb_tocif -A data/dummy.pdb"""
|
|
220
|
-
|
|
221
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
222
|
-
|
|
223
|
-
# Execute the script
|
|
224
|
-
self.exec_module()
|
|
225
|
-
|
|
226
|
-
self.assertEqual(self.retcode, 1)
|
|
227
|
-
self.assertEqual(len(self.stdout), 0)
|
|
228
|
-
self.assertEqual(self.stderr[0][:36],
|
|
229
|
-
"ERROR!! Script takes 1 argument, not")
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if __name__ == '__main__':
|
|
233
|
-
from config import test_dir
|
|
234
|
-
|
|
235
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
236
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
237
|
-
|
|
238
|
-
unittest.main()
|
tests/test_pdb_tofasta.py
DELETED
|
@@ -1,158 +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_tofasta`.
|
|
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_tofasta'
|
|
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_tofasta data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
60
|
-
sys.argv = ['', fpath]
|
|
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), 2)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
69
|
-
|
|
70
|
-
self.assertEqual(self.stdout, ['>1DUM|ABCD', 'REANREREMXXXXXXXXXX'])
|
|
71
|
-
|
|
72
|
-
def test_headerless(self):
|
|
73
|
-
"""$ pdb_tofasta data/dummy_nohead.pdb"""
|
|
74
|
-
|
|
75
|
-
fpath = os.path.join(data_dir, 'dummy_nohead.pdb')
|
|
76
|
-
sys.argv = ['', fpath]
|
|
77
|
-
|
|
78
|
-
# Execute the script
|
|
79
|
-
self.exec_module()
|
|
80
|
-
|
|
81
|
-
# Validate results
|
|
82
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
83
|
-
self.assertEqual(len(self.stdout), 2)
|
|
84
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
85
|
-
|
|
86
|
-
self.assertEqual(self.stdout, ['>PDB|ABCD', 'REANREREMXXXXXXXXXX'])
|
|
87
|
-
|
|
88
|
-
def test_multi(self):
|
|
89
|
-
"""$ pdb_tofasta -multi data/dummy.pdb"""
|
|
90
|
-
|
|
91
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
92
|
-
sys.argv = ['', '-multi', fpath]
|
|
93
|
-
|
|
94
|
-
# Execute the script
|
|
95
|
-
self.exec_module()
|
|
96
|
-
|
|
97
|
-
# Validate results
|
|
98
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
99
|
-
self.assertEqual(len(self.stdout), 14)
|
|
100
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
101
|
-
|
|
102
|
-
self.assertEqual(self.stdout, ['>1DUM|B', 'REA',
|
|
103
|
-
'>1DUM|A', 'NRE',
|
|
104
|
-
'>1DUM|C', 'REM',
|
|
105
|
-
'>1DUM|D', 'X',
|
|
106
|
-
'>1DUM|A', 'XXX',
|
|
107
|
-
'>1DUM|B', 'X',
|
|
108
|
-
'>1DUM|C', 'XXXXX'])
|
|
109
|
-
|
|
110
|
-
def test_file_not_found(self):
|
|
111
|
-
"""$ pdb_tofasta not_existing.pdb"""
|
|
112
|
-
|
|
113
|
-
# Error (file not found)
|
|
114
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
115
|
-
sys.argv = ['', afile]
|
|
116
|
-
|
|
117
|
-
# Execute the script
|
|
118
|
-
self.exec_module()
|
|
119
|
-
|
|
120
|
-
self.assertEqual(self.retcode, 1)
|
|
121
|
-
self.assertEqual(len(self.stdout), 0)
|
|
122
|
-
self.assertEqual(self.stderr[0][:22],
|
|
123
|
-
"ERROR!! File not found")
|
|
124
|
-
|
|
125
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
126
|
-
def test_helptext(self):
|
|
127
|
-
"""$ pdb_tofasta"""
|
|
128
|
-
|
|
129
|
-
sys.argv = ['']
|
|
130
|
-
|
|
131
|
-
# Execute the script
|
|
132
|
-
self.exec_module()
|
|
133
|
-
|
|
134
|
-
self.assertEqual(self.retcode, 1)
|
|
135
|
-
self.assertEqual(len(self.stdout), 0)
|
|
136
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
137
|
-
|
|
138
|
-
def test_invalid_option(self):
|
|
139
|
-
"""$ pdb_tofasta -A data/dummy.pdb"""
|
|
140
|
-
|
|
141
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
142
|
-
|
|
143
|
-
# Execute the script
|
|
144
|
-
self.exec_module()
|
|
145
|
-
|
|
146
|
-
self.assertEqual(self.retcode, 1)
|
|
147
|
-
self.assertEqual(len(self.stdout), 0)
|
|
148
|
-
self.assertEqual(self.stderr[0][:36],
|
|
149
|
-
"ERROR!! You provided an invalid opti")
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if __name__ == '__main__':
|
|
153
|
-
from config import test_dir
|
|
154
|
-
|
|
155
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
156
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
157
|
-
|
|
158
|
-
unittest.main()
|
tests/test_pdb_uniqname.py
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2020 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_uniqname`.
|
|
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_uniqname'
|
|
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_uniqname data/hetatm.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
sys.argv = ['', os.path.join(data_dir, 'hetatm.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), 19) # no lines deleted
|
|
68
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
69
|
-
|
|
70
|
-
records = ('ATOM', 'HETATM')
|
|
71
|
-
atnames = [l[12:16] for l in self.stdout if l.startswith(records)]
|
|
72
|
-
|
|
73
|
-
self.assertEqual(
|
|
74
|
-
atnames,
|
|
75
|
-
[
|
|
76
|
-
' C1 ', ' C2 ', ' H1 ', ' C3 ',
|
|
77
|
-
'CA1 ', 'CA2 ', ' H1 ', ' H2 ',
|
|
78
|
-
' C1 ', ' C2 ', ' H ', ' H '
|
|
79
|
-
]
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
def test_error(self):
|
|
83
|
-
"""$ pdb_uniqname data/hetatm_bad.pdb"""
|
|
84
|
-
|
|
85
|
-
# Simulate input
|
|
86
|
-
sys.argv = ['', os.path.join(data_dir, 'hetatm_bad.pdb')]
|
|
87
|
-
|
|
88
|
-
# Execute the script
|
|
89
|
-
self.exec_module()
|
|
90
|
-
|
|
91
|
-
# Validate results
|
|
92
|
-
self.assertEqual(self.retcode, 1) # ensure the program threw an error
|
|
93
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
94
|
-
|
|
95
|
-
self.assertEqual(self.stderr[0][:22],
|
|
96
|
-
"ERROR!! No element fou") # proper error message
|
|
97
|
-
|
|
98
|
-
def test_file_not_found(self):
|
|
99
|
-
"""$ pdb_uniqname not_existing.pdb"""
|
|
100
|
-
|
|
101
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
102
|
-
sys.argv = ['', afile]
|
|
103
|
-
|
|
104
|
-
self.exec_module()
|
|
105
|
-
|
|
106
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
107
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
108
|
-
self.assertEqual(self.stderr[0][:22],
|
|
109
|
-
"ERROR!! File not found") # proper error message
|
|
110
|
-
|
|
111
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
112
|
-
def test_file_missing(self):
|
|
113
|
-
"""$ pdb_uniqname"""
|
|
114
|
-
|
|
115
|
-
sys.argv = ['']
|
|
116
|
-
|
|
117
|
-
self.exec_module()
|
|
118
|
-
|
|
119
|
-
self.assertEqual(self.retcode, 1)
|
|
120
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
121
|
-
self.assertEqual(self.stderr[1],
|
|
122
|
-
self.module.__doc__.split("\n")[1])
|
|
123
|
-
|
|
124
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
125
|
-
def test_helptext(self):
|
|
126
|
-
"""$ pdb_uniqname"""
|
|
127
|
-
|
|
128
|
-
sys.argv = ['']
|
|
129
|
-
|
|
130
|
-
self.exec_module()
|
|
131
|
-
|
|
132
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
133
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
134
|
-
self.assertEqual(self.stderr[1],
|
|
135
|
-
self.module.__doc__.split("\n")[1])
|
|
136
|
-
|
|
137
|
-
def test_invalid_option(self):
|
|
138
|
-
"""$ pdb_uniqname -A data/dummy.pdb"""
|
|
139
|
-
|
|
140
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
141
|
-
|
|
142
|
-
self.exec_module()
|
|
143
|
-
|
|
144
|
-
self.assertEqual(self.retcode, 1)
|
|
145
|
-
self.assertEqual(len(self.stdout), 0)
|
|
146
|
-
self.assertEqual(self.stderr[1],
|
|
147
|
-
self.module.__doc__.split("\n")[1])
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if __name__ == '__main__':
|
|
151
|
-
from config import test_dir
|
|
152
|
-
|
|
153
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
154
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
155
|
-
|
|
156
|
-
unittest.main()
|
tests/test_pdb_validate.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_validate`.
|
|
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_validate'
|
|
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_warnings(self):
|
|
57
|
-
"""$ pdb_validate data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
60
|
-
sys.argv = ['', fpath]
|
|
61
|
-
|
|
62
|
-
# Execute the script
|
|
63
|
-
self.exec_module()
|
|
64
|
-
|
|
65
|
-
# Validate results
|
|
66
|
-
self.assertEqual(self.retcode, 1)
|
|
67
|
-
self.assertEqual(len(self.stdout), 253)
|
|
68
|
-
self.assertEqual(len(self.stderr), 0)
|
|
69
|
-
|
|
70
|
-
# Count no. of line length warnings
|
|
71
|
-
n_warn = len([l for l in self.stdout if 'is short' in l])
|
|
72
|
-
self.assertEqual(n_warn, 70)
|
|
73
|
-
|
|
74
|
-
self.assertEqual(self.stdout[-4],
|
|
75
|
-
"[!] Line 203 is short: 26 < 80")
|
|
76
|
-
|
|
77
|
-
def test_valid(self):
|
|
78
|
-
"""$ pdb_validate data/ensemble_OK.pdb"""
|
|
79
|
-
|
|
80
|
-
fpath = os.path.join(data_dir, 'ensemble_OK.pdb')
|
|
81
|
-
sys.argv = ['', fpath]
|
|
82
|
-
|
|
83
|
-
# Execute the script
|
|
84
|
-
self.exec_module()
|
|
85
|
-
|
|
86
|
-
# Validate results
|
|
87
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
88
|
-
self.assertEqual(len(self.stderr), 0)
|
|
89
|
-
self.assertEqual(len(self.stdout), 1) # no errors
|
|
90
|
-
|
|
91
|
-
self.assertEqual(self.stdout,
|
|
92
|
-
["It *seems* everything is OK."])
|
|
93
|
-
|
|
94
|
-
def test_file_not_found(self):
|
|
95
|
-
"""$ pdb_validate not_existing.pdb"""
|
|
96
|
-
|
|
97
|
-
# Error (file not found)
|
|
98
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
99
|
-
sys.argv = ['', afile]
|
|
100
|
-
|
|
101
|
-
# Execute the script
|
|
102
|
-
self.exec_module()
|
|
103
|
-
|
|
104
|
-
self.assertEqual(self.retcode, 1)
|
|
105
|
-
self.assertEqual(len(self.stdout), 0)
|
|
106
|
-
self.assertEqual(self.stderr[0][:22],
|
|
107
|
-
"ERROR!! File not found")
|
|
108
|
-
|
|
109
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
110
|
-
def test_helptext(self):
|
|
111
|
-
"""$ pdb_validate"""
|
|
112
|
-
|
|
113
|
-
sys.argv = ['']
|
|
114
|
-
|
|
115
|
-
# Execute the script
|
|
116
|
-
self.exec_module()
|
|
117
|
-
|
|
118
|
-
self.assertEqual(self.retcode, 1)
|
|
119
|
-
self.assertEqual(len(self.stdout), 0)
|
|
120
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
121
|
-
|
|
122
|
-
def test_invalid_option(self):
|
|
123
|
-
"""$ pdb_validate -A data/dummy.pdb"""
|
|
124
|
-
|
|
125
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
126
|
-
|
|
127
|
-
# Execute the script
|
|
128
|
-
self.exec_module()
|
|
129
|
-
|
|
130
|
-
self.assertEqual(self.retcode, 1)
|
|
131
|
-
self.assertEqual(len(self.stdout), 0)
|
|
132
|
-
self.assertEqual(self.stderr[0][:36],
|
|
133
|
-
"ERROR!! Script takes 1 argument, not")
|
|
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()
|