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.
Files changed (58) hide show
  1. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/METADATA +19 -11
  2. pdb_tools-2.5.1.dist-info/RECORD +55 -0
  3. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/WHEEL +1 -1
  4. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/entry_points.txt +1 -1
  5. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/top_level.txt +0 -1
  6. pdbtools/pdb_selmodel.py +194 -0
  7. pdbtools/pdb_tidy.py +17 -9
  8. pdb_tools-2.4.12.dist-info/RECORD +0 -103
  9. tests/__init__.py +0 -38
  10. tests/config.py +0 -25
  11. tests/test_pdb_b.py +0 -161
  12. tests/test_pdb_chain.py +0 -160
  13. tests/test_pdb_chainbows.py +0 -140
  14. tests/test_pdb_chainxseg.py +0 -156
  15. tests/test_pdb_chkensemble.py +0 -191
  16. tests/test_pdb_delchain.py +0 -165
  17. tests/test_pdb_delelem.py +0 -165
  18. tests/test_pdb_delhetatm.py +0 -115
  19. tests/test_pdb_delinsertion.py +0 -226
  20. tests/test_pdb_delres.py +0 -241
  21. tests/test_pdb_delresname.py +0 -171
  22. tests/test_pdb_element.py +0 -151
  23. tests/test_pdb_fixinsert.py +0 -223
  24. tests/test_pdb_fromcif.py +0 -124
  25. tests/test_pdb_gap.py +0 -125
  26. tests/test_pdb_head.py +0 -142
  27. tests/test_pdb_intersect.py +0 -139
  28. tests/test_pdb_keepcoord.py +0 -115
  29. tests/test_pdb_merge.py +0 -106
  30. tests/test_pdb_mkensemble.py +0 -132
  31. tests/test_pdb_occ.py +0 -161
  32. tests/test_pdb_reatom.py +0 -243
  33. tests/test_pdb_reres.py +0 -281
  34. tests/test_pdb_rplchain.py +0 -172
  35. tests/test_pdb_rplresname.py +0 -172
  36. tests/test_pdb_seg.py +0 -160
  37. tests/test_pdb_segxchain.py +0 -146
  38. tests/test_pdb_selaltloc.py +0 -943
  39. tests/test_pdb_selatom.py +0 -165
  40. tests/test_pdb_selchain.py +0 -210
  41. tests/test_pdb_selelem.py +0 -165
  42. tests/test_pdb_selhetatm.py +0 -116
  43. tests/test_pdb_selres.py +0 -257
  44. tests/test_pdb_selresname.py +0 -171
  45. tests/test_pdb_selseg.py +0 -165
  46. tests/test_pdb_shiftres.py +0 -241
  47. tests/test_pdb_sort.py +0 -254
  48. tests/test_pdb_splitchain.py +0 -242
  49. tests/test_pdb_splitmodel.py +0 -235
  50. tests/test_pdb_splitseg.py +0 -251
  51. tests/test_pdb_tidy.py +0 -312
  52. tests/test_pdb_tocif.py +0 -238
  53. tests/test_pdb_tofasta.py +0 -158
  54. tests/test_pdb_uniqname.py +0 -156
  55. tests/test_pdb_validate.py +0 -142
  56. tests/test_pdb_wc.py +0 -161
  57. tests/utils.py +0 -56
  58. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info/licenses}/LICENSE +0 -0
@@ -1,226 +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
- import warnings
26
-
27
- from config import data_dir
28
- from utils import OutputCapture
29
-
30
-
31
- class TestTool(unittest.TestCase):
32
- """
33
- Generic class for testing tools.
34
- """
35
-
36
- def setUp(self):
37
- # Dynamically import the module
38
- name = 'pdbtools.pdb_delinsertion'
39
- self.module = __import__(name, fromlist=[''])
40
-
41
- def exec_module(self):
42
- """
43
- Execs module.
44
- """
45
-
46
- with OutputCapture() as output:
47
- try:
48
- with warnings.catch_warnings():
49
- warnings.simplefilter("ignore")
50
- self.module.main()
51
- except SystemExit as e:
52
- self.retcode = e.code
53
-
54
- self.stdout = output.stdout
55
- self.stderr = output.stderr
56
-
57
- return
58
-
59
- def test_default(self):
60
- """$ pdb_fixinsert data/dummy_insertions.pdb"""
61
-
62
- # Simulate input
63
- # pdb_fixinsert dummy_insertions.pdb
64
- sys.argv = ['', os.path.join(data_dir, 'dummy_insertions.pdb')]
65
-
66
- # Execute the script
67
- self.exec_module()
68
-
69
- # Validate results
70
- self.assertEqual(self.retcode, 0) # ensure the program exited OK.
71
- self.assertEqual(len(self.stdout), 255) # no lines deleted
72
- self.assertEqual(len(self.stderr), 0) # no errors
73
-
74
- # Check if we do not have any insertions
75
- records = (('ATOM', 'HETATM', 'TER'))
76
- icodes = set(l[26] for l in self.stdout if l.startswith(records))
77
- self.assertEqual(icodes, set(' '))
78
-
79
- # Check numbering was corrected
80
- resid = [int(l[22:26]) for l in self.stdout if l.startswith(records)]
81
- expected = [
82
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
83
- 4, 4, 4, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
84
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7,
85
- 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
86
- 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
87
- 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
88
- 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
89
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
90
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1,
91
- -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92
- 2, 301, 302, 303, 301, 301, 302, 303, 304, 305
93
- ]
94
- self.assertEqual(resid, expected)
95
-
96
- def test_select_insertion(self):
97
- """$ pdb_fixinsert -A1 data/dummy_insertions.pdb"""
98
-
99
- sys.argv = ['', '-A1', os.path.join(data_dir, 'dummy_insertions.pdb')]
100
-
101
- self.exec_module()
102
-
103
- self.assertEqual(self.retcode, 0)
104
- self.assertEqual(len(self.stdout), 255)
105
- self.assertEqual(len(self.stderr), 0)
106
-
107
- records = (('ATOM', 'HETATM', 'TER'))
108
-
109
- # Check the insertions were deleted specifically
110
- for line in self.stdout:
111
- if line.startswith(records):
112
- icode = line[26]
113
- resid = int(line[22:26])
114
- if line[17:26] == 'ARG B 4':
115
- self.assertIn(icode, ('A', 'B'))
116
- self.assertEqual(resid, 4)
117
- elif line[17:26] == 'GLY B 4':
118
- self.assertEqual(icode, ' ')
119
- self.assertEqual(resid, 4)
120
- elif line[17:26] == 'ASN A 1':
121
- self.assertEqual(icode, ' ')
122
- self.assertEqual(resid, 1)
123
- elif line[17:26] == 'GLY A 1':
124
- self.assertEqual(icode, ' ')
125
- self.assertEqual(resid, 2) # should have renumbered
126
-
127
- # Check numbering was corrected overall
128
- resid = [int(l[22:26]) for l in self.stdout if l.startswith(records)]
129
- expected = [
130
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
131
- 4, 4, 4, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
132
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7,
133
- 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
134
- 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
135
- 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136
- 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
137
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
138
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1,
139
- -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
140
- 2, 301, 302, 303, 301, 301, 302, 303, 304, 305
141
- ]
142
-
143
- self.assertEqual(resid, expected)
144
-
145
- def test_file_not_found(self):
146
- """$ pdb_fixinsert not_existing.pdb"""
147
-
148
- afile = os.path.join(data_dir, 'not_existing.pdb')
149
- sys.argv = ['', afile]
150
-
151
- self.exec_module()
152
-
153
- self.assertEqual(self.retcode, 1) # exit code is 1 (error)
154
- self.assertEqual(len(self.stdout), 0) # nothing written to stdout
155
- self.assertEqual(self.stderr[0][:22],
156
- "ERROR!! File not found") # proper error message
157
-
158
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
159
- def test_file_missing(self):
160
- """$ pdb_fixinsert -A89"""
161
-
162
- sys.argv = ['', '-A89']
163
-
164
- self.exec_module()
165
-
166
- self.assertEqual(self.retcode, 1)
167
- self.assertEqual(len(self.stdout), 0) # no output
168
- self.assertEqual(self.stderr[0],
169
- "ERROR!! No data to process!")
170
-
171
- # @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
172
- # def test_helptext(self):
173
- # """$ pdb_fixinsert"""
174
-
175
- # sys.argv = ['']
176
-
177
- # self.exec_module()
178
-
179
- # self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
180
- # self.assertEqual(len(self.stdout), 0) # no output
181
- # self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
182
-
183
- def test_invalid_option(self):
184
- """$ pdb_fixinsert -A data/dummy_insertions.pdb"""
185
-
186
- sys.argv = ['', '-A', os.path.join(data_dir, 'dummy_insertions.pdb')]
187
-
188
- self.exec_module()
189
-
190
- self.assertEqual(self.retcode, 1)
191
- self.assertEqual(len(self.stdout), 0)
192
- self.assertEqual(self.stderr[0][:27],
193
- "ERROR!! Option invalid: 'A'")
194
-
195
- def test_invalid_option_2(self):
196
- """$ pdb_fixinsert -12A data/dummy_insertions.pdb"""
197
-
198
- sys.argv = ['', '-12A', os.path.join(data_dir, 'dummy_insertions.pdb')]
199
-
200
- self.exec_module()
201
-
202
- self.assertEqual(self.retcode, 1)
203
- self.assertEqual(len(self.stdout), 0)
204
- self.assertEqual(self.stderr[0][:39],
205
- "ERROR!! Option invalid: '12A'")
206
-
207
- def test_not_an_option(self):
208
- """$ pdb_fixinsert 20 data/dummy_insertions.pdb"""
209
-
210
- sys.argv = ['', '20', os.path.join(data_dir, 'dummy_insertions.pdb')]
211
-
212
- self.exec_module()
213
-
214
- self.assertEqual(self.retcode, 1)
215
- self.assertEqual(len(self.stdout), 0)
216
- self.assertEqual(self.stderr[0],
217
- "ERROR! First argument is not an option: '20'")
218
-
219
-
220
- if __name__ == '__main__':
221
- from config import test_dir
222
-
223
- mpath = os.path.abspath(os.path.join(test_dir, '..'))
224
- sys.path.insert(0, mpath) # so we load dev files before any installation
225
-
226
- unittest.main()
tests/test_pdb_delres.py DELETED
@@ -1,241 +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_delres`.
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_delres'
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_delres -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), 60)
68
- self.assertEqual(len(self.stderr), 0)
69
-
70
- def test_range_2(self):
71
- """$ pdb_delres -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), 25)
82
- self.assertEqual(len(self.stderr), 0)
83
-
84
- def test_range_3(self):
85
- """$ pdb_delres -:-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), 195)
96
- self.assertEqual(len(self.stderr), 0)
97
-
98
- def test_range_4(self):
99
- """$ pdb_delres -::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), 160)
110
- self.assertEqual(len(self.stderr), 0)
111
-
112
- def test_invalid_range_1(self):
113
- """$ pdb_delres --9998:: data/dummy.pdb"""
114
-
115
- # Simulate input
116
- sys.argv = ['', '--9998::', 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, 1)
123
- self.assertEqual(len(self.stdout), 0)
124
- self.assertEqual(self.stderr[0][:22],
125
- "ERROR!! Starting value")
126
-
127
- def test_invalid_range_2(self):
128
- """$ pdb_delres -:10000: data/dummy.pdb"""
129
-
130
- # Simulate input
131
- sys.argv = ['', '-:10000:', os.path.join(data_dir, 'dummy.pdb')]
132
-
133
- # Execute the script
134
- self.exec_module()
135
-
136
- # Validate results
137
- self.assertEqual(self.retcode, 1)
138
- self.assertEqual(len(self.stdout), 0)
139
- self.assertEqual(self.stderr[0][:22],
140
- "ERROR!! End value must")
141
-
142
- def test_invalid_range_3(self):
143
- """$ pdb_delres -::: data/dummy.pdb"""
144
-
145
- # Simulate input
146
- sys.argv = ['', '-:::', 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][:21],
155
- "ERROR!! Residue range")
156
-
157
- def test_invalid_range_4(self):
158
- """$ pdb_delres -5:1:: data/dummy.pdb"""
159
-
160
- # Simulate input
161
- sys.argv = ['', '-5:1::', os.path.join(data_dir, 'dummy.pdb')]
162
-
163
- # Execute the script
164
- self.exec_module()
165
-
166
- # Validate results
167
- self.assertEqual(self.retcode, 1)
168
- self.assertEqual(len(self.stdout), 0)
169
- self.assertEqual(self.stderr[0][:21],
170
- "ERROR!! Residue range")
171
-
172
- def test_file_not_found(self):
173
- """$ pdb_delres not_existing.pdb"""
174
-
175
- afile = os.path.join(data_dir, 'not_existing.pdb')
176
- sys.argv = ['', afile]
177
-
178
- self.exec_module()
179
-
180
- self.assertEqual(self.retcode, 1) # exit code is 1 (error)
181
- self.assertEqual(len(self.stdout), 0) # nothing written to stdout
182
- self.assertEqual(self.stderr[0][:22],
183
- "ERROR!! File not found") # proper error message
184
-
185
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
186
- def test_file_missing(self):
187
- """$ pdb_delres -1:10"""
188
-
189
- sys.argv = ['', '-1:10']
190
-
191
- self.exec_module()
192
-
193
- self.assertEqual(self.retcode, 1)
194
- self.assertEqual(len(self.stdout), 0) # no output
195
- self.assertEqual(self.stderr[0],
196
- "ERROR!! No data to process!")
197
-
198
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
199
- def test_helptext(self):
200
- """$ pdb_delres"""
201
-
202
- sys.argv = ['']
203
-
204
- self.exec_module()
205
-
206
- self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
207
- self.assertEqual(len(self.stdout), 0) # no output
208
- self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
209
-
210
- def test_invalid_option(self):
211
- """$ pdb_delres -A:B data/dummy.pdb"""
212
-
213
- sys.argv = ['', '-A:B', os.path.join(data_dir, 'dummy.pdb')]
214
-
215
- self.exec_module()
216
-
217
- self.assertEqual(self.retcode, 1)
218
- self.assertEqual(len(self.stdout), 0)
219
- self.assertEqual(self.stderr[0][:39],
220
- "ERROR!! Starting value must be numerica")
221
-
222
- def test_not_an_option(self):
223
- """$ pdb_delres 20 data/dummy.pdb"""
224
-
225
- sys.argv = ['', '20', os.path.join(data_dir, 'dummy.pdb')]
226
-
227
- self.exec_module()
228
-
229
- self.assertEqual(self.retcode, 1)
230
- self.assertEqual(len(self.stdout), 0)
231
- self.assertEqual(self.stderr[0],
232
- "ERROR! First argument is not an option: '20'")
233
-
234
-
235
- if __name__ == '__main__':
236
- from config import test_dir
237
-
238
- mpath = os.path.abspath(os.path.join(test_dir, '..'))
239
- sys.path.insert(0, mpath) # so we load dev files before any installation
240
-
241
- unittest.main()
@@ -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_delresname`.
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_delresname'
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_delresname -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), 128)
68
- self.assertEqual(len(self.stderr), 0)
69
-
70
- def test_multiple_sele(self):
71
- """$ pdb_delresname -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), 127)
82
- self.assertEqual(len(self.stderr), 0)
83
-
84
- def test_empty_sele(self):
85
- """$ pdb_delresname - 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_delresname -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_delresname 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_delresname -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_delresname"""
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_delresname 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()