openlp/tests/interfaces/openlp_core_utils/test_utils.py

66 lines
1.8 KiB
Python

"""
Functional tests to test the AppLocation class and related methods.
"""
import os
from unittest import TestCase
from PyQt4 import QtCore, QtGui
from openlp.core.utils import is_not_image_file
from tests.utils.constants import TEST_RESOURCES_PATH
class TestUtils(TestCase):
"""
A test suite to test out various methods around the Utils functions.
"""
def setUp(self):
"""
Some pre-test setup required.
"""
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
def is_not_image_empty_test(self):
"""
Test the method handles an empty string
"""
# Given and empty string
file_name = ""
# WHEN testing for it
result = is_not_image_file(file_name)
# THEN the result is false
assert result is True, 'The missing file test should return True'
def is_not_image_with_image_file_test(self):
"""
Test the method handles an image file
"""
# Given and empty string
file_name = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')
# WHEN testing for it
result = is_not_image_file(file_name)
# THEN the result is false
assert result is False, 'The file is present so the test should return False'
def is_not_image_with_none_image_file_test(self):
"""
Test the method handles a non image file
"""
# Given and empty string
file_name = os.path.join(TEST_RESOURCES_PATH, 'serviceitem_custom_1.osj')
# WHEN testing for it
result = is_not_image_file(file_name)
# THEN the result is false
assert result is True, 'The file is not an image file so the test should return True'