2019-11-26 17:49:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
2019-11-26 17:49:41 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
|
|
|
"""
|
|
|
|
All the tests
|
|
|
|
"""
|
|
|
|
import os
|
2020-01-04 21:24:32 +00:00
|
|
|
import sys
|
2019-11-26 17:49:41 +00:00
|
|
|
from tempfile import mkstemp
|
2019-12-04 20:01:02 +00:00
|
|
|
from unittest.mock import MagicMock
|
2019-11-26 17:49:41 +00:00
|
|
|
|
|
|
|
import pytest
|
2020-01-04 21:24:32 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets # noqa
|
|
|
|
sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock()
|
2019-11-26 17:49:41 +00:00
|
|
|
|
2020-01-04 21:24:32 +00:00
|
|
|
from openlp.core.app import OpenLP
|
2020-01-18 21:00:13 +00:00
|
|
|
from openlp.core.state import State
|
2019-11-26 17:49:41 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
|
|
|
from openlp.core.common.settings import Settings
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.yield_fixture
|
|
|
|
def qapp():
|
|
|
|
"""An instance of QApplication"""
|
2020-01-04 21:24:32 +00:00
|
|
|
app = OpenLP()
|
|
|
|
yield app
|
|
|
|
del app
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.yield_fixture
|
|
|
|
def mocked_qapp():
|
|
|
|
"""A mocked instance of QApplication"""
|
|
|
|
app = MagicMock()
|
2019-11-26 17:49:41 +00:00
|
|
|
yield app
|
|
|
|
del app
|
|
|
|
|
|
|
|
|
2019-12-04 20:01:02 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def registry():
|
|
|
|
"""An instance of the Registry"""
|
|
|
|
Registry.create()
|
|
|
|
|
|
|
|
|
2019-11-26 17:49:41 +00:00
|
|
|
@pytest.yield_fixture
|
2019-12-04 20:01:02 +00:00
|
|
|
def settings(qapp, registry):
|
2019-11-26 17:49:41 +00:00
|
|
|
"""A Settings() instance"""
|
|
|
|
fd, ini_file = mkstemp('.ini')
|
|
|
|
Settings.set_filename(ini_file)
|
|
|
|
Settings().setDefaultFormat(QtCore.QSettings.IniFormat)
|
|
|
|
# Needed on windows to make sure a Settings object is available during the tests
|
|
|
|
sets = Settings()
|
|
|
|
sets.setValue('themes/global theme', 'my_theme')
|
2019-12-04 20:01:02 +00:00
|
|
|
Registry().register('settings', sets)
|
2019-11-26 17:49:41 +00:00
|
|
|
yield sets
|
|
|
|
del sets
|
|
|
|
os.close(fd)
|
|
|
|
os.unlink(Settings().fileName())
|
|
|
|
|
|
|
|
|
2019-12-04 20:01:02 +00:00
|
|
|
@pytest.yield_fixture
|
|
|
|
def mock_settings(registry):
|
|
|
|
"""A Mock Settings() instance"""
|
|
|
|
# Create and register a mock settings object to work with
|
|
|
|
mock_settings = MagicMock()
|
|
|
|
Registry().register('settings', mock_settings)
|
|
|
|
yield mock_settings
|
|
|
|
Registry().remove('settings')
|
|
|
|
del mock_settings
|
2020-01-18 21:00:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def state():
|
|
|
|
State().load_settings()
|