Merge branch 'settings_1a' into 'master'

Migrate Settings - Part 1

See merge request openlp/openlp!84
This commit is contained in:
Raoul Snyman 2019-11-26 17:49:42 +00:00
commit f8e499eaf2
9 changed files with 1020 additions and 1029 deletions

View File

@ -400,6 +400,9 @@ def main():
Registry.create()
Registry().register('application', application)
Registry().set_flag('no_web_server', args.no_web_server)
# Upgrade settings.
settings = Settings()
Registry().register('settings', settings)
application.setApplicationVersion(get_version()['version'])
# Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one
server = Server()
@ -414,8 +417,6 @@ def main():
if application.is_data_path_missing():
server.close_server()
sys.exit()
# Upgrade settings.
settings = Settings()
if settings.can_upgrade():
now = datetime.now()
# Only back up if OpenLP has previously run.
@ -435,7 +436,7 @@ def main():
translate('OpenLP', 'Settings back up failed.\n\nContinuing to upgrade.'))
settings.upgrade_settings()
# First time checks in settings
if not Settings().value('core/has run wizard'):
if not settings.value('core/has run wizard'):
if not FirstTimeLanguageForm().exec():
# if cancel then stop processing
server.close_server()

View File

@ -125,6 +125,7 @@ class RegistryProperties(object):
_settings_form = None
_alerts_manager = None
_projector_manager = None
_settings = None
@property
def application(self):
@ -246,3 +247,12 @@ class RegistryProperties(object):
if not hasattr(self, '_projector_manager') or not self._projector_manager:
self._projector_manager = Registry().get('projector_manager')
return self._projector_manager
@property
def settings(self):
"""
Adds the projector manager to the class dynamically
"""
if not hasattr(self, '_settings') or not self._settings:
self._settings = Registry().get('settings')
return self._settings

View File

@ -37,7 +37,6 @@ from openlp.core.api.http import register_endpoint
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.lib.serviceitem import ItemCapabilities
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui import DisplayControllerType
@ -64,7 +63,6 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
self.live_timer.setInterval(TICK_TIME)
self.preview_timer = QtCore.QTimer()
self.preview_timer.setInterval(TICK_TIME)
self.settings = Settings()
# Signals
self.live_timer.timeout.connect(self.media_state_live)
self.preview_timer.timeout.connect(self.media_state_preview)

View File

@ -131,7 +131,7 @@ class BibleMediaItem(MediaManagerItem):
self.bibles_go_live.connect(self.go_live_remote)
self.bibles_add_to_service.connect(self.add_to_service_remote)
# Place to store the search results for both bibles.
self.settings = self.plugin.settings_tab
self.settings_tab = self.plugin.settings_tab
self.quick_preview_allowed = True
self.has_search = True
self.search_results = []
@ -557,8 +557,8 @@ class BibleMediaItem(MediaManagerItem):
:return: None
"""
# TODO: Change layout_style to a property
self.settings.layout_style = index
self.settings.layout_style_combo_box.setCurrentIndex(index)
self.settings_tab.layout_style = index
self.settings_tab.layout_style_combo_box.setCurrentIndex(index)
Settings().setValue('{section}/verse layout style'.format(section=self.settings_section), index)
def on_version_combo_box_index_changed(self):
@ -945,12 +945,12 @@ class BibleMediaItem(MediaManagerItem):
raw_slides.append(bible_text.rstrip())
bible_text = ''
# If we are 'Verse Per Slide' then create a new slide.
elif self.settings.layout_style == LayoutStyle.VersePerSlide:
elif self.settings_tab.layout_style == LayoutStyle.VersePerSlide:
bible_text = '{first_version}{data[text]}'.format(first_version=verse_text, data=data)
raw_slides.append(bible_text.rstrip())
bible_text = ''
# If we are 'Verse Per Line' then force a new line.
elif self.settings.layout_style == LayoutStyle.VersePerLine:
elif self.settings_tab.layout_style == LayoutStyle.VersePerLine:
bible_text = '{bible} {verse}{data[text]}\n'.format(bible=bible_text, verse=verse_text, data=data)
# We have to be 'Continuous'.
else:
@ -966,7 +966,7 @@ class BibleMediaItem(MediaManagerItem):
if bible_text:
raw_slides.append(bible_text.lstrip())
# Service Item: Capabilities
if self.settings.layout_style == LayoutStyle.Continuous and not data['second_bible']:
if self.settings_tab.layout_style == LayoutStyle.Continuous and not data['second_bible']:
# Split the line but do not replace line breaks in renderer.
service_item.add_capability(ItemCapabilities.NoLineBreaks)
service_item.add_capability(ItemCapabilities.CanPreview)
@ -976,8 +976,8 @@ class BibleMediaItem(MediaManagerItem):
# Service Item: Title
service_item.title = '{verse} {version}'.format(verse=verses.format_verses(), version=verses.format_versions())
# Service Item: Theme
if self.settings.bible_theme:
service_item.theme = self.settings.bible_theme
if self.settings_tab.bible_theme:
service_item.theme = self.settings_tab.bible_theme
for slide in raw_slides:
service_item.add_from_text(slide)
return True
@ -994,10 +994,10 @@ class BibleMediaItem(MediaManagerItem):
:param verse: The verse number (int).
:return: An empty or formatted string
"""
if not self.settings.is_verse_number_visible:
if not self.settings_tab.is_verse_number_visible:
return ''
verse_separator = get_reference_separators()['verse']
if not self.settings.show_new_chapters or old_chapter != chapter:
if not self.settings_tab.show_new_chapters or old_chapter != chapter:
verse_text = '{chapter}{sep}{verse}'.format(chapter=chapter, sep=verse_separator, verse=verse)
else:
verse_text = verse
@ -1006,7 +1006,7 @@ class BibleMediaItem(MediaManagerItem):
DisplayStyle.Round: ('(', ')'),
DisplayStyle.Curly: ('{', '}'),
DisplayStyle.Square: ('[', ']')
}[self.settings.display_style]
}[self.settings_tab.display_style]
return '{{su}}{bracket[0]}{verse_text}{bracket[1]}{{/su}} '.format(verse_text=verse_text, bracket=bracket)
def search(self, string, show_error=True):

62
tests/conftest.py Normal file
View File

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 OpenLP Developers #
# ---------------------------------------------------------------------- #
# 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
from tempfile import mkstemp
import pytest
from PyQt5 import QtCore, QtWidgets
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
@pytest.yield_fixture
def qapp():
"""An instance of QApplication"""
app = QtWidgets.QApplication([])
yield app
del app
@pytest.yield_fixture
def settings(qapp):
"""A Settings() instance"""
fd, ini_file = mkstemp('.ini')
Settings.set_filename(ini_file)
Registry.create()
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')
Registry().register('settings', set)
yield sets
del sets
os.close(fd)
os.unlink(Settings().fileName())
@pytest.fixture
def registry():
"""An instance of the Registry"""
Registry.create()

View File

@ -19,6 +19,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import sys
from unittest import TestCase, skip
from unittest.mock import MagicMock, patch
@ -157,6 +158,8 @@ def test_parse_options_file_and_debug():
assert args.rargs == ['dummy_temp'], 'The service file should not be blank'
# Problem seems to be with the what the OpenLP object is defined.
# Running each test on its own is fine but as a block you get seg faults in strange places.
@skip('Figure out why this is causing a segfault')
class TestOpenLP(TestCase):
"""

View File

@ -21,104 +21,10 @@
"""
Package to test the openlp.core.ui package.
"""
from unittest import TestCase, skip
from unittest.mock import patch
from PyQt5 import QtCore
from openlp.core.ui.media import parse_optical_path
from tests.helpers.testmixin import TestMixin
class TestMedia(TestCase, TestMixin):
@skip
def test_get_media_players_no_config(self):
"""
Test that when there's no config, get_media_players() returns an empty list of players (not a string)
"""
def value_results(key):
if key == 'media/players':
return ''
else:
return False
# GIVEN: A mocked out Settings() object
with patch('openlp.core.ui.media.Settings.value') as mocked_value:
mocked_value.side_effect = value_results
# WHEN: get_media_players() is called
used_players, overridden_player = 'vlc'
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
assert [] == used_players, 'Used players should be an empty list'
assert '' == overridden_player, 'Overridden player should be an empty string'
@skip
def test_get_media_players_no_players(self):
"""
Test that when there's no players but overridden player is set, get_media_players() returns 'auto'
"""
def value_results(key):
if key == 'media/override player':
return QtCore.Qt.Checked
else:
return ''
# GIVEN: A mocked out Settings() object
with patch('openlp.core.ui.media.Settings.value') as mocked_value:
mocked_value.side_effect = value_results
# WHEN: get_media_players() is called
used_players, overridden_player = 'vlc'
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
assert [] == used_players, 'Used players should be an empty list'
assert 'auto' == overridden_player, 'Overridden player should be "auto"'
@skip
def test_get_media_players_with_valid_list(self):
"""
Test that when get_media_players() is called the string list is interpreted correctly
"""
def value_results(key):
if key == 'media/players':
return '[vlc]'
else:
return False
# GIVEN: A mocked out Settings() object
with patch('openlp.core.ui.media.Settings.value') as mocked_value:
mocked_value.side_effect = value_results
# WHEN: get_media_players() is called
used_players = 'vlc'
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
assert ['vlc', 'webkit', 'system'] == used_players, 'Used players should be correct'
@skip
def test_get_media_players_with_overridden_player(self):
"""
Test that when get_media_players() is called the overridden player is correctly set
"""
def value_results(key):
if key == 'media/players':
return '[vlc]'
else:
return QtCore.Qt.Checked
# GIVEN: A mocked out Settings() object
with patch('openlp.core.ui.media.Settings.value') as mocked_value:
mocked_value.side_effect = value_results
# WHEN: get_media_players() is called
used_players = 'vlc'
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
assert ['vlc'] == used_players, 'Used players should be correct'
def test_parse_optical_path_linux(self):
def test_parse_optical_path_linux():
"""
Test that test_parse_optical_path() parses a optical path with linux device path correctly
"""
@ -146,7 +52,8 @@ class TestMedia(TestCase, TestMixin):
assert org_name == name, 'Returned end should match the original'
assert org_device_path == device_path, 'Returned device_path should match the original'
def test_parse_optical_path_win(self):
def test_parse_optical_path_win():
"""
Test that test_parse_optical_path() parses a optical path with windows device path correctly
"""

View File

@ -23,50 +23,30 @@ Package to test the openlp.core.ui.media.vlcplayer package.
"""
import os
import sys
import pytest
from datetime import timedelta
from unittest import TestCase, skip
from unittest.mock import MagicMock, call, patch
from openlp.core.common.registry import Registry
from openlp.core.ui.media import ItemMediaInfo, MediaState, MediaType
from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
from tests.helpers import MockDateTime
from tests.helpers.testmixin import TestMixin
class TestVLCPlayer(TestCase, TestMixin):
"""
Test the functions in the :mod:`vlcplayer` module.
"""
def setUp(self):
"""
Common setup for all the tests
"""
@pytest.yield_fixture
def vlc_env():
"""An instance of OpenLP"""
if 'VLC_PLUGIN_PATH' in os.environ:
del os.environ['VLC_PLUGIN_PATH']
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
del sys.modules['openlp.core.ui.media.vendor.vlc']
yield
MockDateTime.revert()
@skip('No way to test this')
@patch('openlp.core.ui.media.vlcplayer.vlc')
def test_get_vlc_fails_and_removes_module(self, mocked_vlc):
"""
Test that when the VLC import fails, it removes the module from sys.modules
"""
# GIVEN: We're on OS X and we don't have the VLC plugin path set
mocked_vlc.Instance.side_effect = NameError
mocked_vlc.libvlc_get_version.return_value = b'0.0.0'
# WHEN: An checking if the player is available
get_vlc()
# THEN: The extra environment variable should be there
assert 'openlp.core.ui.media.vendor.vlc' not in sys.modules
@patch.dict(os.environ)
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
def test_not_osx_fix_vlc_22_plugin_path(self, mocked_is_macosx):
@patch.dict(os.environ)
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
def test_not_osx_fix_vlc_22_plugin_path(mocked_is_macosx):
"""
Test that on Linux or some other non-OS X we do not set the VLC plugin path
"""
@ -79,7 +59,8 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The extra environment variable should NOT be there
assert 'VLC_PLUGIN_PATH' not in os.environ, 'The plugin path should NOT be in the environment variables'
def test_init(self):
def test_init():
"""
Test that the VLC player class initialises correctly
"""
@ -95,12 +76,13 @@ class TestVLCPlayer(TestCase, TestMixin):
assert vlc_player.parent is None
assert vlc_player.can_folder is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup(self, MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup(MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
"""
Test the setup method
"""
@ -145,12 +127,13 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_media_player_new.set_xwindow.assert_called_with(2)
assert vlc_player.has_own_widget is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_has_audio(self, MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_has_audio(MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
"""
Test the setup method when has_audio is True
"""
@ -182,13 +165,13 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The VLC instance should be created with the correct options
mocked_vlc.Instance.assert_called_with('--no-video-title-show ')
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_visible_mouse(self, MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx,
mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_visible_mouse(MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
"""
Test the setup method when Settings().value("hide mouse") is False
"""
@ -220,12 +203,13 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The VLC instance should be created with the correct options
mocked_vlc.Instance.assert_called_with('--no-video-title-show ')
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_windows(self, MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_windows(MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
"""
Test the setup method when running on Windows
"""
@ -257,12 +241,13 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: set_hwnd should be called
mocked_media_player_new.set_hwnd.assert_called_with(2)
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_osx(self, MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.QtWidgets')
@patch('openlp.core.ui.media.vlcplayer.Settings')
def test_setup_osx(MockedSettings, MockedQtWidgets, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
"""
Test the setup method when running on OS X
"""
@ -294,8 +279,9 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: set_nsobject should be called
mocked_media_player_new.set_nsobject.assert_called_with(2)
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_check_available(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_check_available(mocked_get_vlc):
"""
Check that when the "vlc" module is available, then VLC is set as available
"""
@ -309,8 +295,9 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: VLC should be available
assert is_available is True
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_check_not_available(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_check_not_available(mocked_get_vlc):
"""
Check that when the "vlc" module is not available, then VLC is set as unavailable
"""
@ -324,9 +311,10 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: VLC should NOT be available
assert is_available is False
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load(self, mocked_normcase, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load(mocked_normcase, mocked_get_vlc):
"""
Test loading a video into VLC
"""
@ -360,10 +348,11 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_volume.assert_called_with(mocked_controller, 100)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd(self, mocked_normcase, mocked_get_vlc, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd(mocked_normcase, mocked_get_vlc, mocked_is_win):
"""
Test loading an audio CD into VLC
"""
@ -403,10 +392,11 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_volume.assert_called_with(mocked_controller, 100)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd_on_windows(self, mocked_normcase, mocked_get_vlc, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd_on_windows(mocked_normcase, mocked_get_vlc, mocked_is_win):
"""
Test loading an audio CD into VLC on Windows
"""
@ -447,10 +437,11 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_volume.assert_called_with(mocked_controller, 100)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd_no_tracks(self, mocked_normcase, mocked_get_vlc, mocked_is_win):
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
def test_load_audio_cd_no_tracks(mocked_normcase, mocked_get_vlc, mocked_is_win):
"""
Test loading an audio CD that has no tracks into VLC
"""
@ -493,9 +484,10 @@ class TestVLCPlayer(TestCase, TestMixin):
assert 0 == mocked_vlc_media.parse.call_count
assert result is False
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait(mocked_get_vlc):
"""
Check that waiting for a state change works
"""
@ -516,9 +508,10 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The results should be True
assert result is True
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait_error(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait_error(mocked_get_vlc, vlc_env):
"""
Check that getting an error when waiting for a state change returns False
"""
@ -539,9 +532,10 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The results should be True
assert result is False
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait_times_out(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
def test_media_state_wait_times_out(mocked_get_vlc, vlc_env):
"""
Check that waiting for a state returns False when it times out after 60 seconds
"""
@ -564,7 +558,8 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The results should be True
assert result is False
def test_resize(self):
def test_resize():
"""
Test resizing the player
"""
@ -581,9 +576,10 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_controller.preview_display.size.assert_called_with()
mocked_controller.vlc_widget.resize.assert_called_with((10, 10))
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play(self, mocked_get_vlc, mocked_threading):
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play(mocked_get_vlc, mocked_threading):
"""
Test the play() method
"""
@ -616,9 +612,10 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_controller.vlc_widget.raise_.assert_called_with()
assert result is True, 'The value returned from play() should be True'
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play_media_wait_state_not_playing(self, mocked_get_vlc, mocked_threading):
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play_media_wait_state_not_playing(mocked_get_vlc, mocked_threading):
"""
Test the play() method when media_wait_state() returns False
"""
@ -643,9 +640,10 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_thread.start.assert_called_with()
assert result is False
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play_dvd(self, mocked_get_vlc, mocked_threading):
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_play_dvd(mocked_get_vlc, mocked_threading):
"""
Test the play() method with a DVD
"""
@ -684,8 +682,9 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_controller.vlc_widget.raise_.assert_called_with()
assert result is True, 'The value returned from play() should be True'
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause(mocked_get_vlc):
"""
Test that the pause method works correctly
"""
@ -709,8 +708,9 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_media_state_wait.assert_called_with(mocked_display, 2)
assert MediaState.Paused == vlc_player.get_live_state()
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause_not_playing(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause_not_playing(mocked_get_vlc):
"""
Test the pause method when the player is not playing
"""
@ -729,8 +729,9 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media.get_state.assert_called_with()
assert 0 == mocked_display.vlc_media_player.pause.call_count
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause_fail(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_pause_fail(mocked_get_vlc):
"""
Test the pause method when the player fails to pause the media
"""
@ -754,8 +755,9 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_media_state_wait.assert_called_with(mocked_display, 2)
assert MediaState.Paused is not vlc_player.state
@patch('openlp.core.ui.media.vlcplayer.threading')
def test_stop(self, mocked_threading):
@patch('openlp.core.ui.media.vlcplayer.threading')
def test_stop(mocked_threading):
"""
Test stopping the current item
"""
@ -775,7 +777,8 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_thread.start.assert_called_with()
assert MediaState.Stopped == vlc_player.get_live_state()
def test_volume(self):
def test_volume():
"""
Test setting the volume
"""
@ -790,7 +793,8 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The volume should have been set
mocked_display.vlc_media_player.audio_set_volume.assert_called_with(10)
def test_seek_unseekable_media(self):
def test_seek_unseekable_media():
"""
Test seeking something that can't be seeked
"""
@ -807,7 +811,8 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media_player.is_seekable.assert_called_with()
assert 0 == mocked_display.vlc_media_player.set_time.call_count
def test_seek_seekable_media(self):
def test_seek_seekable_media():
"""
Test seeking something that is seekable, but not a DVD
"""
@ -824,7 +829,8 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media_player.is_seekable.assert_called_with()
mocked_display.vlc_media_player.set_time.assert_called_with(100)
def test_seek_dvd(self):
def test_seek_dvd():
"""
Test seeking a DVD
"""
@ -842,7 +848,8 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media_player.is_seekable.assert_called_with()
mocked_display.vlc_media_player.set_time.assert_called_with(2000)
def test_reset(self):
def test_reset():
"""
Test the reset() method
"""
@ -858,7 +865,8 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_widget.setVisible.assert_called_with(False)
assert MediaState.Off == vlc_player.get_live_state()
def test_set_visible_has_own_widget(self):
def test_set_visible_has_own_widget():
"""
Test the set_visible() method when the player has its own widget
"""
@ -873,8 +881,9 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The media should be stopped and invsibile
mocked_display.vlc_widget.setVisible.assert_called_with(True)
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_update_ui(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_update_ui(mocked_get_vlc):
"""
Test updating the UI
"""
@ -904,8 +913,9 @@ class TestVLCPlayer(TestCase, TestMixin):
expected_calls = [call(True), call(False)]
assert expected_calls == mocked_controller.seek_slider.blockSignals.call_args_list
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_update_ui_dvd(self, mocked_get_vlc):
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_update_ui_dvd(mocked_get_vlc):
"""
Test updating the UI for a CD or DVD
"""

View File

@ -738,14 +738,14 @@ class TestMediaItem(TestCase, TestMixin):
Test on_style_combo_box_index_changed
"""
# GIVEN: An instance of :class:`MediaManagerItem` a mocked media_item.settings
self.media_item.settings = MagicMock()
self.media_item.settings_tab = MagicMock()
# WHEN: Calling on_style_combo_box_index_changed
self.media_item.on_style_combo_box_index_changed(2)
# THEN: The layout_style setting should have been set
assert self.media_item.settings.layout_style == 2
self.media_item.settings.layout_style_combo_box.setCurrentIndex.assert_called_once_with(2)
assert self.media_item.settings_tab.layout_style == 2
self.media_item.settings_tab.layout_style_combo_box.setCurrentIndex.assert_called_once_with(2)
self.mocked_settings_instance.setValue.assert_called_once_with('bibles/verse layout style', 2)
def test_on_version_combo_box_index_changed_no_bible(self):