2
MAP Client, a program to generate detailed musculoskeletal models for OpenSim.
3
Copyright (C) 2012 University of Auckland
5
This file is part of MAP Client. (http://launchpad.net/mapclient)
7
MAP Client is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
MAP Client is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with MAP Client. If not, see <http://www.gnu.org/licenses/>..
21
from PySide import QtGui
23
from tools.pluginwizard import wizarddialog
24
from tools.pluginwizard.skeleton import SkeletonOptions, Skeleton
26
if QtGui.qApp == None: QtGui.QApplication([])
27
import widgets.resources_rc
31
test_path = os.path.join(os.path.dirname(alltests.__file__), 'test_resources', 'wizard_test')
33
PLUGIN_WRITE_TO_DIRECTORY = test_path
34
PLUGIN_PACKAGE_NAME = 'abcdalphastep'
35
PLUGIN_NAME = 'Abcd Alpha'
36
PLUGIN_IMAGE_FILE = os.path.join(test_path, 'logo.png')
38
AUTHOR_NAME = 'Prince of Persia'
40
class WizardTestCase(unittest.TestCase):
43
def assertIn(self, a, b, *args, **kwargs):
44
''''Python < v2.7 compatibility. Assert "a" in "b"'''
46
f = super(WizardTestCase, self).assertIn
47
except AttributeError:
48
self.assertTrue(a in b, *args, **kwargs)
50
f(a, b, *args, **kwargs)
52
def assertNotIn(self, a, b, *args, **kwargs):
53
''''Python < v2.7 compatibility. Assert "a" NOT in "b"'''
55
f = super(WizardTestCase, self).assertNotIn
56
except AttributeError:
57
self.assertFalse(a in b, *args, **kwargs)
59
f(a, b, *args, **kwargs)
61
def _doCleanUp(self, package_name):
62
rmdir = os.path.join(PLUGIN_WRITE_TO_DIRECTORY, package_name)
63
if os.path.exists(rmdir):
65
for package_dir, _, files in os.walk(rmdir):
67
src_file = os.path.join(package_dir, file_)
70
directories.append(package_dir)
73
for directory in directories:
81
# def testRunWizard(self):
83
# Visual test for wizard, uncomment to manually test.
85
# dlg = wizarddialog.WizardDialog()
86
# result = dlg.exec_()
87
# self.assertTrue(result == dlg.Accepted or result == dlg.Rejected)
90
dlg = wizarddialog.WizardDialog()
93
p1._ui.nameLineEdit.setText(PLUGIN_NAME)
94
p1._ui.iconLineEdit.setText(PLUGIN_IMAGE_FILE)
96
p2._ui.portTableWidget.insertRow(0)
97
cb = QtGui.QComboBox()
98
cb.addItems(['provides', 'uses'])
99
p2._ui.portTableWidget.setCellWidget(0, 0, cb)
100
p2._ui.portTableWidget.setItem(0, 1, QtGui.QTableWidgetItem('http://my.example.org/1.0/workflowstep#octopus'))
102
p3._ui.configTableWidget.setItem(0, 1, QtGui.QTableWidgetItem('xxx'))
104
p4._ui.authorNameLineEdit.setText(AUTHOR_NAME)
105
p4._ui.categoryLineEdit.setText(CATEGORY)
107
p5._ui.directoryLineEdit.setText(PLUGIN_WRITE_TO_DIRECTORY)
111
options = dlg.getOptions()
112
self.assertEqual(PLUGIN_NAME, options.getName())
113
self.assertEqual(PLUGIN_IMAGE_FILE, options.getImageFile())
114
self.assertEqual(PLUGIN_PACKAGE_NAME, options.getPackageName())
115
self.assertEqual(PLUGIN_WRITE_TO_DIRECTORY, options.getOutputDirectory())
116
self.assertEqual(1, options.portCount())
117
self.assertEqual([u'http://physiomeproject.org/workflow/1.0/rdf-schema#provides', u'http://my.example.org/1.0/workflowstep#octopus'], options.getPort(0))
118
self.assertEqual(1, options.configCount())
119
self.assertEqual([u'identifier', u''], options.getConfig(0))
120
self.assertEqual(CATEGORY, options.getCategory())
121
self.assertEqual(AUTHOR_NAME, options.getAuthorName())
123
def testSkeleton1(self):
125
local_package_name = PLUGIN_PACKAGE_NAME.replace('step', str(1) + 'step')
127
options = SkeletonOptions()
128
options.setImageFile(PLUGIN_IMAGE_FILE)
129
options.setName(PLUGIN_NAME + str(1))
130
options.setPackageName(local_package_name)
131
options.setOutputDirectory(PLUGIN_WRITE_TO_DIRECTORY)
132
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'object')
133
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'http://my.example.org/1.0/workflowstep#octopus')
134
options.addConfig('identifier', '')
135
options.setAuthorName(AUTHOR_NAME)
136
options.setCategory(CATEGORY)
138
s = Skeleton(options)
141
package_dir = os.path.join(PLUGIN_WRITE_TO_DIRECTORY, local_package_name)
142
self.assertTrue(os.path.exists(package_dir))
143
package_init_file = os.path.join(package_dir, '__init__.py')
144
self.assertTrue(os.path.exists(package_init_file))
145
init_contents = open(package_init_file).read()
146
self.assertIn(AUTHOR_NAME, init_contents)
148
step_file = os.path.join(package_dir, local_package_name, 'step.py')
149
self.assertTrue(os.path.exists(step_file))
151
file_contents = open(step_file).read()
152
self.assertIn('octopus', file_contents)
153
self.assertIn('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', file_contents)
154
self.assertIn('return self._config[', file_contents)
155
self.assertIn('] = identifier', file_contents)
156
self.assertIn('self._category = \'' + CATEGORY + '\'', file_contents)
157
self.assertNotIn('{setidentifiercontent}', file_contents)
158
self.assertNotIn('{serializecontent}', file_contents)
159
self.assertNotIn('{serializesetvalues}', file_contents)
162
resources_file = os.path.join(package_dir, local_package_name, 'resources_rc.py')
163
self.assertTrue(os.path.exists(resources_file))
165
config_file = os.path.join(package_dir, local_package_name, 'configuredialog.py')
166
self.assertTrue(os.path.exists(config_file))
168
config_contents = open(config_file).read()
169
self.assertIn('validate', config_contents)
171
self._doCleanUp(local_package_name) # Move this to the start of the test if you want to see the output
173
def testSkeleton2(self):
175
local_package_name = PLUGIN_PACKAGE_NAME.replace('step', str(2) + 'step')
177
options = SkeletonOptions()
178
options.setImageFile(PLUGIN_IMAGE_FILE)
179
options.setName(PLUGIN_NAME + str(2))
180
options.setPackageName(local_package_name)
181
options.setOutputDirectory(PLUGIN_WRITE_TO_DIRECTORY)
182
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'object')
183
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'number')
184
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'http://my.example.org/1.0/workflowstep#octopus')
185
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'int')
187
s = Skeleton(options)
190
package_dir = os.path.join(PLUGIN_WRITE_TO_DIRECTORY, local_package_name)
191
self.assertTrue(os.path.exists(package_dir))
192
package_init_file = os.path.join(package_dir, '__init__.py')
193
self.assertTrue(os.path.exists(package_init_file))
194
step_file = os.path.join(package_dir, local_package_name, 'step.py')
195
self.assertTrue(os.path.exists(step_file))
197
file_contents = open(step_file).read()
198
self.assertIn('octopus', file_contents)
199
self.assertIn('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', file_contents)
200
self.assertIn('# TODO: The string must be replaced with', file_contents)
201
self.assertIn('# TODO: Must actually set the step', file_contents)
202
self.assertNotIn('{setidentifiercontent}', file_contents)
203
self.assertNotIn('{serializecontent}', file_contents)
204
self.assertNotIn('{serializesetvalues}', file_contents)
206
resources_file = os.path.join(package_dir, local_package_name, 'resources_rc.py')
207
self.assertTrue(os.path.exists(resources_file))
209
self._doCleanUp(local_package_name) # Move this to the start of the test if you want to see the output
211
def testSkeleton3(self):
213
local_package_name = PLUGIN_PACKAGE_NAME.replace('step', str(3) + 'step')
215
options = SkeletonOptions()
216
options.setImageFile(PLUGIN_IMAGE_FILE)
217
options.setName(PLUGIN_NAME + str(3))
218
options.setPackageName(local_package_name)
219
options.setOutputDirectory(PLUGIN_WRITE_TO_DIRECTORY)
220
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'object')
221
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'number')
222
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'http://my.example.org/1.0/workflowstep#octopus')
223
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'int')
224
options.addConfig('identifier', '')
225
options.addConfig('Cabbage', 'Brown')
226
options.addConfig('Path', '')
227
options.addConfig('Carrot', 'tis a long way down')
229
s = Skeleton(options)
232
package_dir = os.path.join(PLUGIN_WRITE_TO_DIRECTORY, local_package_name)
233
self.assertTrue(os.path.exists(package_dir))
234
package_init_file = os.path.join(package_dir, '__init__.py')
235
self.assertTrue(os.path.exists(package_init_file))
236
step_file = os.path.join(package_dir, local_package_name, 'step.py')
237
self.assertTrue(os.path.exists(step_file))
239
file_contents = open(step_file).read()
240
self.assertIn('octopus', file_contents)
241
self.assertIn('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', file_contents)
242
self.assertIn('Cabbage', file_contents)
243
self.assertIn('Carrot', file_contents)
244
self.assertNotIn('{setidentifiercontent}', file_contents)
245
self.assertNotIn('{serializecontent}', file_contents)
246
self.assertNotIn('{serializesetvalues}', file_contents)
248
resources_file = os.path.join(package_dir, local_package_name, 'resources_rc.py')
249
self.assertTrue(os.path.exists(resources_file))
251
config_file = os.path.join(package_dir, local_package_name, 'configuredialog.py')
252
self.assertTrue(os.path.exists(config_file))
254
self._doCleanUp(local_package_name) # Move this to the start of the test if you want to see the output
256
def testSkeleton4(self):
258
local_package_name = PLUGIN_PACKAGE_NAME.replace('step', str(4) + 'step')
260
options = SkeletonOptions()
261
options.setImageFile(PLUGIN_IMAGE_FILE)
262
options.setName(PLUGIN_NAME + str(4))
263
options.setPackageName(local_package_name)
264
options.setOutputDirectory(PLUGIN_WRITE_TO_DIRECTORY)
265
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'object')
266
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'number')
267
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', 'http://my.example.org/1.0/workflowstep#octopus')
268
options.addPort('http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'int')
269
options.addConfig('Cabbage', 'Brown')
270
options.addConfig('Path', '')
271
options.addConfig('Carrot', 'tis a long way down')
274
s = Skeleton(options)
277
package_dir = os.path.join(PLUGIN_WRITE_TO_DIRECTORY, local_package_name)
278
self.assertTrue(os.path.exists(package_dir))
279
package_init_file = os.path.join(package_dir, '__init__.py')
280
self.assertTrue(os.path.exists(package_init_file))
281
step_file = os.path.join(package_dir, local_package_name, 'step.py')
282
self.assertTrue(os.path.exists(step_file))
284
file_contents = open(step_file).read()
285
self.assertIn('octopus', file_contents)
286
self.assertIn('http://physiomeproject.org/workflow/1.0/rdf-schema#provides', file_contents)
287
self.assertIn('Cabbage', file_contents)
288
self.assertIn('Carrot', file_contents)
289
self.assertNotIn('{setidentifiercontent}', file_contents)
290
self.assertNotIn('{serializecontent}', file_contents)
291
self.assertNotIn('{serializesetvalues}', file_contents)
293
resources_file = os.path.join(package_dir, local_package_name, 'resources_rc.py')
294
self.assertTrue(os.path.exists(resources_file))
296
config_file = os.path.join(package_dir, local_package_name, 'configuredialog.py')
297
self.assertTrue(os.path.exists(config_file))
299
self._doCleanUp(local_package_name) # Move this to the start of the test if you want to see the output
302
if __name__ == "__main__":
303
# import sys;sys.argv = ['', 'Test.testName']