2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2013-12-24 08:56:50 +00:00
|
|
|
# Copyright (c) 2008-2014 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
2013-09-19 21:02:28 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2013-02-13 19:10:41 +00:00
|
|
|
"""
|
2013-09-19 21:02:28 +00:00
|
|
|
Package to test the openlp.core.ui package.
|
2013-02-13 19:10:41 +00:00
|
|
|
"""
|
|
|
|
import os
|
|
|
|
|
2013-09-08 10:30:14 +00:00
|
|
|
from unittest import TestCase
|
2013-09-19 21:02:28 +00:00
|
|
|
from PyQt4 import QtGui
|
2013-02-13 19:10:41 +00:00
|
|
|
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.common import Registry
|
|
|
|
from openlp.core.lib import ImageManager, ScreenList
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-02-16 06:51:25 +00:00
|
|
|
|
2013-08-31 18:17:38 +00:00
|
|
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
|
2013-02-13 19:10:41 +00:00
|
|
|
|
2013-02-13 19:22:43 +00:00
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestImageManager(TestCase, TestMixin):
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2014-03-14 22:08:44 +00:00
|
|
|
self.get_application()
|
2013-02-13 19:10:41 +00:00
|
|
|
ScreenList.create(self.app.desktop())
|
|
|
|
self.image_manager = ImageManager()
|
|
|
|
|
2013-02-16 15:02:19 +00:00
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
|
|
|
del self.app
|
|
|
|
|
2013-02-13 19:10:41 +00:00
|
|
|
def basic_image_manager_test(self):
|
|
|
|
"""
|
|
|
|
Test the Image Manager setup basic functionality
|
|
|
|
"""
|
|
|
|
# GIVEN: the an image add to the image manager
|
2013-08-31 18:17:38 +00:00
|
|
|
self.image_manager.add_image(TEST_PATH, 'church.jpg', None)
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
# WHEN the image is retrieved
|
2013-08-31 18:17:38 +00:00
|
|
|
image = self.image_manager.get_image(TEST_PATH, 'church.jpg')
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
# THEN returned record is a type of image
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(isinstance(image, QtGui.QImage), True, 'The returned object should be a QImage')
|
2013-02-13 19:10:41 +00:00
|
|
|
|
2013-03-12 08:19:47 +00:00
|
|
|
# WHEN: The image bytes are requested.
|
2013-08-31 18:17:38 +00:00
|
|
|
byte_array = self.image_manager.get_image_bytes(TEST_PATH, 'church.jpg')
|
2013-03-12 08:19:47 +00:00
|
|
|
|
2013-04-20 18:05:01 +00:00
|
|
|
# THEN: Type should be a str.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(isinstance(byte_array, str), True, 'The returned object should be a str')
|
2013-03-12 08:19:47 +00:00
|
|
|
|
2013-02-13 19:10:41 +00:00
|
|
|
# WHEN the image is retrieved has not been loaded
|
|
|
|
# THEN a KeyError is thrown
|
|
|
|
with self.assertRaises(KeyError) as context:
|
2013-08-31 18:17:38 +00:00
|
|
|
self.image_manager.get_image(TEST_PATH, 'church1.jpg')
|
|
|
|
self.assertNotEquals(context.exception, '', 'KeyError exception should have been thrown for missing image')
|