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_selatom.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_selatom`.
|
|
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_selatom'
|
|
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_selatom -CA data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_selatom dummy.pdb
|
|
61
|
-
sys.argv = ['', '-CA', 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), 30) # selected CA
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
def test_multiple(self):
|
|
72
|
-
"""
|
|
73
|
-
$ pdb_selatom -CA,CB data/dummy.pdb
|
|
74
|
-
"""
|
|
75
|
-
|
|
76
|
-
sys.argv = ['', '-CA,CB', 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), 39) # CA + CB
|
|
82
|
-
self.assertEqual(len(self.stderr), 0)
|
|
83
|
-
|
|
84
|
-
def test_file_not_found(self):
|
|
85
|
-
"""$ pdb_selatom 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_selatom -CA"""
|
|
100
|
-
|
|
101
|
-
sys.argv = ['', '-CA']
|
|
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_selatom"""
|
|
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_selatom 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][:37],
|
|
132
|
-
"ERROR!! Atom name set cannot be empty")
|
|
133
|
-
|
|
134
|
-
def test_invalid_option_2(self):
|
|
135
|
-
"""$ pdb_selatom -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][:37],
|
|
144
|
-
"ERROR!! Atom name is invalid: 'ABCDE'")
|
|
145
|
-
|
|
146
|
-
def test_not_an_option(self):
|
|
147
|
-
"""$ pdb_selatom 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()
|
tests/test_pdb_selchain.py
DELETED
|
@@ -1,210 +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_selchain`.
|
|
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_selchain'
|
|
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_selchain -A data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_selchain dummy.pdb
|
|
61
|
-
sys.argv = ['', '-A', 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), 76) # selected c.A
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
def test_one_option_CAPS_lowercase(self):
|
|
72
|
-
"""$ pdb_selchain -A data/dummy_az09.pdb"""
|
|
73
|
-
|
|
74
|
-
# Simulate input
|
|
75
|
-
# pdb_selchain dummy_az09.pdb
|
|
76
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy_az09.pdb')]
|
|
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), 76) # selected c.A
|
|
84
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
85
|
-
|
|
86
|
-
def test_one_option_lowercase(self):
|
|
87
|
-
"""$ pdb_selchain -b data/dummy_az09.pdb"""
|
|
88
|
-
|
|
89
|
-
# Simulate input
|
|
90
|
-
# pdb_selchain dummy.pdb
|
|
91
|
-
sys.argv = ['', '-b', os.path.join(data_dir, 'dummy_az09.pdb')]
|
|
92
|
-
|
|
93
|
-
# Execute the script
|
|
94
|
-
self.exec_module()
|
|
95
|
-
|
|
96
|
-
# Validate results
|
|
97
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
98
|
-
self.assertEqual(len(self.stdout), 69) # selected c.b
|
|
99
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
100
|
-
|
|
101
|
-
def test_one_option_digit(self):
|
|
102
|
-
"""$ pdb_selchain -1 data/dummy_az09.pdb"""
|
|
103
|
-
|
|
104
|
-
# Simulate input
|
|
105
|
-
# pdb_selchain dummy.pdb
|
|
106
|
-
sys.argv = ['', '-1', os.path.join(data_dir, 'dummy_az09.pdb')]
|
|
107
|
-
|
|
108
|
-
# Execute the script
|
|
109
|
-
self.exec_module()
|
|
110
|
-
|
|
111
|
-
# Validate results
|
|
112
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
113
|
-
self.assertEqual(len(self.stdout), 71) # selected c.1
|
|
114
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
115
|
-
|
|
116
|
-
def test_multiple(self):
|
|
117
|
-
"""
|
|
118
|
-
$ pdb_selchain -A,B data/dummy.pdb
|
|
119
|
-
"""
|
|
120
|
-
|
|
121
|
-
sys.argv = ['', '-A,B', os.path.join(data_dir, 'dummy.pdb')]
|
|
122
|
-
|
|
123
|
-
self.exec_module()
|
|
124
|
-
|
|
125
|
-
self.assertEqual(self.retcode, 0)
|
|
126
|
-
self.assertEqual(len(self.stdout), 129) # c.A + c.B
|
|
127
|
-
self.assertEqual(len(self.stderr), 0)
|
|
128
|
-
|
|
129
|
-
def test_file_not_found(self):
|
|
130
|
-
"""$ pdb_selchain not_existing.pdb"""
|
|
131
|
-
|
|
132
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
133
|
-
sys.argv = ['', afile]
|
|
134
|
-
|
|
135
|
-
self.exec_module()
|
|
136
|
-
|
|
137
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
138
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
139
|
-
self.assertEqual(self.stderr[0][:22],
|
|
140
|
-
"ERROR!! File not found") # proper error message
|
|
141
|
-
|
|
142
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
143
|
-
def test_file_missing(self):
|
|
144
|
-
"""$ pdb_selchain -A"""
|
|
145
|
-
|
|
146
|
-
sys.argv = ['', '-A']
|
|
147
|
-
|
|
148
|
-
self.exec_module()
|
|
149
|
-
|
|
150
|
-
self.assertEqual(self.retcode, 1)
|
|
151
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
152
|
-
self.assertEqual(self.stderr[0],
|
|
153
|
-
"ERROR!! No data to process!")
|
|
154
|
-
|
|
155
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
156
|
-
def test_helptext(self):
|
|
157
|
-
"""$ pdb_selchain"""
|
|
158
|
-
|
|
159
|
-
sys.argv = ['']
|
|
160
|
-
|
|
161
|
-
self.exec_module()
|
|
162
|
-
|
|
163
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
164
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
165
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
166
|
-
|
|
167
|
-
def test_invalid_option(self):
|
|
168
|
-
"""$ pdb_selchain data/dummy.pdb"""
|
|
169
|
-
|
|
170
|
-
sys.argv = ['', os.path.join(data_dir, 'dummy.pdb')]
|
|
171
|
-
|
|
172
|
-
self.exec_module()
|
|
173
|
-
|
|
174
|
-
self.assertEqual(self.retcode, 1)
|
|
175
|
-
self.assertEqual(len(self.stdout), 0)
|
|
176
|
-
self.assertEqual(self.stderr[0][:47],
|
|
177
|
-
"ERROR!! You must provide at least one chain ide")
|
|
178
|
-
|
|
179
|
-
def test_invalid_option_2(self):
|
|
180
|
-
"""$ pdb_selchain -AB data/dummy.pdb"""
|
|
181
|
-
|
|
182
|
-
sys.argv = ['', '-AB', os.path.join(data_dir, 'dummy.pdb')]
|
|
183
|
-
|
|
184
|
-
self.exec_module()
|
|
185
|
-
|
|
186
|
-
self.assertEqual(self.retcode, 1)
|
|
187
|
-
self.assertEqual(len(self.stdout), 0)
|
|
188
|
-
self.assertEqual(self.stderr[0][:40],
|
|
189
|
-
"ERROR!! Chain identifier name is invalid")
|
|
190
|
-
|
|
191
|
-
def test_not_an_option(self):
|
|
192
|
-
"""$ pdb_selchain 20 data/dummy.pdb"""
|
|
193
|
-
|
|
194
|
-
sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
|
|
195
|
-
|
|
196
|
-
self.exec_module()
|
|
197
|
-
|
|
198
|
-
self.assertEqual(self.retcode, 1)
|
|
199
|
-
self.assertEqual(len(self.stdout), 0)
|
|
200
|
-
self.assertEqual(self.stderr[0],
|
|
201
|
-
"ERROR! First argument is not an option: '20'")
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if __name__ == '__main__':
|
|
205
|
-
from config import test_dir
|
|
206
|
-
|
|
207
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
208
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
209
|
-
|
|
210
|
-
unittest.main()
|
tests/test_pdb_selelem.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_selelem`.
|
|
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_selelem'
|
|
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_selelem -C data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_selelem dummy.pdb
|
|
61
|
-
sys.argv = ['', '-C', 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), 60) # selected C
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
def test_multiple(self):
|
|
72
|
-
"""
|
|
73
|
-
$ pdb_selelem -C,O data/dummy.pdb
|
|
74
|
-
"""
|
|
75
|
-
|
|
76
|
-
sys.argv = ['', '-C,O', 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), 75)
|
|
82
|
-
self.assertEqual(len(self.stderr), 0)
|
|
83
|
-
|
|
84
|
-
def test_file_not_found(self):
|
|
85
|
-
"""$ pdb_selelem 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_selelem -C"""
|
|
100
|
-
|
|
101
|
-
sys.argv = ['', '-C']
|
|
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_selelem"""
|
|
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_selelem 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][:37],
|
|
132
|
-
"ERROR!! Element set cannot be empty")
|
|
133
|
-
|
|
134
|
-
def test_invalid_option_2(self):
|
|
135
|
-
"""$ pdb_selelem -ABC data/dummy.pdb"""
|
|
136
|
-
|
|
137
|
-
sys.argv = ['', '-ABC', 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][:38],
|
|
144
|
-
"ERROR!! Element name is invalid: 'ABC'")
|
|
145
|
-
|
|
146
|
-
def test_not_an_option(self):
|
|
147
|
-
"""$ pdb_selelem 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()
|
tests/test_pdb_selhetatm.py
DELETED
|
@@ -1,116 +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_selhetatm`.
|
|
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_selhetatm'
|
|
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_selhetatm data/dummy.pdb"""
|
|
58
|
-
|
|
59
|
-
# Simulate input
|
|
60
|
-
# pdb_selhetatm dummy.pdb
|
|
61
|
-
sys.argv = ['', 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), 10) # 9 HETATM records + 1 CONECT
|
|
69
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def test_file_not_found(self):
|
|
73
|
-
"""$ pdb_selhetatm not_existing.pdb"""
|
|
74
|
-
|
|
75
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
76
|
-
sys.argv = ['', afile]
|
|
77
|
-
|
|
78
|
-
self.exec_module()
|
|
79
|
-
|
|
80
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
81
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
82
|
-
self.assertEqual(self.stderr[0][:22],
|
|
83
|
-
"ERROR!! File not found") # proper error message
|
|
84
|
-
|
|
85
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
86
|
-
def test_helptext(self):
|
|
87
|
-
"""$ pdb_selhetatm"""
|
|
88
|
-
|
|
89
|
-
sys.argv = ['']
|
|
90
|
-
|
|
91
|
-
self.exec_module()
|
|
92
|
-
|
|
93
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
94
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
95
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
96
|
-
|
|
97
|
-
def test_invalid_option(self):
|
|
98
|
-
"""$ pdb_selhetatm -A data/dummy.pdb"""
|
|
99
|
-
|
|
100
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
101
|
-
|
|
102
|
-
self.exec_module()
|
|
103
|
-
|
|
104
|
-
self.assertEqual(self.retcode, 1)
|
|
105
|
-
self.assertEqual(len(self.stdout), 0)
|
|
106
|
-
self.assertEqual(self.stderr[0][:36],
|
|
107
|
-
"ERROR!! Script takes 1 argument, not")
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if __name__ == '__main__':
|
|
111
|
-
from config import test_dir
|
|
112
|
-
|
|
113
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
114
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
115
|
-
|
|
116
|
-
unittest.main()
|