13 # |
13 # |
14 # Description: |
14 # Description: |
15 # |
15 # |
16 |
16 |
17 import unittest |
17 import unittest |
18 import os, shutil |
18 import sys, os |
19 import sys |
|
20 import __init__ |
|
21 |
19 |
22 from imageplugin import imageml,generators |
20 from imageplugin import generators |
23 from cone.public import api, exceptions, plugin |
21 from cone.public import api, exceptions, plugin, utils |
24 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
22 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
25 |
23 |
26 def impl_from_resource(resource_ref, configuration): |
24 def impl_from_resource(resource_ref, configuration): |
27 impls = plugin.ImplFactory.get_impls_from_file(resource_ref, configuration) |
25 impls = plugin.ImplFactory.get_impls_from_file(resource_ref, configuration) |
28 assert len(impls) == 1 |
26 assert len(impls) == 1 |
119 command_obj = impl.generators[1].get_command() |
117 command_obj = impl.generators[1].get_command() |
120 cmd = command_obj.get_command(command_obj._get_filtered_input_files()) |
118 cmd = command_obj.get_command(command_obj._get_filtered_input_files()) |
121 self.assertEquals(len(cmd), 5) |
119 self.assertEquals(len(cmd), 5) |
122 self.assertEquals(cmd[3], '/c16') |
120 self.assertEquals(cmd[3], '/c16') |
123 self.assertEquals(cmd[4], r'conversion_workdir\icon.svg') |
121 self.assertEquals(cmd[4], r'conversion_workdir\icon.svg') |
|
122 |
|
123 def test_create_generator_with_extraparams(self): |
|
124 prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject"))) |
|
125 config = prj.get_configuration('product.confml') |
|
126 dview = config.get_default_view() |
|
127 impl = impl_from_resource('variant/implml/startupmif_animation_with_version.imageml', config) |
|
128 |
|
129 # 1st impl |
|
130 self.assertEquals(impl.generators[0].extraparams, '/V3') |
|
131 |
|
132 # Assert the the extraparams is actually used in the command |
|
133 command_obj = impl.generators[0].get_command() |
|
134 cmd = command_obj.get_command(command_obj._get_filtered_input_files()) |
|
135 self.assertEquals(len(cmd), 6) |
|
136 self.assertEquals(cmd[2], r'/V3') |
|
137 |
|
138 # 2nd impl |
|
139 self.assertEquals(impl.generators[1].extraparams, '${StartupSettings.PluginTimeout}') |
|
140 self.assertEquals(utils.expand_refs_by_default_view(impl.generators[1].extraparams, dview), '30000') |
|
141 |
|
142 # Assert the the extraparams is actually used in the command |
|
143 command_obj = impl.generators[1].get_command() |
|
144 cmd = command_obj.get_command(command_obj._get_filtered_input_files()) |
|
145 self.assertEquals(len(cmd), 6) |
|
146 self.assertEquals(cmd[2], r'30000') |
|
147 |
|
148 # 3rd impl |
|
149 self.assertEquals(impl.generators[2].extraparams, '${StartupSettings.PluginTimeout}') |
|
150 self.assertEquals(utils.expand_refs_by_default_view(impl.generators[1].extraparams, dview), '30000') |
|
151 |
|
152 # Assert the the extraparams is actually used in the command |
|
153 command_obj = impl.generators[2].get_command() |
|
154 cmd = command_obj.get_command(command_obj._get_filtered_input_files()) |
|
155 self.assertEquals(len(cmd), 4) |
|
156 self.assertEquals(cmd[1], r'30000') |
|
157 |
124 |
158 |
125 def test_create_generator_with_invalid_output(self): |
159 def test_create_generator_with_invalid_output(self): |
126 prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject"))) |
160 prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject"))) |
127 config = prj.get_configuration('product.confml') |
161 config = prj.get_configuration('product.confml') |
128 impl = impl_from_resource('variant/implml/startup_animation.imageml', config) |
162 impl = impl_from_resource('variant/implml/startup_animation.imageml', config) |
137 self.assertEquals(impl.generators[0].outputpath, '${KCRUidStartup.foobar}') |
171 self.assertEquals(impl.generators[0].outputpath, '${KCRUidStartup.foobar}') |
138 self.fail("Output path ref is invalid!") |
172 self.fail("Output path ref is invalid!") |
139 except exceptions.NotFound: |
173 except exceptions.NotFound: |
140 pass |
174 pass |
141 |
175 |
|
176 # Only run these tests on Windows |
|
177 if sys.platform != 'win32': |
|
178 del TestGenerator |
|
179 del TestInputFile |
|
180 del TestInputDir |
|
181 del TestGeneratorFromProject |
|
182 |
142 if __name__ == '__main__': |
183 if __name__ == '__main__': |
143 unittest.main() |
184 unittest.main() |