Merge lp:~knightrider0xd/openlp/preview-shows-live-fix-1080596 into lp:openlp
- preview-shows-live-fix-1080596
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 2661 |
Proposed branch: | lp:~knightrider0xd/openlp/preview-shows-live-fix-1080596 |
Merge into: | lp:openlp |
Diff against target: |
687 lines (+472/-19) 9 files modified
openlp/core/lib/__init__.py (+26/-2) openlp/core/lib/serviceitem.py (+2/-0) openlp/core/ui/lib/listpreviewwidget.py (+8/-6) openlp/core/ui/slidecontroller.py (+15/-3) openlp/plugins/presentations/lib/presentationcontroller.py (+2/-2) tests/functional/openlp_core_lib/test_lib.py (+190/-2) tests/functional/openlp_core_lib/test_serviceitem.py (+5/-2) tests/functional/openlp_core_ui/test_slidecontroller.py (+170/-1) tests/functional/openlp_core_ui_lib/test_listpreviewwidget.py (+54/-1) |
To merge this branch: | bzr merge lp:~knightrider0xd/openlp/preview-shows-live-fix-1080596 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Bentley | Approve | ||
Raoul Snyman | Approve | ||
Review via email: mp+294803@code.launchpad.net |
This proposal supersedes a proposal from 2016-05-06.
Commit message
Description of the change
Fixes bug 1080596 where presentations in the preview pane display live view rather than preview of selected slide.
In addition, fixes the aspect ratio & quality of thumbnails by saving them in the correct aspect ratio at a higher resolution, and loading them through the image manager.
New test cases implemented, or existing cases modified to test coverage complete for changes.
lp:~knightrider0xd/openlp/preview-shows-live-fix-1080596 (revision 2652)
[SUCCESS] https:/
[SUCCESS] https:/
Failing interface & coverage tests due to issue with unrelated crosswalk import module.
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal | # |
Raoul Snyman (raoul-snyman) wrote : | # |
Looks OK to me.
Tim Bentley (trb143) : | # |
Preview Diff
1 | === modified file 'openlp/core/lib/__init__.py' | |||
2 | --- openlp/core/lib/__init__.py 2016-04-23 19:28:52 +0000 | |||
3 | +++ openlp/core/lib/__init__.py 2016-05-16 12:42:11 +0000 | |||
4 | @@ -55,9 +55,13 @@ | |||
5 | 55 | 55 | ||
6 | 56 | ``Theme`` | 56 | ``Theme`` |
7 | 57 | This says, that the image is used by a theme. | 57 | This says, that the image is used by a theme. |
8 | 58 | |||
9 | 59 | ``CommandPlugins`` | ||
10 | 60 | This states that an image is being used by a command plugin. | ||
11 | 58 | """ | 61 | """ |
12 | 59 | ImagePlugin = 1 | 62 | ImagePlugin = 1 |
13 | 60 | Theme = 2 | 63 | Theme = 2 |
14 | 64 | CommandPlugins = 3 | ||
15 | 61 | 65 | ||
16 | 62 | 66 | ||
17 | 63 | class MediaType(object): | 67 | class MediaType(object): |
18 | @@ -174,10 +178,30 @@ | |||
19 | 174 | ext = os.path.splitext(thumb_path)[1].lower() | 178 | ext = os.path.splitext(thumb_path)[1].lower() |
20 | 175 | reader = QtGui.QImageReader(image_path) | 179 | reader = QtGui.QImageReader(image_path) |
21 | 176 | if size is None: | 180 | if size is None: |
23 | 177 | ratio = reader.size().width() / reader.size().height() | 181 | # No size given; use default height of 88 |
24 | 182 | if reader.size().isEmpty(): | ||
25 | 183 | ratio = 1 | ||
26 | 184 | else: | ||
27 | 185 | ratio = reader.size().width() / reader.size().height() | ||
28 | 178 | reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) | 186 | reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) |
30 | 179 | else: | 187 | elif size.isValid(): |
31 | 188 | # Complete size given | ||
32 | 180 | reader.setScaledSize(size) | 189 | reader.setScaledSize(size) |
33 | 190 | else: | ||
34 | 191 | # Invalid size given | ||
35 | 192 | if reader.size().isEmpty(): | ||
36 | 193 | ratio = 1 | ||
37 | 194 | else: | ||
38 | 195 | ratio = reader.size().width() / reader.size().height() | ||
39 | 196 | if size.width() >= 0: | ||
40 | 197 | # Valid width; scale height | ||
41 | 198 | reader.setScaledSize(QtCore.QSize(size.width(), int(size.width() / ratio))) | ||
42 | 199 | elif size.height() >= 0: | ||
43 | 200 | # Valid height; scale width | ||
44 | 201 | reader.setScaledSize(QtCore.QSize(int(ratio * size.height()), size.height())) | ||
45 | 202 | else: | ||
46 | 203 | # Invalid; use default height of 88 | ||
47 | 204 | reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) | ||
48 | 181 | thumb = reader.read() | 205 | thumb = reader.read() |
49 | 182 | thumb.save(thumb_path, ext[1:]) | 206 | thumb.save(thumb_path, ext[1:]) |
50 | 183 | if not return_icon: | 207 | if not return_icon: |
51 | 184 | 208 | ||
52 | === modified file 'openlp/core/lib/serviceitem.py' | |||
53 | --- openlp/core/lib/serviceitem.py 2016-02-14 17:53:16 +0000 | |||
54 | +++ openlp/core/lib/serviceitem.py 2016-05-16 12:42:11 +0000 | |||
55 | @@ -334,6 +334,8 @@ | |||
56 | 334 | file_location_hash, ntpath.basename(image)) | 334 | file_location_hash, ntpath.basename(image)) |
57 | 335 | self._raw_frames.append({'title': file_name, 'image': image, 'path': path, | 335 | self._raw_frames.append({'title': file_name, 'image': image, 'path': path, |
58 | 336 | 'display_title': display_title, 'notes': notes}) | 336 | 'display_title': display_title, 'notes': notes}) |
59 | 337 | if self.is_capable(ItemCapabilities.HasThumbnails): | ||
60 | 338 | self.image_manager.add_image(image, ImageSource.CommandPlugins, '#000000') | ||
61 | 337 | self._new_item() | 339 | self._new_item() |
62 | 338 | 340 | ||
63 | 339 | def get_service_repr(self, lite_save): | 341 | def get_service_repr(self, lite_save): |
64 | 340 | 342 | ||
65 | === modified file 'openlp/core/ui/lib/listpreviewwidget.py' | |||
66 | --- openlp/core/ui/lib/listpreviewwidget.py 2016-04-22 18:32:59 +0000 | |||
67 | +++ openlp/core/ui/lib/listpreviewwidget.py 2016-05-16 12:42:11 +0000 | |||
68 | @@ -27,7 +27,7 @@ | |||
69 | 27 | from PyQt5 import QtCore, QtGui, QtWidgets | 27 | from PyQt5 import QtCore, QtGui, QtWidgets |
70 | 28 | 28 | ||
71 | 29 | from openlp.core.common import RegistryProperties, Settings | 29 | from openlp.core.common import RegistryProperties, Settings |
73 | 30 | from openlp.core.lib import ImageSource, ServiceItem | 30 | from openlp.core.lib import ImageSource, ItemCapabilities, ServiceItem |
74 | 31 | 31 | ||
75 | 32 | 32 | ||
76 | 33 | class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): | 33 | class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): |
77 | @@ -152,14 +152,16 @@ | |||
78 | 152 | else: | 152 | else: |
79 | 153 | label.setScaledContents(True) | 153 | label.setScaledContents(True) |
80 | 154 | if self.service_item.is_command(): | 154 | if self.service_item.is_command(): |
84 | 155 | pixmap = QtGui.QPixmap(frame['image']) | 155 | if self.service_item.is_capable(ItemCapabilities.HasThumbnails): |
85 | 156 | pixmap.setDevicePixelRatio(label.devicePixelRatio()) | 156 | image = self.image_manager.get_image(frame['image'], ImageSource.CommandPlugins) |
86 | 157 | label.setPixmap(pixmap) | 157 | pixmap = QtGui.QPixmap.fromImage(image) |
87 | 158 | else: | ||
88 | 159 | pixmap = QtGui.QPixmap(frame['image']) | ||
89 | 158 | else: | 160 | else: |
90 | 159 | image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin) | 161 | image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin) |
91 | 160 | pixmap = QtGui.QPixmap.fromImage(image) | 162 | pixmap = QtGui.QPixmap.fromImage(image) |
94 | 161 | pixmap.setDevicePixelRatio(label.devicePixelRatio()) | 163 | pixmap.setDevicePixelRatio(label.devicePixelRatio()) |
95 | 162 | label.setPixmap(pixmap) | 164 | label.setPixmap(pixmap) |
96 | 163 | slide_height = width // self.screen_ratio | 165 | slide_height = width // self.screen_ratio |
97 | 164 | # Setup and validate row height cap if in use. | 166 | # Setup and validate row height cap if in use. |
98 | 165 | max_img_row_height = Settings().value('advanced/slide max height') | 167 | max_img_row_height = Settings().value('advanced/slide max height') |
99 | 166 | 168 | ||
100 | === modified file 'openlp/core/ui/slidecontroller.py' | |||
101 | --- openlp/core/ui/slidecontroller.py 2016-04-22 18:32:45 +0000 | |||
102 | +++ openlp/core/ui/slidecontroller.py 2016-05-16 12:42:11 +0000 | |||
103 | @@ -1135,9 +1135,21 @@ | |||
104 | 1135 | """ | 1135 | """ |
105 | 1136 | self.log_debug('update_preview %s ' % self.screens.current['primary']) | 1136 | self.log_debug('update_preview %s ' % self.screens.current['primary']) |
106 | 1137 | if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay): | 1137 | if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay): |
110 | 1138 | # Grab now, but try again in a couple of seconds if slide change is slow | 1138 | if self.is_live: |
111 | 1139 | QtCore.QTimer.singleShot(500, self.grab_maindisplay) | 1139 | # If live, grab screen-cap of main display now |
112 | 1140 | QtCore.QTimer.singleShot(2500, self.grab_maindisplay) | 1140 | QtCore.QTimer.singleShot(500, self.grab_maindisplay) |
113 | 1141 | # but take another in a couple of seconds in case slide change is slow | ||
114 | 1142 | QtCore.QTimer.singleShot(2500, self.grab_maindisplay) | ||
115 | 1143 | else: | ||
116 | 1144 | # If not live, use the slide's thumbnail/icon instead | ||
117 | 1145 | image_path = self.service_item.get_rendered_frame(self.selected_row) | ||
118 | 1146 | if self.service_item.is_capable(ItemCapabilities.HasThumbnails): | ||
119 | 1147 | image = self.image_manager.get_image(image_path, ImageSource.CommandPlugins) | ||
120 | 1148 | self.slide_image = QtGui.QPixmap.fromImage(image) | ||
121 | 1149 | else: | ||
122 | 1150 | self.slide_image = QtGui.QPixmap(image_path) | ||
123 | 1151 | self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) | ||
124 | 1152 | self.slide_preview.setPixmap(self.slide_image) | ||
125 | 1141 | else: | 1153 | else: |
126 | 1142 | self.slide_image = self.display.preview() | 1154 | self.slide_image = self.display.preview() |
127 | 1143 | self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) | 1155 | self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) |
128 | 1144 | 1156 | ||
129 | === modified file 'openlp/plugins/presentations/lib/presentationcontroller.py' | |||
130 | --- openlp/plugins/presentations/lib/presentationcontroller.py 2015-12-31 22:46:06 +0000 | |||
131 | +++ openlp/plugins/presentations/lib/presentationcontroller.py 2016-05-16 12:42:11 +0000 | |||
132 | @@ -242,13 +242,13 @@ | |||
133 | 242 | 242 | ||
134 | 243 | def convert_thumbnail(self, file, idx): | 243 | def convert_thumbnail(self, file, idx): |
135 | 244 | """ | 244 | """ |
137 | 245 | Convert the slide image the application made to a standard 320x240 .png image. | 245 | Convert the slide image the application made to a scaled 360px height .png image. |
138 | 246 | """ | 246 | """ |
139 | 247 | if self.check_thumbnails(): | 247 | if self.check_thumbnails(): |
140 | 248 | return | 248 | return |
141 | 249 | if os.path.isfile(file): | 249 | if os.path.isfile(file): |
142 | 250 | thumb_path = self.get_thumbnail_path(idx, False) | 250 | thumb_path = self.get_thumbnail_path(idx, False) |
144 | 251 | create_thumb(file, thumb_path, False, QtCore.QSize(320, 240)) | 251 | create_thumb(file, thumb_path, False, QtCore.QSize(-1, 360)) |
145 | 252 | 252 | ||
146 | 253 | def get_thumbnail_path(self, slide_no, check_exists): | 253 | def get_thumbnail_path(self, slide_no, check_exists): |
147 | 254 | """ | 254 | """ |
148 | 255 | 255 | ||
149 | === modified file 'tests/functional/openlp_core_lib/test_lib.py' | |||
150 | --- tests/functional/openlp_core_lib/test_lib.py 2015-12-31 22:46:06 +0000 | |||
151 | +++ tests/functional/openlp_core_lib/test_lib.py 2016-05-16 12:42:11 +0000 | |||
152 | @@ -250,7 +250,7 @@ | |||
153 | 250 | 250 | ||
154 | 251 | def create_thumb_with_size_test(self): | 251 | def create_thumb_with_size_test(self): |
155 | 252 | """ | 252 | """ |
157 | 253 | Test the create_thumb() function | 253 | Test the create_thumb() function with a given size. |
158 | 254 | """ | 254 | """ |
159 | 255 | # GIVEN: An image to create a thumb of. | 255 | # GIVEN: An image to create a thumb of. |
160 | 256 | image_path = os.path.join(TEST_PATH, 'church.jpg') | 256 | image_path = os.path.join(TEST_PATH, 'church.jpg') |
161 | @@ -270,7 +270,7 @@ | |||
162 | 270 | # WHEN: Create the thumb. | 270 | # WHEN: Create the thumb. |
163 | 271 | icon = create_thumb(image_path, thumb_path, size=thumb_size) | 271 | icon = create_thumb(image_path, thumb_path, size=thumb_size) |
164 | 272 | 272 | ||
166 | 273 | # THEN: Check if the thumb was created. | 273 | # THEN: Check if the thumb was created and scaled to the given size. |
167 | 274 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | 274 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') |
168 | 275 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | 275 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') |
169 | 276 | self.assertFalse(icon.isNull(), 'The icon should not be null') | 276 | self.assertFalse(icon.isNull(), 'The icon should not be null') |
170 | @@ -282,6 +282,194 @@ | |||
171 | 282 | except: | 282 | except: |
172 | 283 | pass | 283 | pass |
173 | 284 | 284 | ||
174 | 285 | def create_thumb_no_size_test(self): | ||
175 | 286 | """ | ||
176 | 287 | Test the create_thumb() function with no size specified. | ||
177 | 288 | """ | ||
178 | 289 | # GIVEN: An image to create a thumb of. | ||
179 | 290 | image_path = os.path.join(TEST_PATH, 'church.jpg') | ||
180 | 291 | thumb_path = os.path.join(TEST_PATH, 'church_thumb.jpg') | ||
181 | 292 | expected_size = QtCore.QSize(63, 88) | ||
182 | 293 | |||
183 | 294 | # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the | ||
184 | 295 | # last test. | ||
185 | 296 | try: | ||
186 | 297 | os.remove(thumb_path) | ||
187 | 298 | except: | ||
188 | 299 | pass | ||
189 | 300 | |||
190 | 301 | # Only continue when the thumb does not exist. | ||
191 | 302 | self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.') | ||
192 | 303 | |||
193 | 304 | # WHEN: Create the thumb. | ||
194 | 305 | icon = create_thumb(image_path, thumb_path) | ||
195 | 306 | |||
196 | 307 | # THEN: Check if the thumb was created, retaining its aspect ratio. | ||
197 | 308 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | ||
198 | 309 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
199 | 310 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
200 | 311 | self.assertEqual(expected_size, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
201 | 312 | |||
202 | 313 | # Remove the thumb so that the test actually tests if the thumb will be created. | ||
203 | 314 | try: | ||
204 | 315 | os.remove(thumb_path) | ||
205 | 316 | except: | ||
206 | 317 | pass | ||
207 | 318 | |||
208 | 319 | def create_thumb_invalid_size_test(self): | ||
209 | 320 | """ | ||
210 | 321 | Test the create_thumb() function with invalid size specified. | ||
211 | 322 | """ | ||
212 | 323 | # GIVEN: An image to create a thumb of. | ||
213 | 324 | image_path = os.path.join(TEST_PATH, 'church.jpg') | ||
214 | 325 | thumb_path = os.path.join(TEST_PATH, 'church_thumb.jpg') | ||
215 | 326 | thumb_size = QtCore.QSize(-1, -1) | ||
216 | 327 | expected_size = QtCore.QSize(63, 88) | ||
217 | 328 | |||
218 | 329 | # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the | ||
219 | 330 | # last test. | ||
220 | 331 | try: | ||
221 | 332 | os.remove(thumb_path) | ||
222 | 333 | except: | ||
223 | 334 | pass | ||
224 | 335 | |||
225 | 336 | # Only continue when the thumb does not exist. | ||
226 | 337 | self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.') | ||
227 | 338 | |||
228 | 339 | # WHEN: Create the thumb. | ||
229 | 340 | icon = create_thumb(image_path, thumb_path, size=thumb_size) | ||
230 | 341 | |||
231 | 342 | # THEN: Check if the thumb was created, retaining its aspect ratio. | ||
232 | 343 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | ||
233 | 344 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
234 | 345 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
235 | 346 | self.assertEqual(expected_size, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
236 | 347 | |||
237 | 348 | # Remove the thumb so that the test actually tests if the thumb will be created. | ||
238 | 349 | try: | ||
239 | 350 | os.remove(thumb_path) | ||
240 | 351 | except: | ||
241 | 352 | pass | ||
242 | 353 | |||
243 | 354 | def create_thumb_width_only_test(self): | ||
244 | 355 | """ | ||
245 | 356 | Test the create_thumb() function with a size of only width specified. | ||
246 | 357 | """ | ||
247 | 358 | # GIVEN: An image to create a thumb of. | ||
248 | 359 | image_path = os.path.join(TEST_PATH, 'church.jpg') | ||
249 | 360 | thumb_path = os.path.join(TEST_PATH, 'church_thumb.jpg') | ||
250 | 361 | thumb_size = QtCore.QSize(100, -1) | ||
251 | 362 | expected_size = QtCore.QSize(100, 137) | ||
252 | 363 | |||
253 | 364 | # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the | ||
254 | 365 | # last test. | ||
255 | 366 | try: | ||
256 | 367 | os.remove(thumb_path) | ||
257 | 368 | except: | ||
258 | 369 | pass | ||
259 | 370 | |||
260 | 371 | # Only continue when the thumb does not exist. | ||
261 | 372 | self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.') | ||
262 | 373 | |||
263 | 374 | # WHEN: Create the thumb. | ||
264 | 375 | icon = create_thumb(image_path, thumb_path, size=thumb_size) | ||
265 | 376 | |||
266 | 377 | # THEN: Check if the thumb was created, retaining its aspect ratio. | ||
267 | 378 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | ||
268 | 379 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
269 | 380 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
270 | 381 | self.assertEqual(expected_size, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
271 | 382 | |||
272 | 383 | # Remove the thumb so that the test actually tests if the thumb will be created. | ||
273 | 384 | try: | ||
274 | 385 | os.remove(thumb_path) | ||
275 | 386 | except: | ||
276 | 387 | pass | ||
277 | 388 | |||
278 | 389 | def create_thumb_height_only_test(self): | ||
279 | 390 | """ | ||
280 | 391 | Test the create_thumb() function with a size of only height specified. | ||
281 | 392 | """ | ||
282 | 393 | # GIVEN: An image to create a thumb of. | ||
283 | 394 | image_path = os.path.join(TEST_PATH, 'church.jpg') | ||
284 | 395 | thumb_path = os.path.join(TEST_PATH, 'church_thumb.jpg') | ||
285 | 396 | thumb_size = QtCore.QSize(-1, 100) | ||
286 | 397 | expected_size = QtCore.QSize(72, 100) | ||
287 | 398 | |||
288 | 399 | # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the | ||
289 | 400 | # last test. | ||
290 | 401 | try: | ||
291 | 402 | os.remove(thumb_path) | ||
292 | 403 | except: | ||
293 | 404 | pass | ||
294 | 405 | |||
295 | 406 | # Only continue when the thumb does not exist. | ||
296 | 407 | self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.') | ||
297 | 408 | |||
298 | 409 | # WHEN: Create the thumb. | ||
299 | 410 | icon = create_thumb(image_path, thumb_path, size=thumb_size) | ||
300 | 411 | |||
301 | 412 | # THEN: Check if the thumb was created, retaining its aspect ratio. | ||
302 | 413 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | ||
303 | 414 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
304 | 415 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
305 | 416 | self.assertEqual(expected_size, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
306 | 417 | |||
307 | 418 | # Remove the thumb so that the test actually tests if the thumb will be created. | ||
308 | 419 | try: | ||
309 | 420 | os.remove(thumb_path) | ||
310 | 421 | except: | ||
311 | 422 | pass | ||
312 | 423 | |||
313 | 424 | def create_thumb_empty_img_test(self): | ||
314 | 425 | """ | ||
315 | 426 | Test the create_thumb() function with a size of only height specified. | ||
316 | 427 | """ | ||
317 | 428 | # GIVEN: An image to create a thumb of. | ||
318 | 429 | image_path = os.path.join(TEST_PATH, 'church.jpg') | ||
319 | 430 | thumb_path = os.path.join(TEST_PATH, 'church_thumb.jpg') | ||
320 | 431 | thumb_size = QtCore.QSize(-1, 100) | ||
321 | 432 | expected_size_1 = QtCore.QSize(88, 88) | ||
322 | 433 | expected_size_2 = QtCore.QSize(100, 100) | ||
323 | 434 | |||
324 | 435 | |||
325 | 436 | # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the | ||
326 | 437 | # last test. | ||
327 | 438 | try: | ||
328 | 439 | os.remove(thumb_path) | ||
329 | 440 | except: | ||
330 | 441 | pass | ||
331 | 442 | |||
332 | 443 | # Only continue when the thumb does not exist. | ||
333 | 444 | self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.') | ||
334 | 445 | |||
335 | 446 | # WHEN: Create the thumb. | ||
336 | 447 | with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size: | ||
337 | 448 | mocked_size.return_value = QtCore.QSize(0, 0) | ||
338 | 449 | icon = create_thumb(image_path, thumb_path, size=None) | ||
339 | 450 | |||
340 | 451 | # THEN: Check if the thumb was created with aspect ratio of 1. | ||
341 | 452 | self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists') | ||
342 | 453 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
343 | 454 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
344 | 455 | self.assertEqual(expected_size_1, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
345 | 456 | |||
346 | 457 | # WHEN: Create the thumb. | ||
347 | 458 | with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size: | ||
348 | 459 | mocked_size.return_value = QtCore.QSize(0, 0) | ||
349 | 460 | icon = create_thumb(image_path, thumb_path, size=thumb_size) | ||
350 | 461 | |||
351 | 462 | # THEN: Check if the thumb was created with aspect ratio of 1. | ||
352 | 463 | self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') | ||
353 | 464 | self.assertFalse(icon.isNull(), 'The icon should not be null') | ||
354 | 465 | self.assertEqual(expected_size_2, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size') | ||
355 | 466 | |||
356 | 467 | # Remove the thumb so that the test actually tests if the thumb will be created. | ||
357 | 468 | try: | ||
358 | 469 | os.remove(thumb_path) | ||
359 | 470 | except: | ||
360 | 471 | pass | ||
361 | 472 | |||
362 | 285 | def check_item_selected_true_test(self): | 473 | def check_item_selected_true_test(self): |
363 | 286 | """ | 474 | """ |
364 | 287 | Test that the check_item_selected() function returns True when there are selected indexes | 475 | Test that the check_item_selected() function returns True when there are selected indexes |
365 | 288 | 476 | ||
366 | === modified file 'tests/functional/openlp_core_lib/test_serviceitem.py' | |||
367 | --- tests/functional/openlp_core_lib/test_serviceitem.py 2015-12-31 22:46:06 +0000 | |||
368 | +++ tests/functional/openlp_core_lib/test_serviceitem.py 2016-05-16 12:42:11 +0000 | |||
369 | @@ -244,14 +244,16 @@ | |||
370 | 244 | self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command') | 244 | self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command') |
371 | 245 | self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match') | 245 | self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match') |
372 | 246 | 246 | ||
373 | 247 | @patch(u'openlp.core.lib.serviceitem.ServiceItem.image_manager') | ||
374 | 247 | @patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path') | 248 | @patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path') |
376 | 248 | def add_from_command_for_a_presentation_thumb_test(self, mocked_get_section_data_path): | 249 | def add_from_command_for_a_presentation_thumb_test(self, mocked_get_section_data_path, mocked_image_manager): |
377 | 249 | """ | 250 | """ |
379 | 250 | Test the Service Item - adding a presentation, and updating the thumb path | 251 | Test the Service Item - adding a presentation, updating the thumb path & adding the thumb to image_manager |
380 | 251 | """ | 252 | """ |
381 | 252 | # GIVEN: A service item, a mocked AppLocation and presentation data | 253 | # GIVEN: A service item, a mocked AppLocation and presentation data |
382 | 253 | mocked_get_section_data_path.return_value = os.path.join('mocked', 'section', 'path') | 254 | mocked_get_section_data_path.return_value = os.path.join('mocked', 'section', 'path') |
383 | 254 | service_item = ServiceItem(None) | 255 | service_item = ServiceItem(None) |
384 | 256 | service_item.add_capability(ItemCapabilities.HasThumbnails) | ||
385 | 255 | service_item.has_original_files = False | 257 | service_item.has_original_files = False |
386 | 256 | service_item.name = 'presentations' | 258 | service_item.name = 'presentations' |
387 | 257 | presentation_name = 'test.pptx' | 259 | presentation_name = 'test.pptx' |
388 | @@ -270,6 +272,7 @@ | |||
389 | 270 | # THEN: verify that it is setup as a Command and that the frame data matches | 272 | # THEN: verify that it is setup as a Command and that the frame data matches |
390 | 271 | self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command') | 273 | self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command') |
391 | 272 | self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match') | 274 | self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match') |
392 | 275 | self.assertEqual(1, mocked_image_manager.add_image.call_count, 'image_manager should be used') | ||
393 | 273 | 276 | ||
394 | 274 | def service_item_load_optical_media_from_service_test(self): | 277 | def service_item_load_optical_media_from_service_test(self): |
395 | 275 | """ | 278 | """ |
396 | 276 | 279 | ||
397 | === modified file 'tests/functional/openlp_core_ui/test_slidecontroller.py' | |||
398 | --- tests/functional/openlp_core_ui/test_slidecontroller.py 2016-02-27 14:25:31 +0000 | |||
399 | +++ tests/functional/openlp_core_ui/test_slidecontroller.py 2016-05-16 12:42:11 +0000 | |||
400 | @@ -26,7 +26,7 @@ | |||
401 | 26 | 26 | ||
402 | 27 | from unittest import TestCase | 27 | from unittest import TestCase |
403 | 28 | from openlp.core import Registry | 28 | from openlp.core import Registry |
405 | 29 | from openlp.core.lib import ServiceItemAction | 29 | from openlp.core.lib import ImageSource, ServiceItemAction |
406 | 30 | from openlp.core.ui import SlideController, LiveController, PreviewController | 30 | from openlp.core.ui import SlideController, LiveController, PreviewController |
407 | 31 | from openlp.core.ui.slidecontroller import InfoLabel, WIDE_MENU, NON_TEXT_MENU | 31 | from openlp.core.ui.slidecontroller import InfoLabel, WIDE_MENU, NON_TEXT_MENU |
408 | 32 | 32 | ||
409 | @@ -713,6 +713,175 @@ | |||
410 | 713 | slide_controller.theme_screen, slide_controller.blank_screen | 713 | slide_controller.theme_screen, slide_controller.blank_screen |
411 | 714 | ]) | 714 | ]) |
412 | 715 | 715 | ||
413 | 716 | @patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager') | ||
414 | 717 | @patch(u'PyQt5.QtCore.QTimer.singleShot') | ||
415 | 718 | def update_preview_test_live(self, mocked_singleShot, mocked_image_manager): | ||
416 | 719 | """ | ||
417 | 720 | Test that the preview screen is updated with a screen grab for live service items | ||
418 | 721 | """ | ||
419 | 722 | # GIVEN: A mocked live service item, a mocked image_manager, a mocked Registry, | ||
420 | 723 | # and a slide controller with many mocks. | ||
421 | 724 | # Mocked Live Item | ||
422 | 725 | mocked_live_item = MagicMock() | ||
423 | 726 | mocked_live_item.get_rendered_frame.return_value = '' | ||
424 | 727 | mocked_live_item.is_capable = MagicMock() | ||
425 | 728 | mocked_live_item.is_capable.side_effect = [True, True] | ||
426 | 729 | # Mock image_manager | ||
427 | 730 | mocked_image_manager.get_image.return_value = QtGui.QImage() | ||
428 | 731 | # Mock Registry | ||
429 | 732 | Registry.create() | ||
430 | 733 | mocked_main_window = MagicMock() | ||
431 | 734 | Registry().register('main_window', mocked_main_window) | ||
432 | 735 | # Mock SlideController | ||
433 | 736 | slide_controller = SlideController(None) | ||
434 | 737 | slide_controller.service_item = mocked_live_item | ||
435 | 738 | slide_controller.is_live = True | ||
436 | 739 | slide_controller.log_debug = MagicMock() | ||
437 | 740 | slide_controller.selected_row = MagicMock() | ||
438 | 741 | slide_controller.screens = MagicMock() | ||
439 | 742 | slide_controller.screens.current = {'primary': ''} | ||
440 | 743 | slide_controller.display = MagicMock() | ||
441 | 744 | slide_controller.display.preview.return_value = QtGui.QImage() | ||
442 | 745 | slide_controller.grab_maindisplay = MagicMock() | ||
443 | 746 | slide_controller.slide_preview = MagicMock() | ||
444 | 747 | slide_controller.slide_count = 0 | ||
445 | 748 | |||
446 | 749 | # WHEN: update_preview is called | ||
447 | 750 | slide_controller.update_preview() | ||
448 | 751 | |||
449 | 752 | # THEN: A screen_grab should have been called | ||
450 | 753 | self.assertEqual(0, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should not be called') | ||
451 | 754 | self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called') | ||
452 | 755 | self.assertEqual(2, mocked_singleShot.call_count, | ||
453 | 756 | 'Timer to grab_maindisplay should have been called 2 times') | ||
454 | 757 | self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager not be called') | ||
455 | 758 | |||
456 | 759 | @patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager') | ||
457 | 760 | @patch(u'PyQt5.QtCore.QTimer.singleShot') | ||
458 | 761 | def update_preview_test_pres(self, mocked_singleShot, mocked_image_manager): | ||
459 | 762 | """ | ||
460 | 763 | Test that the preview screen is updated with the correct preview for presentation service items | ||
461 | 764 | """ | ||
462 | 765 | # GIVEN: A mocked presentation service item, a mocked image_manager, a mocked Registry, | ||
463 | 766 | # and a slide controller with many mocks. | ||
464 | 767 | # Mocked Presentation Item | ||
465 | 768 | mocked_pres_item = MagicMock() | ||
466 | 769 | mocked_pres_item.get_rendered_frame.return_value = '' | ||
467 | 770 | mocked_pres_item.is_capable = MagicMock() | ||
468 | 771 | mocked_pres_item.is_capable.side_effect = [True, True] | ||
469 | 772 | # Mock image_manager | ||
470 | 773 | mocked_image_manager.get_image.return_value = QtGui.QImage() | ||
471 | 774 | # Mock Registry | ||
472 | 775 | Registry.create() | ||
473 | 776 | mocked_main_window = MagicMock() | ||
474 | 777 | Registry().register('main_window', mocked_main_window) | ||
475 | 778 | # Mock SlideController | ||
476 | 779 | slide_controller = SlideController(None) | ||
477 | 780 | slide_controller.service_item = mocked_pres_item | ||
478 | 781 | slide_controller.is_live = False | ||
479 | 782 | slide_controller.log_debug = MagicMock() | ||
480 | 783 | slide_controller.selected_row = MagicMock() | ||
481 | 784 | slide_controller.screens = MagicMock() | ||
482 | 785 | slide_controller.screens.current = {'primary': ''} | ||
483 | 786 | slide_controller.display = MagicMock() | ||
484 | 787 | slide_controller.display.preview.return_value = QtGui.QImage() | ||
485 | 788 | slide_controller.grab_maindisplay = MagicMock() | ||
486 | 789 | slide_controller.slide_preview = MagicMock() | ||
487 | 790 | slide_controller.slide_count = 0 | ||
488 | 791 | |||
489 | 792 | # WHEN: update_preview is called | ||
490 | 793 | slide_controller.update_preview() | ||
491 | 794 | |||
492 | 795 | # THEN: setPixmap and the image_manager should have been called | ||
493 | 796 | self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called') | ||
494 | 797 | self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called') | ||
495 | 798 | self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called') | ||
496 | 799 | self.assertEqual(1, mocked_image_manager.get_image.call_count, 'image_manager should be called') | ||
497 | 800 | |||
498 | 801 | @patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager') | ||
499 | 802 | @patch(u'PyQt5.QtCore.QTimer.singleShot') | ||
500 | 803 | def update_preview_test_media(self, mocked_singleShot, mocked_image_manager): | ||
501 | 804 | """ | ||
502 | 805 | Test that the preview screen is updated with the correct preview for media service items | ||
503 | 806 | """ | ||
504 | 807 | # GIVEN: A mocked media service item, a mocked image_manager, a mocked Registry, | ||
505 | 808 | # and a slide controller with many mocks. | ||
506 | 809 | # Mocked Media Item | ||
507 | 810 | mocked_media_item = MagicMock() | ||
508 | 811 | mocked_media_item.get_rendered_frame.return_value = '' | ||
509 | 812 | mocked_media_item.is_capable = MagicMock() | ||
510 | 813 | mocked_media_item.is_capable.side_effect = [True, False] | ||
511 | 814 | # Mock image_manager | ||
512 | 815 | mocked_image_manager.get_image.return_value = QtGui.QImage() | ||
513 | 816 | # Mock Registry | ||
514 | 817 | Registry.create() | ||
515 | 818 | mocked_main_window = MagicMock() | ||
516 | 819 | Registry().register('main_window', mocked_main_window) | ||
517 | 820 | # Mock SlideController | ||
518 | 821 | slide_controller = SlideController(None) | ||
519 | 822 | slide_controller.service_item = mocked_media_item | ||
520 | 823 | slide_controller.is_live = False | ||
521 | 824 | slide_controller.log_debug = MagicMock() | ||
522 | 825 | slide_controller.selected_row = MagicMock() | ||
523 | 826 | slide_controller.screens = MagicMock() | ||
524 | 827 | slide_controller.screens.current = {'primary': ''} | ||
525 | 828 | slide_controller.display = MagicMock() | ||
526 | 829 | slide_controller.display.preview.return_value = QtGui.QImage() | ||
527 | 830 | slide_controller.grab_maindisplay = MagicMock() | ||
528 | 831 | slide_controller.slide_preview = MagicMock() | ||
529 | 832 | slide_controller.slide_count = 0 | ||
530 | 833 | |||
531 | 834 | # WHEN: update_preview is called | ||
532 | 835 | slide_controller.update_preview() | ||
533 | 836 | |||
534 | 837 | # THEN: setPixmap should have been called | ||
535 | 838 | self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called') | ||
536 | 839 | self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called') | ||
537 | 840 | self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called') | ||
538 | 841 | self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager should not be called') | ||
539 | 842 | |||
540 | 843 | @patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager') | ||
541 | 844 | @patch(u'PyQt5.QtCore.QTimer.singleShot') | ||
542 | 845 | def update_preview_test_image(self, mocked_singleShot, mocked_image_manager): | ||
543 | 846 | """ | ||
544 | 847 | Test that the preview screen is updated with the correct preview for image service items | ||
545 | 848 | """ | ||
546 | 849 | # GIVEN: A mocked image service item, a mocked image_manager, a mocked Registry, | ||
547 | 850 | # and a slide controller with many mocks. | ||
548 | 851 | # Mocked Image Item | ||
549 | 852 | mocked_img_item = MagicMock() | ||
550 | 853 | mocked_img_item.get_rendered_frame.return_value = '' | ||
551 | 854 | mocked_img_item.is_capable = MagicMock() | ||
552 | 855 | mocked_img_item.is_capable.side_effect = [False, True] | ||
553 | 856 | # Mock image_manager | ||
554 | 857 | mocked_image_manager.get_image.return_value = QtGui.QImage() | ||
555 | 858 | # Mock Registry | ||
556 | 859 | Registry.create() | ||
557 | 860 | mocked_main_window = MagicMock() | ||
558 | 861 | Registry().register('main_window', mocked_main_window) | ||
559 | 862 | # Mock SlideController | ||
560 | 863 | slide_controller = SlideController(None) | ||
561 | 864 | slide_controller.service_item = mocked_img_item | ||
562 | 865 | slide_controller.is_live = False | ||
563 | 866 | slide_controller.log_debug = MagicMock() | ||
564 | 867 | slide_controller.selected_row = MagicMock() | ||
565 | 868 | slide_controller.screens = MagicMock() | ||
566 | 869 | slide_controller.screens.current = {'primary': ''} | ||
567 | 870 | slide_controller.display = MagicMock() | ||
568 | 871 | slide_controller.display.preview.return_value = QtGui.QImage() | ||
569 | 872 | slide_controller.grab_maindisplay = MagicMock() | ||
570 | 873 | slide_controller.slide_preview = MagicMock() | ||
571 | 874 | slide_controller.slide_count = 0 | ||
572 | 875 | |||
573 | 876 | # WHEN: update_preview is called | ||
574 | 877 | slide_controller.update_preview() | ||
575 | 878 | |||
576 | 879 | # THEN: setPixmap and display.preview should have been called | ||
577 | 880 | self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called') | ||
578 | 881 | self.assertEqual(1, slide_controller.display.preview.call_count, 'display.preview() should be called') | ||
579 | 882 | self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called') | ||
580 | 883 | self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager should not be called') | ||
581 | 884 | |||
582 | 716 | 885 | ||
583 | 717 | class TestInfoLabel(TestCase): | 886 | class TestInfoLabel(TestCase): |
584 | 718 | 887 | ||
585 | 719 | 888 | ||
586 | === modified file 'tests/functional/openlp_core_ui_lib/test_listpreviewwidget.py' | |||
587 | --- tests/functional/openlp_core_ui_lib/test_listpreviewwidget.py 2016-04-22 18:35:23 +0000 | |||
588 | +++ tests/functional/openlp_core_ui_lib/test_listpreviewwidget.py 2016-05-16 12:42:11 +0000 | |||
589 | @@ -24,9 +24,11 @@ | |||
590 | 24 | """ | 24 | """ |
591 | 25 | from unittest import TestCase | 25 | from unittest import TestCase |
592 | 26 | 26 | ||
593 | 27 | from PyQt5 import QtGui | ||
594 | 28 | |||
595 | 27 | from openlp.core.common import Settings | 29 | from openlp.core.common import Settings |
596 | 28 | from openlp.core.ui.lib.listpreviewwidget import ListPreviewWidget | 30 | from openlp.core.ui.lib.listpreviewwidget import ListPreviewWidget |
598 | 29 | from openlp.core.lib import ServiceItem | 31 | from openlp.core.lib import ImageSource, ServiceItem |
599 | 30 | 32 | ||
600 | 31 | from tests.functional import MagicMock, patch, call | 33 | from tests.functional import MagicMock, patch, call |
601 | 32 | 34 | ||
602 | @@ -72,6 +74,53 @@ | |||
603 | 72 | self.assertIsNotNone(list_preview_widget, 'The ListPreviewWidget object should not be None') | 74 | self.assertIsNotNone(list_preview_widget, 'The ListPreviewWidget object should not be None') |
604 | 73 | self.assertEquals(list_preview_widget.screen_ratio, 1, 'Should not be called') | 75 | self.assertEquals(list_preview_widget.screen_ratio, 1, 'Should not be called') |
605 | 74 | 76 | ||
606 | 77 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.image_manager') | ||
607 | 78 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') | ||
608 | 79 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.setRowHeight') | ||
609 | 80 | def replace_service_item_test_thumbs(self, mocked_setRowHeight, mocked_resizeRowsToContents, | ||
610 | 81 | mocked_image_manager): | ||
611 | 82 | """ | ||
612 | 83 | Test that thubmails for different slides are loaded properly in replace_service_item. | ||
613 | 84 | """ | ||
614 | 85 | # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", | ||
615 | 86 | # different ServiceItem(s), an ImageManager, and a ListPreviewWidget. | ||
616 | 87 | |||
617 | 88 | # Mock Settings().value('advanced/slide max height') | ||
618 | 89 | self.mocked_Settings_obj.value.return_value = 0 | ||
619 | 90 | # Mock self.viewport().width() | ||
620 | 91 | self.mocked_viewport_obj.width.return_value = 200 | ||
621 | 92 | # Mock Image service item | ||
622 | 93 | mocked_img_service_item = MagicMock() | ||
623 | 94 | mocked_img_service_item.is_text.return_value = False | ||
624 | 95 | mocked_img_service_item.is_media.return_value = False | ||
625 | 96 | mocked_img_service_item.is_command.return_value = False | ||
626 | 97 | mocked_img_service_item.is_capable.return_value = False | ||
627 | 98 | mocked_img_service_item.get_frames.return_value = [{'title': None, 'path': 'TEST1', 'image': 'FAIL'}, | ||
628 | 99 | {'title': None, 'path': 'TEST2', 'image': 'FAIL'}] | ||
629 | 100 | # Mock Command service item | ||
630 | 101 | mocked_cmd_service_item = MagicMock() | ||
631 | 102 | mocked_cmd_service_item.is_text.return_value = False | ||
632 | 103 | mocked_cmd_service_item.is_media.return_value = False | ||
633 | 104 | mocked_cmd_service_item.is_command.return_value = True | ||
634 | 105 | mocked_cmd_service_item.is_capable.return_value = True | ||
635 | 106 | mocked_cmd_service_item.get_frames.return_value = [{'title': None, 'path': 'FAIL', 'image': 'TEST3'}, | ||
636 | 107 | {'title': None, 'path': 'FAIL', 'image': 'TEST4'}] | ||
637 | 108 | # Mock image_manager | ||
638 | 109 | mocked_image_manager.get_image.return_value = QtGui.QImage() | ||
639 | 110 | |||
640 | 111 | # init ListPreviewWidget and load service item | ||
641 | 112 | list_preview_widget = ListPreviewWidget(None, 1) | ||
642 | 113 | |||
643 | 114 | # WHEN: replace_service_item is called | ||
644 | 115 | list_preview_widget.replace_service_item(mocked_img_service_item, 200, 0) | ||
645 | 116 | list_preview_widget.replace_service_item(mocked_cmd_service_item, 200, 0) | ||
646 | 117 | |||
647 | 118 | # THEN: The ImageManager should be called in the appriopriate manner for each service item. | ||
648 | 119 | self.assertEquals(mocked_image_manager.get_image.call_count, 4, 'Should be called once for each slide') | ||
649 | 120 | calls = [call('TEST1', ImageSource.ImagePlugin), call('TEST2', ImageSource.ImagePlugin), | ||
650 | 121 | call('TEST3', ImageSource.CommandPlugins), call('TEST4', ImageSource.CommandPlugins)] | ||
651 | 122 | mocked_image_manager.get_image.assert_has_calls(calls) | ||
652 | 123 | |||
653 | 75 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') | 124 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
654 | 76 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.setRowHeight') | 125 | @patch(u'openlp.core.ui.lib.listpreviewwidget.ListPreviewWidget.setRowHeight') |
655 | 77 | def replace_recalculate_layout_test_text(self, mocked_setRowHeight, mocked_resizeRowsToContents): | 126 | def replace_recalculate_layout_test_text(self, mocked_setRowHeight, mocked_resizeRowsToContents): |
656 | @@ -120,6 +169,7 @@ | |||
657 | 120 | # Mock image service item | 169 | # Mock image service item |
658 | 121 | service_item = MagicMock() | 170 | service_item = MagicMock() |
659 | 122 | service_item.is_text.return_value = False | 171 | service_item.is_text.return_value = False |
660 | 172 | service_item.is_capable.return_value = False | ||
661 | 123 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, | 173 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
662 | 124 | {'title': None, 'path': None, 'image': None}] | 174 | {'title': None, 'path': None, 'image': None}] |
663 | 125 | # init ListPreviewWidget and load service item | 175 | # init ListPreviewWidget and load service item |
664 | @@ -156,6 +206,7 @@ | |||
665 | 156 | # Mock image service item | 206 | # Mock image service item |
666 | 157 | service_item = MagicMock() | 207 | service_item = MagicMock() |
667 | 158 | service_item.is_text.return_value = False | 208 | service_item.is_text.return_value = False |
668 | 209 | service_item.is_capable.return_value = False | ||
669 | 159 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, | 210 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
670 | 160 | {'title': None, 'path': None, 'image': None}] | 211 | {'title': None, 'path': None, 'image': None}] |
671 | 161 | # init ListPreviewWidget and load service item | 212 | # init ListPreviewWidget and load service item |
672 | @@ -225,6 +276,7 @@ | |||
673 | 225 | # Mock image service item | 276 | # Mock image service item |
674 | 226 | service_item = MagicMock() | 277 | service_item = MagicMock() |
675 | 227 | service_item.is_text.return_value = False | 278 | service_item.is_text.return_value = False |
676 | 279 | service_item.is_capable.return_value = False | ||
677 | 228 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, | 280 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
678 | 229 | {'title': None, 'path': None, 'image': None}] | 281 | {'title': None, 'path': None, 'image': None}] |
679 | 230 | # Mock self.cellWidget().children().setMaximumWidth() | 282 | # Mock self.cellWidget().children().setMaximumWidth() |
680 | @@ -261,6 +313,7 @@ | |||
681 | 261 | # Mock image service item | 313 | # Mock image service item |
682 | 262 | service_item = MagicMock() | 314 | service_item = MagicMock() |
683 | 263 | service_item.is_text.return_value = False | 315 | service_item.is_text.return_value = False |
684 | 316 | service_item.is_capable.return_value = False | ||
685 | 264 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, | 317 | service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
686 | 265 | {'title': None, 'path': None, 'image': None}] | 318 | {'title': None, 'path': None, 'image': None}] |
687 | 266 | # Mock self.cellWidget().children().setMaximumWidth() | 319 | # Mock self.cellWidget().children().setMaximumWidth() |
Just one clarification?