This commit is contained in:
Phill Ridout 2017-12-22 21:21:39 +00:00
commit 3bdf6d0bd6
33 changed files with 550 additions and 501 deletions

View File

@ -80,6 +80,7 @@ def extension_loader(glob_pattern, excluded_files=[]):
extension_path = extension_path.relative_to(app_dir)
if extension_path.name in excluded_files:
continue
log.debug('Attempting to import %s', extension_path)
module_name = path_to_module(extension_path)
try:
importlib.import_module(module_name)

View File

@ -25,7 +25,6 @@ OpenLP work.
"""
import html
import logging
import os
import re
import math

View File

@ -71,7 +71,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Scan a directory for objects inheriting from the ``Plugin`` class.
"""
glob_pattern = os.path.join('plugins', '*', '*plugin.py')
glob_pattern = os.path.join('plugins', '*', '[!.]*plugin.py')
extension_loader(glob_pattern)
plugin_classes = Plugin.__subclasses__()
plugin_objects = []

View File

@ -181,7 +181,8 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
"""
log.debug('_check_available_media_players')
controller_dir = os.path.join('core', 'ui', 'media')
glob_pattern = os.path.join(controller_dir, '*player.py')
# Find all files that do not begin with '.' (lp:#1738047) and end with player.py
glob_pattern = os.path.join(controller_dir, '[!.]*player.py')
extension_loader(glob_pattern, ['mediaplayer.py'])
player_classes = MediaPlayer.__subclasses__()
for player_class in player_classes:

View File

@ -336,6 +336,7 @@ class BibleImportForm(OpenLPWizard):
self.sword_layout.addWidget(self.sword_tab_widget)
self.sword_disabled_label = QtWidgets.QLabel(self.sword_widget)
self.sword_disabled_label.setObjectName('SwordDisabledLabel')
self.sword_disabled_label.setWordWrap(True)
self.sword_layout.addWidget(self.sword_disabled_label)
self.select_stack.addWidget(self.sword_widget)
self.wordproject_widget = QtWidgets.QWidget(self.select_page)

View File

@ -129,7 +129,8 @@ class PresentationPlugin(Plugin):
"""
log.debug('check_pre_conditions')
controller_dir = os.path.join('plugins', 'presentations', 'lib')
glob_pattern = os.path.join(controller_dir, '*controller.py')
# Find all files that do not begin with '.' (lp:#1738047) and end with controller.py
glob_pattern = os.path.join(controller_dir, '[!.]*controller.py')
extension_loader(glob_pattern, ['presentationcontroller.py'])
controller_classes = PresentationController.__subclasses__()
for controller_class in controller_classes:

View File

@ -289,9 +289,9 @@ class TestOpenLP(TestCase):
result = self.openlp.event(event)
# THEN: The path should be inserted.
self.assertTrue(result, "The method should have returned True.")
assert result is True, "The method should have returned True."
mocked_file_method.assert_called_once_with()
self.assertEqual(self.openlp.args[0], file_path, "The path should be in args.")
assert self.openlp.args[0] == file_path, "The path should be in args."
@patch('openlp.core.app.is_macosx')
def test_application_activate_event(self, mocked_is_macosx):
@ -309,7 +309,7 @@ class TestOpenLP(TestCase):
result = self.openlp.event(event)
# THEN:
self.assertTrue(result, "The method should have returned True.")
assert result is True, "The method should have returned True."
# self.assertFalse(self.openlp.main_window.isMinimized())
@patch('openlp.core.app.get_version')
@ -321,11 +321,11 @@ class TestOpenLP(TestCase):
# GIVEN: Mocked data version and OpenLP version which are the same
old_install = False
MOCKED_VERSION = {
'full': '2.2.0-bzr000',
'version': '2.2.0',
'full': '2.4.0-bzr000',
'version': '2.4.0',
'build': 'bzr000'
}
Settings().setValue('core/application version', '2.2.0')
Settings().setValue('core/application version', '2.4.0')
mocked_get_version.return_value = MOCKED_VERSION
mocked_question.return_value = QtWidgets.QMessageBox.No
@ -333,8 +333,8 @@ class TestOpenLP(TestCase):
self.openlp.backup_on_upgrade(old_install, False)
# THEN: It should not ask if we want to create a backup
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be the same!')
self.assertEqual(mocked_question.call_count, 0, 'No question should have been asked!')
assert Settings().value('core/application version') == '2.4.0', 'Version should be the same!'
assert mocked_question.call_count == 0, 'No question should have been asked!'
@patch('openlp.core.app.get_version')
@patch('openlp.core.app.QtWidgets.QMessageBox.question')
@ -345,8 +345,8 @@ class TestOpenLP(TestCase):
# GIVEN: Mocked data version and OpenLP version which are different
old_install = True
MOCKED_VERSION = {
'full': '2.2.0-bzr000',
'version': '2.2.0',
'full': '2.4.0-bzr000',
'version': '2.4.0',
'build': 'bzr000'
}
Settings().setValue('core/application version', '2.0.5')
@ -359,7 +359,7 @@ class TestOpenLP(TestCase):
self.openlp.backup_on_upgrade(old_install, True)
# THEN: It should ask if we want to create a backup
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
self.assertEqual(mocked_question.call_count, 1, 'A question should have been asked!')
assert Settings().value('core/application version') == '2.4.0', 'Version should be upgraded!'
assert mocked_question.call_count == 1, 'A question should have been asked!'
self.openlp.splash.hide.assert_called_once_with()
self.openlp.splash.show.assert_called_once_with()

View File

@ -54,10 +54,10 @@ class TestMediaController(TestCase, TestMixin):
media_controller._generate_extensions_lists()
# THEN: extensions list should have been copied from the player to the mediacontroller
self.assertListEqual(media_player.video_extensions_list, media_controller.video_extensions_list,
'Video extensions should be the same')
self.assertListEqual(media_player.audio_extensions_list, media_controller.audio_extensions_list,
'Audio extensions should be the same')
assert media_player.video_extensions_list == media_controller.video_extensions_list, \
'Video extensions should be the same'
assert media_player.audio_extensions_list == media_controller.audio_extensions_list, \
'Audio extensions should be the same'
def test_resize(self):
"""
@ -96,7 +96,7 @@ class TestMediaController(TestCase, TestMixin):
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return False
self.assertFalse(ret, '_check_file_type should return False when no mediaplayers are available.')
assert ret is False, '_check_file_type should return False when no mediaplayers are available.'
@patch('openlp.core.ui.media.mediacontroller.MediaController._get_used_players')
@patch('openlp.core.ui.media.mediacontroller.UiStrings')
@ -119,7 +119,7 @@ class TestMediaController(TestCase, TestMixin):
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return False
self.assertFalse(ret, '_check_file_type should return False when the processor for service_item is None.')
assert ret is False, '_check_file_type should return False when the processor for service_item is None.'
@patch('openlp.core.ui.media.mediacontroller.MediaController._get_used_players')
@patch('openlp.core.ui.media.mediacontroller.UiStrings')
@ -148,8 +148,8 @@ class TestMediaController(TestCase, TestMixin):
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return True
self.assertTrue(ret, '_check_file_type should return True when mediaplayers are available and '
'the service item has an automatic processor.')
assert ret is True, '_check_file_type should return True when mediaplayers are available and ' \
'the service item has an automatic processor.'
@patch('openlp.core.ui.media.mediacontroller.MediaController._get_used_players')
@patch('openlp.core.ui.media.mediacontroller.UiStrings')
@ -178,8 +178,8 @@ class TestMediaController(TestCase, TestMixin):
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return True
self.assertTrue(ret, '_check_file_type should return True when the players available are different'
'from the processor from the service item.')
assert ret is True, '_check_file_type should return True when the players available are different' \
'from the processor from the service item.'
def test_media_play_msg(self):
"""

View File

@ -64,17 +64,17 @@ class TestSystemPlayer(TestCase):
player = SystemPlayer(self)
# THEN: The correct initial values should be set up
self.assertEqual('system', player.name)
self.assertEqual('System', player.original_name)
self.assertEqual('&System', player.display_name)
self.assertEqual(self, player.parent)
self.assertEqual(ADDITIONAL_EXT, player.additional_extensions)
assert 'system' == player.name
assert 'System' == player.original_name
assert '&System' == player.display_name
assert self == player.parent
assert ADDITIONAL_EXT == player.additional_extensions
MockQMediaPlayer.assert_called_once_with(None, QtMultimedia.QMediaPlayer.VideoSurface)
mocked_mimetypes.init.assert_called_once_with()
mocked_media_player.service.assert_called_once_with()
mocked_media_player.supportedMimeTypes.assert_called_once_with()
self.assertEqual(['*.aiff'], player.audio_extensions_list)
self.assertEqual(['*.afl', '*.asf'], player.video_extensions_list)
assert ['*.aiff'] == player.audio_extensions_list
assert ['*.afl', '*.asf'] == player.video_extensions_list
@patch('openlp.core.ui.media.systemplayer.QtMultimediaWidgets.QVideoWidget')
@patch('openlp.core.ui.media.systemplayer.QtMultimedia.QMediaPlayer')
@ -96,15 +96,15 @@ class TestSystemPlayer(TestCase):
# THEN: The player should have a display widget
MockQVideoWidget.assert_called_once_with(mocked_display)
self.assertEqual(mocked_video_widget, mocked_display.video_widget)
assert mocked_video_widget == mocked_display.video_widget
mocked_display.size.assert_called_once_with()
mocked_video_widget.resize.assert_called_once_with([1, 2, 3, 4])
MockQMediaPlayer.assert_called_with(mocked_display)
self.assertEqual(mocked_media_player, mocked_display.media_player)
assert mocked_media_player == mocked_display.media_player
mocked_media_player.setVideoOutput.assert_called_once_with(mocked_video_widget)
mocked_video_widget.raise_.assert_called_once_with()
mocked_video_widget.hide.assert_called_once_with()
self.assertTrue(player.has_own_widget)
assert player.has_own_widget is True
def test_disconnect_slots(self):
"""
@ -133,7 +133,7 @@ class TestSystemPlayer(TestCase):
result = player.check_available()
# THEN: it should be available
self.assertTrue(result)
assert result is True
def test_load_valid_media(self):
"""
@ -157,7 +157,7 @@ class TestSystemPlayer(TestCase):
mocked_display.media_player.setMedia.assert_called_once_with(
QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile('/path/to/file')))
mocked_volume.assert_called_once_with(mocked_display, 1)
self.assertTrue(result)
assert result is True
def test_load_invalid_media(self):
"""
@ -178,7 +178,7 @@ class TestSystemPlayer(TestCase):
# THEN: stuff
mocked_display.controller.media_info.file_info.absoluteFilePath.assert_called_once_with()
mocked_check_media.assert_called_once_with('/path/to/file')
self.assertFalse(result)
assert result is False
def test_resize(self):
"""
@ -227,7 +227,7 @@ class TestSystemPlayer(TestCase):
mocked_display.media_player.durationChanged.connect.assert_called_once_with('function')
mocked_set_state.assert_called_once_with(MediaState.Playing, mocked_display)
mocked_display.video_widget.raise_.assert_called_once_with()
self.assertTrue(result)
assert result is True
@patch('openlp.core.ui.media.systemplayer.functools')
def test_play_is_preview(self, mocked_functools):
@ -258,7 +258,7 @@ class TestSystemPlayer(TestCase):
mocked_display.media_player.durationChanged.connect.assert_called_once_with('function')
mocked_set_state.assert_called_once_with(MediaState.Playing, mocked_display)
mocked_display.video_widget.raise_.assert_called_once_with()
self.assertTrue(result)
assert result is True
def test_pause_is_live(self):
"""
@ -419,14 +419,13 @@ class TestSystemPlayer(TestCase):
expected_position_calls = [call(), call()]
expected_block_signals_calls = [call(True), call(False)]
mocked_display.media_player.state.assert_called_once_with()
self.assertEqual(1, mocked_stop.call_count)
self.assertEqual(expected_stop_calls, mocked_stop.call_args_list)
self.assertEqual(2, mocked_display.media_player.position.call_count)
self.assertEqual(expected_position_calls, mocked_display.media_player.position.call_args_list)
assert 1 == mocked_stop.call_count
assert expected_stop_calls == mocked_stop.call_args_list
assert 2 == mocked_display.media_player.position.call_count
assert expected_position_calls == mocked_display.media_player.position.call_args_list
mocked_set_visible.assert_called_once_with(mocked_display, False)
mocked_display.controller.seek_slider.isSliderDown.assert_called_once_with()
self.assertEqual(expected_block_signals_calls,
mocked_display.controller.seek_slider.blockSignals.call_args_list)
assert expected_block_signals_calls == mocked_display.controller.seek_slider.blockSignals.call_args_list
mocked_display.controller.seek_slider.setSliderPosition.assert_called_once_with(2)
def test_get_media_display_css(self):
@ -440,7 +439,7 @@ class TestSystemPlayer(TestCase):
result = player.get_media_display_css()
# THEN: The css should be empty
self.assertEqual('', result)
assert '' == result
@patch('openlp.core.ui.media.systemplayer.QtMultimedia.QMediaPlayer')
def test_get_info(self, MockQMediaPlayer):
@ -459,7 +458,7 @@ class TestSystemPlayer(TestCase):
# THEN: The info should be correct
expected_info = 'This media player uses your operating system to provide media capabilities.<br/> ' \
'<strong>Audio</strong><br/>[]<br/><strong>Video</strong><br/>[]<br/>'
self.assertEqual(expected_info, result)
assert expected_info == result
@patch('openlp.core.ui.media.systemplayer.CheckMediaWorker')
@patch('openlp.core.ui.media.systemplayer.QtCore.QThread')
@ -493,9 +492,9 @@ class TestSystemPlayer(TestCase):
mocked_check_media_worker.finished.connect.assert_called_once_with('quit')
mocked_thread.started.connect.assert_called_once_with('play')
mocked_thread.start.assert_called_once_with()
self.assertEqual(2, mocked_thread.isRunning.call_count)
assert 2 == mocked_thread.isRunning.call_count
mocked_application.processEvents.assert_called_once_with()
self.assertTrue(result)
assert result is True
class TestCheckMediaWorker(TestCase):
@ -513,7 +512,7 @@ class TestCheckMediaWorker(TestCase):
worker = CheckMediaWorker(path)
# THEN: The correct values should be set up
self.assertIsNotNone(worker)
assert worker is not None
def test_signals_media(self):
"""
@ -530,7 +529,7 @@ class TestCheckMediaWorker(TestCase):
# THEN: The worker should exit and the result should be True
mocked_stop.assert_called_once_with()
mocked_finished.emit.assert_called_once_with()
self.assertTrue(worker.result)
assert worker.result is True
def test_signals_error(self):
"""
@ -547,4 +546,4 @@ class TestCheckMediaWorker(TestCase):
# THEN: The worker should exit and the result should be True
mocked_stop.assert_called_once_with()
mocked_finished.emit.assert_called_once_with()
self.assertFalse(worker.result)
assert worker.result is False

View File

@ -24,7 +24,7 @@ Package to test the openlp.core.ui.media.vlcplayer package.
"""
import os
import sys
from datetime import datetime, timedelta
from datetime import timedelta
from unittest import TestCase, skip
from unittest.mock import MagicMock, patch, call
@ -64,7 +64,7 @@ class TestVLCPlayer(TestCase, TestMixin):
get_vlc()
# THEN: The extra environment variable should be there
self.assertNotIn('openlp.core.ui.media.vendor.vlc', sys.modules)
assert 'openlp.core.ui.media.vendor.vlc' not in sys.modules
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
def test_fix_vlc_22_plugin_path(self, mocked_is_macosx):
@ -78,9 +78,8 @@ class TestVLCPlayer(TestCase, TestMixin):
get_vlc()
# THEN: The extra environment variable should be there
self.assertIn('VLC_PLUGIN_PATH', os.environ,
'The plugin path should be in the environment variables')
self.assertEqual('/Applications/VLC.app/Contents/MacOS/plugins', os.environ['VLC_PLUGIN_PATH'])
assert 'VLC_PLUGIN_PATH' in os.environ, 'The plugin path should be in the environment variables'
assert '/Applications/VLC.app/Contents/MacOS/plugins' == os.environ['VLC_PLUGIN_PATH']
@patch.dict(os.environ)
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@ -95,8 +94,7 @@ class TestVLCPlayer(TestCase, TestMixin):
get_vlc()
# THEN: The extra environment variable should NOT be there
self.assertNotIn('VLC_PLUGIN_PATH', os.environ,
'The plugin path should NOT be in the environment variables')
assert 'VLC_PLUGIN_PATH' not in os.environ, 'The plugin path should NOT be in the environment variables'
def test_init(self):
"""
@ -109,12 +107,12 @@ class TestVLCPlayer(TestCase, TestMixin):
vlc_player = VlcPlayer(None)
# THEN: The correct variables are set
self.assertEqual('VLC', vlc_player.original_name)
self.assertEqual('&VLC', vlc_player.display_name)
self.assertIsNone(vlc_player.parent)
self.assertTrue(vlc_player.can_folder)
self.assertListEqual(AUDIO_EXT, vlc_player.audio_extensions_list)
self.assertListEqual(VIDEO_EXT, vlc_player.video_extensions_list)
assert 'VLC' == vlc_player.original_name
assert '&VLC' == vlc_player.display_name
assert vlc_player.parent is None
assert vlc_player.can_folder is True
assert AUDIO_EXT == vlc_player.audio_extensions_list
assert VIDEO_EXT == vlc_player.video_extensions_list
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@ -151,20 +149,20 @@ class TestVLCPlayer(TestCase, TestMixin):
vlc_player.setup(mocked_display)
# THEN: The VLC widget should be set up correctly
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
assert mocked_display.vlc_widget == mocked_qframe
mocked_qframe.setFrameStyle.assert_called_with(1)
mocked_settings.value.assert_called_with('advanced/hide mouse')
mocked_vlc.Instance.assert_called_with('--no-video-title-show --no-audio --no-video-title-show '
'--mouse-hide-timeout=0')
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
assert mocked_display.vlc_instance == mocked_instance
mocked_instance.media_player_new.assert_called_with()
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
assert mocked_display.vlc_media_player == mocked_media_player_new
mocked_display.size.assert_called_with()
mocked_qframe.resize.assert_called_with((10, 10))
mocked_qframe.raise_.assert_called_with()
mocked_qframe.hide.assert_called_with()
mocked_media_player_new.set_xwindow.assert_called_with(2)
self.assertTrue(vlc_player.has_own_widget)
assert vlc_player.has_own_widget is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@ -328,7 +326,7 @@ class TestVLCPlayer(TestCase, TestMixin):
is_available = vlc_player.check_available()
# THEN: VLC should be available
self.assertTrue(is_available)
assert is_available is True
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_check_not_available(self, mocked_get_vlc):
@ -343,7 +341,7 @@ class TestVLCPlayer(TestCase, TestMixin):
is_available = vlc_player.check_available()
# THEN: VLC should NOT be available
self.assertFalse(is_available)
assert is_available is False
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.os.path.normcase')
@ -376,11 +374,11 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_path.assert_called_with(media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
assert mocked_vlc_media == mocked_display.vlc_media
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
mocked_vlc_media.parse.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertTrue(result)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@ -421,11 +419,11 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_location.assert_called_with('cdda://' + media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
assert mocked_vlc_media == mocked_display.vlc_media
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
mocked_vlc_media.parse.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertTrue(result)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@ -466,11 +464,11 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_location.assert_called_with('cdda:///' + media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
assert mocked_vlc_media == mocked_display.vlc_media
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
mocked_vlc_media.parse.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertTrue(result)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@ -511,11 +509,11 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_location.assert_called_with('cdda://' + media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
self.assertEqual(0, mocked_subitems.item_at_index.call_count)
assert mocked_vlc_media == mocked_display.vlc_media
assert 0 == mocked_subitems.item_at_index.call_count
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
self.assertEqual(0, mocked_vlc_media.parse.call_count)
self.assertFalse(result)
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)
@ -538,7 +536,7 @@ class TestVLCPlayer(TestCase, TestMixin):
result = vlc_player.media_state_wait(mocked_display, 2)
# THEN: The results should be True
self.assertTrue(result)
assert result is True
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
@ -561,7 +559,7 @@ class TestVLCPlayer(TestCase, TestMixin):
result = vlc_player.media_state_wait(mocked_display, 2)
# THEN: The results should be True
self.assertFalse(result)
assert result is False
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@patch('openlp.core.ui.media.vlcplayer.datetime', MockDateTime)
@ -586,7 +584,7 @@ class TestVLCPlayer(TestCase, TestMixin):
result = vlc_player.media_state_wait(mocked_display, 3)
# THEN: The results should be True
self.assertFalse(result)
assert result is False
def test_resize(self):
"""
@ -636,9 +634,9 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: A bunch of things should happen to play the media
mocked_thread.start.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertEqual(MediaState.Playing, vlc_player.get_live_state())
assert MediaState.Playing == vlc_player.get_live_state()
mocked_display.vlc_widget.raise_.assert_called_with()
self.assertTrue(result, 'The value returned from play() should be True')
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')
@ -666,7 +664,7 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: A thread should be started, but the method should return False
mocked_thread.start.assert_called_with()
self.assertFalse(result)
assert result is False
@patch('openlp.core.ui.media.vlcplayer.threading')
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
@ -705,9 +703,9 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media_player.audio_set_track.assert_called_with(1)
mocked_display.vlc_media_player.video_set_spu.assert_called_with(1)
mocked_volume.assert_called_with(mocked_display, 100)
self.assertEqual(MediaState.Playing, vlc_player.get_live_state())
assert MediaState.Playing == vlc_player.get_live_state()
mocked_display.vlc_widget.raise_.assert_called_with()
self.assertTrue(result, 'The value returned from play() should be True')
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):
@ -732,7 +730,7 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media.get_state.assert_called_with()
mocked_display.vlc_media_player.pause.assert_called_with()
mocked_media_state_wait.assert_called_with(mocked_display, 2)
self.assertEqual(MediaState.Paused, vlc_player.get_live_state())
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):
@ -752,7 +750,7 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The pause method should exit early
mocked_display.vlc_media.get_state.assert_called_with()
self.assertEqual(0, mocked_display.vlc_media_player.pause.call_count)
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):
@ -777,7 +775,7 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_display.vlc_media.get_state.assert_called_with()
mocked_display.vlc_media_player.pause.assert_called_with()
mocked_media_state_wait.assert_called_with(mocked_display, 2)
self.assertNotEqual(MediaState.Paused, vlc_player.state)
assert MediaState.Paused is not vlc_player.state
@patch('openlp.core.ui.media.vlcplayer.threading')
def test_stop(self, mocked_threading):
@ -798,7 +796,7 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: A thread should have been started to stop VLC
mocked_threading.Thread.assert_called_with(target=mocked_stop)
mocked_thread.start.assert_called_with()
self.assertEqual(MediaState.Stopped, vlc_player.get_live_state())
assert MediaState.Stopped == vlc_player.get_live_state()
def test_volume(self):
"""
@ -828,7 +826,7 @@ class TestVLCPlayer(TestCase, TestMixin):
vlc_player.volume(mocked_display, 10)
# THEN: The volume should NOT have been set
self.assertEqual(0, mocked_display.vlc_media_player.audio_set_volume.call_count)
assert 0 == mocked_display.vlc_media_player.audio_set_volume.call_count
def test_seek_unseekable_media(self):
"""
@ -845,7 +843,7 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: nothing should happen
mocked_display.vlc_media_player.is_seekable.assert_called_with()
self.assertEqual(0, mocked_display.vlc_media_player.set_time.call_count)
assert 0 == mocked_display.vlc_media_player.set_time.call_count
def test_seek_seekable_media(self):
"""
@ -896,7 +894,7 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The media should be stopped and invisible
mocked_display.vlc_media_player.stop.assert_called_with()
mocked_display.vlc_widget.setVisible.assert_called_with(False)
self.assertEqual(MediaState.Off, vlc_player.get_live_state())
assert MediaState.Off == vlc_player.get_live_state()
def test_set_visible_has_own_widget(self):
"""
@ -926,7 +924,7 @@ class TestVLCPlayer(TestCase, TestMixin):
vlc_player.set_visible(mocked_display, True)
# THEN: The media should be stopped and invsibile
self.assertEqual(0, mocked_display.vlc_widget.setVisible.call_count)
assert 0 == mocked_display.vlc_widget.setVisible.call_count
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
def test_update_ui(self, mocked_get_vlc):
@ -953,12 +951,12 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: Certain methods should be called
mocked_stop.assert_called_with(mocked_display)
self.assertEqual(2, mocked_stop.call_count)
assert 2 == mocked_stop.call_count
mocked_display.vlc_media_player.get_time.assert_called_with()
mocked_set_visible.assert_called_with(mocked_display, False)
mocked_controller.seek_slider.setSliderPosition.assert_called_with(400000)
expected_calls = [call(True), call(False)]
self.assertEqual(expected_calls, mocked_controller.seek_slider.blockSignals.call_args_list)
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):
@ -987,12 +985,12 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: Certain methods should be called
mocked_stop.assert_called_with(mocked_display)
self.assertEqual(2, mocked_stop.call_count)
assert 2 == mocked_stop.call_count
mocked_display.vlc_media_player.get_time.assert_called_with()
mocked_set_visible.assert_called_with(mocked_display, False)
mocked_controller.seek_slider.setSliderPosition.assert_called_with(300)
expected_calls = [call(True), call(False)]
self.assertEqual(expected_calls, mocked_controller.seek_slider.blockSignals.call_args_list)
assert expected_calls == mocked_controller.seek_slider.blockSignals.call_args_list
@patch('openlp.core.ui.media.vlcplayer.translate')
def test_get_info(self, mocked_translate):
@ -1007,6 +1005,6 @@ class TestVLCPlayer(TestCase, TestMixin):
info = vlc_player.get_info()
# THEN: The information should be correct
self.assertEqual('VLC is an external player which supports a number of different formats.<br/> '
'<strong>Audio</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>Video</strong><br/>' +
str(VIDEO_EXT) + '<br/>', info)
assert 'VLC is an external player which supports a number of different formats.<br/> ' \
'<strong>Audio</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>Video</strong><br/>' + \
str(VIDEO_EXT) + '<br/>' == info

View File

@ -47,8 +47,7 @@ class TestWebkitPlayer(TestCase):
available = webkit_player.check_available()
# THEN: The player should not be available when '[object HTMLUnknownElement]' is returned
self.assertEqual(False, available,
'The WebkitPlayer should not be available when video feature detection fails')
assert available is False, 'The WebkitPlayer should not be available when video feature detection fails'
def test_check_available_video_enabled(self):
"""
@ -64,5 +63,4 @@ class TestWebkitPlayer(TestCase):
available = webkit_player.check_available()
# THEN: The player should be available when '[object HTMLVideoElement]' is returned
self.assertEqual(True, available,
'The WebkitPlayer should be available when video feature detection passes')
assert available is True, 'The WebkitPlayer should be available when video feature detection passes'

View File

@ -59,8 +59,8 @@ class TestFirstTimeForm(TestCase, TestMixin):
about_form = AboutForm(None)
# THEN: The build number should be in the text
self.assertTrue('OpenLP 3.1.5 build 3000' in about_form.about_text_edit.toPlainText(),
"The build number should be set correctly")
assert 'OpenLP 3.1.5 build 3000' in about_form.about_text_edit.toPlainText(), \
"The build number should be set correctly"
def test_about_form_date(self):
"""
@ -74,5 +74,4 @@ class TestFirstTimeForm(TestCase, TestMixin):
license_text = about_form.license_text_edit.toPlainText()
# THEN: The date should be in the text twice.
self.assertTrue(license_text.count(date_string, 0) == 2,
"The text string should be added twice to the license string")
assert license_text.count(date_string, 0) == 2, "The text string should be added twice to the license string"

View File

@ -50,7 +50,7 @@ class TestAdvancedTab(TestCase, TestMixin):
advanced_tab = AdvancedTab(settings_form)
# THEN:
self.assertEqual("Advanced", advanced_tab.tab_title, 'The tab title should be Advanced')
assert "Advanced" == advanced_tab.tab_title, 'The tab title should be Advanced'
def test_change_search_as_type(self):
"""
@ -64,6 +64,6 @@ class TestAdvancedTab(TestCase, TestMixin):
advanced_tab.on_search_as_type_check_box_changed(True)
# THEN: we should have two post save processed to run
self.assertEqual(2, len(settings_form.processes), 'Two post save processes should be created')
self.assertTrue("songs_config_updated" in settings_form.processes, 'The songs plugin should be called')
self.assertTrue("custom_config_updated" in settings_form.processes, 'The custom plugin should be called')
assert 2 == len(settings_form.processes), 'Two post save processes should be created'
assert "songs_config_updated" in settings_form.processes, 'The songs plugin should be called'
assert "custom_config_updated" in settings_form.processes, 'The custom plugin should be called'

View File

@ -90,12 +90,12 @@ class TestFirstTimeForm(TestCase, TestMixin):
frw.initialize(expected_screens)
# THEN: The screens should be set up, and the default values initialised
self.assertEqual(expected_screens, frw.screens, 'The screens should be correct')
self.assertTrue(frw.web_access, 'The default value of self.web_access should be True')
self.assertFalse(frw.was_cancelled, 'The default value of self.was_cancelled should be False')
self.assertListEqual([], frw.theme_screenshot_threads, 'The list of threads should be empty')
self.assertListEqual([], frw.theme_screenshot_workers, 'The list of workers should be empty')
self.assertFalse(frw.has_run_wizard, 'has_run_wizard should be False')
assert expected_screens == frw.screens, 'The screens should be correct'
assert frw.web_access is True, 'The default value of self.web_access should be True'
assert frw.was_cancelled is False, 'The default value of self.was_cancelled should be False'
assert [] == frw.theme_screenshot_threads, 'The list of threads should be empty'
assert [] == frw.theme_screenshot_workers, 'The list of workers should be empty'
assert frw.has_run_wizard is False, 'has_run_wizard should be False'
def test_set_defaults(self):
"""
@ -124,7 +124,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
# THEN: The default values should have been set
mocked_restart.assert_called_with()
self.assertEqual('http://openlp.org/files/frw/', frw.web, 'The default URL should be set')
assert 'http://openlp.org/files/frw/' == frw.web, 'The default URL should be set'
mocked_cancel_button.clicked.connect.assert_called_with(frw.on_cancel_button_clicked)
mocked_no_internet_finish_btn.clicked.connect.assert_called_with(frw.on_no_internet_finish_button_clicked)
mocked_currentIdChanged.connect.assert_called_with(frw.on_current_id_changed)
@ -176,12 +176,12 @@ class TestFirstTimeForm(TestCase, TestMixin):
frw.on_cancel_button_clicked()
# THEN: The right things should be called in the right order
self.assertTrue(frw.was_cancelled, 'The was_cancelled property should have been set to True')
assert frw.was_cancelled is True, 'The was_cancelled property should have been set to True'
mocked_worker.set_download_canceled.assert_called_with(True)
mocked_thread.isRunning.assert_called_with()
self.assertEqual(2, mocked_thread.isRunning.call_count, 'isRunning() should have been called twice')
assert 2 == mocked_thread.isRunning.call_count, 'isRunning() should have been called twice'
mocked_time.sleep.assert_called_with(0.1)
self.assertEqual(1, mocked_time.sleep.call_count, 'sleep() should have only been called once')
assert 1 == mocked_time.sleep.call_count, 'sleep() should have only been called once'
mocked_set_normal_cursor.assert_called_with()
def test_broken_config(self):
@ -198,7 +198,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
first_time_form._download_index()
# THEN: The First Time Form should not have web access
self.assertFalse(first_time_form.web_access, 'There should not be web access with a broken config file')
assert first_time_form.web_access is False, 'There should not be web access with a broken config file'
def test_invalid_config(self):
"""
@ -214,7 +214,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
first_time_form._download_index()
# THEN: The First Time Form should not have web access
self.assertFalse(first_time_form.web_access, 'There should not be web access with an invalid config file')
assert first_time_form.web_access is False, 'There should not be web access with an invalid config file'
@patch('openlp.core.ui.firsttimeform.get_web_page')
@patch('openlp.core.ui.firsttimeform.QtWidgets.QMessageBox')

View File

@ -43,7 +43,7 @@ class TestFormattingTagController(TestCase):
result = self.services._strip(tag)
# THEN: The tag should be returned with the wrappers removed.
self.assertEqual(result, 'tag', 'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'')
assert result == 'tag', 'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\''
def test_end_tag_changed_processes_correctly(self):
"""
@ -64,11 +64,9 @@ class TestFormattingTagController(TestCase):
error, result = self.services.end_tag_changed(test['start'], test['end'])
# THEN: The result should match the predetermined value.
self.assertTrue(result == test['gen'],
'Function should handle end tag correctly : %s and %s for %s ' %
(test['gen'], result, test['start']))
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
error)
assert result == test['gen'], \
'Function should handle end tag correctly : %s and %s for %s ' % (test['gen'], result, test['start'])
assert error == test['valid'], 'Function should not generate unexpected error messages : %s ' % error
def test_start_tag_changed_processes_correctly(self):
"""
@ -88,10 +86,9 @@ class TestFormattingTagController(TestCase):
error, result = self.services.start_tag_changed(test['start'], test['end'])
# THEN: The result should match the predetermined value.
self.assertTrue(result == test['gen'], 'Function should handle end tag correctly : %s and %s ' %
(test['gen'], result))
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
error)
assert result == test['gen'], \
'Function should handle end tag correctly : %s and %s ' % (test['gen'], result)
assert error == test['valid'], 'Function should not generate unexpected error messages : %s ' % error
def test_start_html_to_end_html(self):
"""
@ -106,5 +103,4 @@ class TestFormattingTagController(TestCase):
result = self.services.start_html_to_end_html(test1)
# THEN: The result should match the predetermined value.
self.assertTrue(result == test2, 'Calculated end tag should be valid: %s and %s = %s' %
(test1, test2, result))
assert result == test2, 'Calculated end tag should be valid: %s and %s = %s' % (test1, test2, result)

View File

@ -83,8 +83,8 @@ class TestFormattingTagForm(TestCase):
call(row_count, 2, mocked_table_widget),
call(row_count, 3, mocked_table_widget)
]
self.assertEqual(expected_set_item_calls, form.tag_table_widget.setItem.call_args_list,
'setItem should have been called correctly')
assert expected_set_item_calls == form.tag_table_widget.setItem.call_args_list, \
'setItem should have been called correctly'
form.tag_table_widget.resizeRowsToContents.assert_called_with()
form.tag_table_widget.scrollToBottom.assert_called_with()
form.tag_table_widget.selectRow.assert_called_with(row_count)

View File

@ -83,7 +83,7 @@ class TestMainDisplay(TestCase, TestMixin):
main_display = MainDisplay(display)
# THEN: The controller should be a live controller.
self.assertEqual(main_display.is_live, True, 'The main display should be a live controller')
assert main_display.is_live is True, 'The main display should be a live controller'
def test_set_transparency_enabled(self):
"""
@ -97,12 +97,12 @@ class TestMainDisplay(TestCase, TestMixin):
main_display.set_transparency(True)
# THEN: The transparent stylesheet should be used
self.assertEqual(TRANSPARENT_STYLESHEET, main_display.styleSheet(),
'The MainDisplay should use the transparent stylesheet')
self.assertFalse(main_display.autoFillBackground(),
'The MainDisplay should not have autoFillBackground set')
self.assertTrue(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground),
'The MainDisplay should have a translucent background')
assert TRANSPARENT_STYLESHEET == main_display.styleSheet(), \
'The MainDisplay should use the transparent stylesheet'
assert main_display.autoFillBackground() is False, \
'The MainDisplay should not have autoFillBackground set'
assert main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground) is True, \
'The MainDisplay should have a translucent background'
def test_set_transparency_disabled(self):
"""
@ -116,10 +116,10 @@ class TestMainDisplay(TestCase, TestMixin):
main_display.set_transparency(False)
# THEN: The opaque stylesheet should be used
self.assertEqual(OPAQUE_STYLESHEET, main_display.styleSheet(),
'The MainDisplay should use the opaque stylesheet')
self.assertFalse(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground),
'The MainDisplay should not have a translucent background')
assert OPAQUE_STYLESHEET == main_display.styleSheet(), \
'The MainDisplay should use the opaque stylesheet'
assert main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground) is False, \
'The MainDisplay should not have a translucent background'
def test_css_changed(self):
"""
@ -156,9 +156,9 @@ class TestMainDisplay(TestCase, TestMixin):
main_display = MainDisplay(display)
# THEN: The window flags should be the same as those needed on Mac OS X.
self.assertEqual(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint | QtCore.Qt.NoDropShadowWindowHint,
main_display.windowFlags(),
'The window flags should be Qt.Window, Qt.FramelessWindowHint, and Qt.NoDropShadowWindowHint.')
assert QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint | QtCore.Qt.NoDropShadowWindowHint == \
main_display.windowFlags(), \
'The window flags should be Qt.Window, Qt.FramelessWindowHint, and Qt.NoDropShadowWindowHint.'
@skipUnless(is_macosx(), 'Can only run test on Mac OS X due to pyobjc dependency.')
def test_macosx_display(self):
@ -181,10 +181,10 @@ class TestMainDisplay(TestCase, TestMixin):
pyobjc_nsview = objc_object(cobject=nsview_pointer)
# THEN: The window level and collection behavior should be the same as those needed for Mac OS X.
self.assertEqual(pyobjc_nsview.window().level(), NSMainMenuWindowLevel + 2,
'Window level should be NSMainMenuWindowLevel + 2')
self.assertEqual(pyobjc_nsview.window().collectionBehavior(), NSWindowCollectionBehaviorManaged,
'Window collection behavior should be NSWindowCollectionBehaviorManaged')
assert pyobjc_nsview.window().level() == NSMainMenuWindowLevel + 2, \
'Window level should be NSMainMenuWindowLevel + 2'
assert pyobjc_nsview.window().collectionBehavior() == NSWindowCollectionBehaviorManaged, \
'Window collection behavior should be NSWindowCollectionBehaviorManaged'
@patch('openlp.core.ui.maindisplay.Settings')
def test_show_display_startup_logo(self, MockedSettings):
@ -250,9 +250,9 @@ class TestMainDisplay(TestCase, TestMixin):
main_display.build_html(service_item)
# THEN: the following should had not been called
self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once')
self.assertEquals(main_display.media_controller.video.call_count, 0,
'Media Controller video should not have been called')
assert main_display.web_view.setHtml.call_count == 1, 'setHTML should be called once'
assert main_display.media_controller.video.call_count == 0, \
'Media Controller video should not have been called'
@patch('openlp.core.ui.maindisplay.Settings')
@patch('openlp.core.ui.maindisplay.build_html')
@ -282,9 +282,9 @@ class TestMainDisplay(TestCase, TestMixin):
main_display.build_html(service_item)
# THEN: the following should had not been called
self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once')
self.assertEquals(main_display.media_controller.video.call_count, 1,
'Media Controller video should have been called once')
assert main_display.web_view.setHtml.call_count == 1, 'setHTML should be called once'
assert main_display.media_controller.video.call_count == 1, \
'Media Controller video should have been called once'
def test_calling_next_item_in_playlist():

View File

@ -130,8 +130,8 @@ class TestMainWindow(TestCase, TestMixin):
self.main_window.set_service_modified(True, 'test.osz')
# THEN the main window's title should be set to the
self.assertEqual(self.main_window.windowTitle(), '%s - %s*' % (UiStrings().OpenLP, 'test.osz'),
'The main window\'s title should be set to "<the contents of UiStrings().OpenLP> - test.osz*"')
assert self.main_window.windowTitle(), '%s - %s*' % (UiStrings().OpenLP, 'test.osz') == \
'The main window\'s title should be set to "<the contents of UiStrings().OpenLP> - test.osz*"'
def test_set_service_unmodified(self):
"""
@ -143,8 +143,8 @@ class TestMainWindow(TestCase, TestMixin):
self.main_window.set_service_modified(False, 'test.osz')
# THEN the main window's title should be set to the
self.assertEqual(self.main_window.windowTitle(), '%s - %s' % (UiStrings().OpenLP, 'test.osz'),
'The main window\'s title should be set to "<the contents of UiStrings().OpenLP> - test.osz"')
assert self.main_window.windowTitle(), '%s - %s' % (UiStrings().OpenLP, 'test.osz') == \
'The main window\'s title should be set to "<the contents of UiStrings().OpenLP> - test.osz"'
def test_mainwindow_configuration(self):
"""

View File

@ -52,8 +52,8 @@ class TestMedia(TestCase, TestMixin):
used_players, overridden_player = get_media_players()
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
self.assertEqual([], used_players, 'Used players should be an empty list')
self.assertEqual('', overridden_player, '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'
def test_get_media_players_no_players(self):
"""
@ -73,8 +73,8 @@ class TestMedia(TestCase, TestMixin):
used_players, overridden_player = get_media_players()
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
self.assertEqual([], used_players, 'Used players should be an empty list')
self.assertEqual('auto', overridden_player, 'Overridden player should be "auto"')
assert [] == used_players, 'Used players should be an empty list'
assert 'auto' == overridden_player, 'Overridden player should be "auto"'
def test_get_media_players_with_valid_list(self):
"""
@ -94,8 +94,8 @@ class TestMedia(TestCase, TestMixin):
used_players, overridden_player = get_media_players()
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
self.assertEqual(['vlc', 'webkit', 'system'], used_players, 'Used players should be correct')
self.assertEqual('', overridden_player, 'Overridden player should be an empty string')
assert ['vlc', 'webkit', 'system'] == used_players, 'Used players should be correct'
assert '' == overridden_player, 'Overridden player should be an empty string'
def test_get_media_players_with_overridden_player(self):
"""
@ -115,8 +115,8 @@ class TestMedia(TestCase, TestMixin):
used_players, overridden_player = get_media_players()
# THEN: the used_players should be an empty list, and the overridden player should be an empty string
self.assertEqual(['vlc', 'webkit', 'system'], used_players, 'Used players should be correct')
self.assertEqual('vlc,webkit,system', overridden_player, 'Overridden player should be a string of players')
assert ['vlc', 'webkit', 'system'] == used_players, 'Used players should be correct'
assert 'vlc,webkit,system' == overridden_player, 'Overridden player should be a string of players'
def test_parse_optical_path_linux(self):
"""
@ -138,13 +138,13 @@ class TestMedia(TestCase, TestMixin):
(device_path, title_track, audio_track, subtitle_track, start, end, name) = parse_optical_path(path)
# THEN: The return values should match the original values
self.assertEqual(org_title_track, title_track, 'Returned title_track should match the original')
self.assertEqual(org_audio_track, audio_track, 'Returned audio_track should match the original')
self.assertEqual(org_subtitle_track, subtitle_track, 'Returned subtitle_track should match the original')
self.assertEqual(org_start, start, 'Returned start should match the original')
self.assertEqual(org_end, end, 'Returned end should match the original')
self.assertEqual(org_name, name, 'Returned end should match the original')
self.assertEqual(org_device_path, device_path, 'Returned device_path should match the original')
assert org_title_track == title_track, 'Returned title_track should match the original'
assert org_audio_track == audio_track, 'Returned audio_track should match the original'
assert org_subtitle_track == subtitle_track, 'Returned subtitle_track should match the original'
assert org_start == start, 'Returned start should match the original'
assert org_end == end, 'Returned end should match the original'
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):
"""
@ -166,10 +166,10 @@ class TestMedia(TestCase, TestMixin):
(device_path, title_track, audio_track, subtitle_track, start, end, name) = parse_optical_path(path)
# THEN: The return values should match the original values
self.assertEqual(org_title_track, title_track, 'Returned title_track should match the original')
self.assertEqual(org_audio_track, audio_track, 'Returned audio_track should match the original')
self.assertEqual(org_subtitle_track, subtitle_track, 'Returned subtitle_track should match the original')
self.assertEqual(org_start, start, 'Returned start should match the original')
self.assertEqual(org_end, end, 'Returned end should match the original')
self.assertEqual(org_name, name, 'Returned end should match the original')
self.assertEqual(org_device_path, device_path, 'Returned device_path should match the original')
assert org_title_track == title_track, 'Returned title_track should match the original'
assert org_audio_track == audio_track, 'Returned audio_track should match the original'
assert org_subtitle_track == subtitle_track, 'Returned subtitle_track should match the original'
assert org_start == start, 'Returned start should match the original'
assert org_end == end, 'Returned end should match the original'
assert org_name == name, 'Returned end should match the original'
assert org_device_path == device_path, 'Returned device_path should match the original'

View File

@ -54,7 +54,7 @@ class TestServiceManager(TestCase):
ServiceManager(None)
# WHEN: the default service manager is built.
# THEN: The the controller should be registered in the registry.
self.assertNotEqual(Registry().get('service_manager'), None, 'The base service manager should be registered')
assert Registry().get('service_manager') is not None, 'The base service manager should be registered'
def test_create_basic_service(self):
"""
@ -67,9 +67,9 @@ class TestServiceManager(TestCase):
service_manager.service_theme = 'test_theme'
service = service_manager.create_basic_service()[0]
# THEN: The controller should be registered in the registry.
self.assertNotEqual(service, None, 'The base service should be created')
self.assertEqual(service['openlp_core']['service-theme'], 'test_theme', 'The test theme should be saved')
self.assertEqual(service['openlp_core']['lite-service'], False, 'The lite service should be saved')
assert service is not None, 'The base service should be created'
assert service['openlp_core']['service-theme'] == 'test_theme', 'The test theme should be saved'
assert service['openlp_core']['lite-service'] is False, 'The lite service should be saved'
def test_supported_suffixes(self):
"""
@ -81,9 +81,9 @@ class TestServiceManager(TestCase):
service_manager.supported_suffixes('txt')
service_manager.supported_suffixes(['pptx', 'ppt'])
# THEN: The suffixes should be available to test.
self.assertEqual('txt' in service_manager.suffixes, True, 'The suffix txt should be in the list')
self.assertEqual('ppt' in service_manager.suffixes, True, 'The suffix ppt should be in the list')
self.assertEqual('pptx' in service_manager.suffixes, True, 'The suffix pptx should be in the list')
assert 'txt' in service_manager.suffixes, 'The suffix txt should be in the list'
assert 'ppt' in service_manager.suffixes, 'The suffix ppt should be in the list'
assert 'pptx' in service_manager.suffixes, 'The suffix pptx should be in the list'
def test_build_context_menu(self):
"""
@ -114,20 +114,20 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have been called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have been called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have been called once')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.rename_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have been called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have been called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have been called once'
def test_build_song_context_menu(self):
"""
@ -169,29 +169,29 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
assert service_manager.edit_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.rename_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 1, 'Should have be called once')
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
assert service_manager.auto_play_slides_once.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.timed_slide_interval.setChecked.call_count == 1, 'Should have be called once'
def test_build_bible_context_menu(self):
"""
@ -233,29 +233,29 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.rename_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 1, 'Should have be called once')
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
assert service_manager.auto_play_slides_once.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.timed_slide_interval.setChecked.call_count == 1, 'Should have be called once'
def test_build_custom_context_menu(self):
"""
@ -298,29 +298,29 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
assert service_manager.edit_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.rename_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 1, 'Should have be called once')
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
assert service_manager.auto_play_slides_once.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.timed_slide_interval.setChecked.call_count == 1, 'Should have be called once'
def test_build_image_context_menu(self):
"""
@ -361,29 +361,29 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.rename_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
# THEN we add a 2nd display frame and regenerate the menu.
service_item._raw_frames.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 2,
'Should have be called twice')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 1, 'Should have be called once')
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
assert service_manager.auto_play_slides_once.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 1, 'Should have be called once'
assert service_manager.timed_slide_interval.setChecked.call_count == 1, 'Should have be called once'
def test_build_media_context_menu(self):
"""
@ -422,25 +422,25 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.rename_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
# THEN I change the length of the media and regenerate the menu.
service_item.set_media_length(5)
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
self.assertEqual(service_manager.time_action.setVisible.call_count, 3, 'Should have be called three times')
assert service_manager.time_action.setVisible.call_count == 3, 'Should have be called three times'
def test_build_presentation_pdf_context_menu(self):
"""
@ -480,20 +480,20 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 2, 'Should have be called twice')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.rename_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 2, 'Should have be called twice'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
def test_build_presentation_non_pdf_context_menu(self):
"""
@ -530,20 +530,20 @@ class TestServiceManager(TestCase):
# WHEN I define a context menu
service_manager.context_menu(1)
# THEN the following calls should have occurred.
self.assertEqual(service_manager.edit_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.rename_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.create_custom_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.maintain_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.notes_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.time_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_start_action.setVisible.call_count, 1, 'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
self.assertEqual(service_manager.auto_play_slides_once.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.auto_play_slides_loop.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
self.assertEqual(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
'Should have be called once')
assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.rename_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
@patch('openlp.core.ui.servicemanager.Settings')
@patch('PyQt5.QtCore.QTimer.singleShot')
@ -576,7 +576,7 @@ class TestServiceManager(TestCase):
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview()
# THEN: timer should not be started
self.assertEqual(mocked_singleShot.call_count, 0, 'Should not be called')
assert mocked_singleShot.call_count == 0, 'Should not be called'
@patch('openlp.core.ui.servicemanager.Settings')
@patch('PyQt5.QtCore.QTimer.singleShot')
@ -595,7 +595,7 @@ class TestServiceManager(TestCase):
service_manager.on_single_click_preview()
# THEN: timer should not be started
mocked_make_live.assert_called_with()
self.assertEqual(mocked_singleShot.call_count, 0, 'Should not be called')
assert mocked_singleShot.call_count == 0, 'Should not be called'
@patch('openlp.core.ui.servicemanager.ServiceManager.make_preview')
def test_single_click_timeout_single(self, mocked_make_preview):
@ -607,8 +607,7 @@ class TestServiceManager(TestCase):
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview_timeout()
# THEN: make_preview() should have been called
self.assertEqual(mocked_make_preview.call_count, 1,
'ServiceManager.make_preview() should have been called once')
assert mocked_make_preview.call_count == 1, 'ServiceManager.make_preview() should have been called once'
@patch('openlp.core.ui.servicemanager.ServiceManager.make_preview')
@patch('openlp.core.ui.servicemanager.ServiceManager.make_live')
@ -622,7 +621,7 @@ class TestServiceManager(TestCase):
service_manager.on_double_click_live()
service_manager.on_single_click_preview_timeout()
# THEN: make_preview() should not have been called
self.assertEqual(mocked_make_preview.call_count, 0, 'ServiceManager.make_preview() should not be called')
assert mocked_make_preview.call_count == 0, 'ServiceManager.make_preview() should not be called'
@patch('openlp.core.ui.servicemanager.shutil.copy')
@patch('openlp.core.ui.servicemanager.zipfile')
@ -650,7 +649,7 @@ class TestServiceManager(TestCase):
result = service_manager.save_file()
# THEN: The "save_as" method is called to save the service
self.assertTrue(result)
assert result is True
mocked_save_file_as.assert_called_with()
@patch('openlp.core.ui.servicemanager.shutil.copy')
@ -678,7 +677,7 @@ class TestServiceManager(TestCase):
result = service_manager.save_local_file()
# THEN: The "save_as" method is called to save the service
self.assertTrue(result)
assert result is True
mocked_save_file_as.assert_called_with()
@patch('openlp.core.ui.servicemanager.ServiceManager.regenerate_service_items')
@ -699,8 +698,8 @@ class TestServiceManager(TestCase):
service_manager.theme_change()
# THEN: The the theme toolbar should not be visible
self.assertFalse(service_manager.toolbar.actions['theme_combo_box'].isVisible(),
'The visibility should be False')
assert service_manager.toolbar.actions['theme_combo_box'].isVisible() is False, \
'The visibility should be False'
@patch('openlp.core.ui.servicemanager.ServiceManager.regenerate_service_items')
def test_theme_change_service(self, mocked_regenerate_service_items):
@ -720,8 +719,8 @@ class TestServiceManager(TestCase):
service_manager.theme_change()
# THEN: The the theme toolbar should be visible
self.assertTrue(service_manager.toolbar.actions['theme_combo_box'].isVisible(),
'The visibility should be True')
assert service_manager.toolbar.actions['theme_combo_box'].isVisible() is True, \
'The visibility should be True'
@patch('openlp.core.ui.servicemanager.ServiceManager.regenerate_service_items')
def test_theme_change_song(self, mocked_regenerate_service_items):
@ -741,5 +740,5 @@ class TestServiceManager(TestCase):
service_manager.theme_change()
# THEN: The the theme toolbar should be visible
self.assertTrue(service_manager.toolbar.actions['theme_combo_box'].isVisible(),
'The visibility should be True')
assert service_manager.toolbar.actions['theme_combo_box'].isVisible() is True, \
'The visibility should be True'

View File

@ -57,7 +57,7 @@ class TestSettingsForm(TestCase):
# THEN: The general tab should have been inserted into the stacked layout and an item inserted into the list
mocked_add_widget.assert_called_with(general_tab)
self.assertEqual(1, mocked_add_item.call_count, 'addItem should have been called')
assert 1 == mocked_add_item.call_count, 'addItem should have been called'
def test_insert_tab_not_visible(self):
"""
@ -75,7 +75,7 @@ class TestSettingsForm(TestCase):
# THEN: The general tab should have been inserted, but no list item should have been inserted into the list
mocked_add_widget.assert_called_with(general_tab)
self.assertEqual(0, mocked_add_item.call_count, 'addItem should not have been called')
assert 0 == mocked_add_item.call_count, 'addItem should not have been called'
def test_accept_with_inactive_plugins(self):
"""
@ -107,7 +107,7 @@ class TestSettingsForm(TestCase):
# THEN: The general tab's save() method should have been called, but not the themes tab
mocked_general_save.assert_called_with()
self.assertEqual(0, mocked_theme_save.call_count, 'The Themes tab\'s save() should not have been called')
assert 0 == mocked_theme_save.call_count, 'The Themes tab\'s save() should not have been called'
def test_list_item_changed_invalid_item(self):
"""
@ -128,7 +128,7 @@ class TestSettingsForm(TestCase):
settings_form.list_item_changed(100)
# THEN: The rest of the method should not have been called
self.assertEqual(0, mocked_count.call_count, 'The count method of the stacked layout should not be called')
assert 0 == mocked_count.call_count, 'The count method of the stacked layout should not be called'
def test_reject_with_inactive_items(self):
"""
@ -158,7 +158,7 @@ class TestSettingsForm(TestCase):
# THEN: The general tab's cancel() method should have been called, but not the themes tab
mocked_general_cancel.assert_called_with()
self.assertEqual(0, mocked_theme_cancel.call_count, 'The Themes tab\'s cancel() should not have been called')
assert 0 == mocked_theme_cancel.call_count, 'The Themes tab\'s cancel() should not have been called'
def test_register_post_process(self):
"""

View File

@ -29,12 +29,18 @@ from PyQt5 import QtCore, QtGui
from openlp.core.common.registry import Registry
from openlp.core.lib import ServiceItemAction
from openlp.core.ui import SlideController, LiveController, PreviewController
from openlp.core.ui.slidecontroller import InfoLabel, WIDE_MENU, NON_TEXT_MENU
from openlp.core.ui.slidecontroller import InfoLabel, SlideController, LiveController, PreviewController, \
NON_TEXT_MENU, WIDE_MENU
class TestSlideController(TestCase):
def setUp(self):
"""
Set up the components need for all tests.
"""
Registry.create()
def test_initial_slide_controller(self):
"""
Test the initial slide controller state .
@ -44,7 +50,7 @@ class TestSlideController(TestCase):
# WHEN: the default controller is built.
# THEN: The controller should not be a live controller.
self.assertEqual(slide_controller.is_live, False, 'The base slide controller should not be a live controller')
assert slide_controller.is_live is False, 'The base slide controller should not be a live controller'
def test_text_service_item_blank(self):
"""
@ -121,8 +127,8 @@ class TestSlideController(TestCase):
# THEN: Only on_blank_display() should have been called with an argument of True
mocked_on_blank_display.assert_called_once_with(True)
self.assertEqual(0, mocked_on_theme_display.call_count, 'on_theme_display should not have been called')
self.assertEqual(0, mocked_on_hide_display.call_count, 'on_hide_display should not have been called')
assert 0 == mocked_on_theme_display.call_count, 'on_theme_display should not have been called'
assert 0 == mocked_on_hide_display.call_count, 'on_hide_display should not have been called'
def test_toggle_display_hide(self):
"""
@ -142,8 +148,8 @@ class TestSlideController(TestCase):
# THEN: Only on_blank_display() should have been called with an argument of True
mocked_on_blank_display.assert_called_once_with(True)
self.assertEqual(0, mocked_on_theme_display.call_count, 'on_theme_display should not have been called')
self.assertEqual(0, mocked_on_hide_display.call_count, 'on_hide_display should not have been called')
assert 0 == mocked_on_theme_display.call_count, 'on_theme_display should not have been called'
assert 0 == mocked_on_hide_display.call_count, 'on_hide_display should not have been called'
def test_toggle_display_theme(self):
"""
@ -163,8 +169,8 @@ class TestSlideController(TestCase):
# THEN: Only on_theme_display() should have been called with an argument of True
mocked_on_theme_display.assert_called_once_with(True)
self.assertEqual(0, mocked_on_blank_display.call_count, 'on_blank_display should not have been called')
self.assertEqual(0, mocked_on_hide_display.call_count, 'on_hide_display should not have been called')
assert 0 == mocked_on_blank_display.call_count, 'on_blank_display should not have been called'
assert 0 == mocked_on_hide_display.call_count, 'on_hide_display should not have been called'
def test_toggle_display_desktop(self):
"""
@ -184,8 +190,8 @@ class TestSlideController(TestCase):
# THEN: Only on_hide_display() should have been called with an argument of True
mocked_on_hide_display.assert_called_once_with(True)
self.assertEqual(0, mocked_on_blank_display.call_count, 'on_blank_display should not have been called')
self.assertEqual(0, mocked_on_theme_display.call_count, 'on_theme_display should not have been called')
assert 0 == mocked_on_blank_display.call_count, 'on_blank_display should not have been called'
assert 0 == mocked_on_theme_display.call_count, 'on_theme_display should not have been called'
def test_toggle_display_show(self):
"""
@ -348,7 +354,7 @@ class TestSlideController(TestCase):
# THEN: The value of slide_limits should be 10
mocked_value.assert_called_once_with('advanced/slide limits')
self.assertEqual(10, slide_controller.slide_limits, 'Slide limits should have been updated to 10')
assert 10 == slide_controller.slide_limits, 'Slide limits should have been updated to 10'
def test_enable_tool_bar_live(self):
"""
@ -368,7 +374,7 @@ class TestSlideController(TestCase):
# THEN: The enable_live_tool_bar() method is called, not enable_preview_tool_bar()
mocked_enable_live_tool_bar.assert_called_once_with(mocked_service_item)
self.assertEqual(0, mocked_enable_preview_tool_bar.call_count, 'The preview method should not have been called')
assert 0 == mocked_enable_preview_tool_bar.call_count, 'The preview method should not have been called'
def test_enable_tool_bar_preview(self):
"""
@ -388,7 +394,7 @@ class TestSlideController(TestCase):
# THEN: The enable_preview_tool_bar() method is called, not enable_live_tool_bar()
mocked_enable_preview_tool_bar.assert_called_once_with(mocked_service_item)
self.assertEqual(0, mocked_enable_live_tool_bar.call_count, 'The live method should not have been called')
assert 0 == mocked_enable_live_tool_bar.call_count, 'The live method should not have been called'
def test_refresh_service_item_text(self):
"""
@ -409,7 +415,7 @@ class TestSlideController(TestCase):
# THEN: The item should be re-processed
mocked_service_item.is_text.assert_called_once_with()
self.assertEqual(0, mocked_service_item.is_image.call_count, 'is_image should not have been called')
assert 0 == mocked_service_item.is_image.call_count, 'is_image should not have been called'
mocked_service_item.render.assert_called_once_with()
mocked_process_item.assert_called_once_with(mocked_service_item, 5)
@ -456,9 +462,8 @@ class TestSlideController(TestCase):
# THEN: The item should be re-processed
mocked_service_item.is_text.assert_called_once_with()
mocked_service_item.is_image.assert_called_once_with()
self.assertEqual(0, mocked_service_item.render.call_count, 'The render() method should not have been called')
self.assertEqual(0, mocked_process_item.call_count,
'The mocked_process_item() method should not have been called')
assert 0 == mocked_service_item.render.call_count, 'The render() method should not have been called'
assert 0 == mocked_process_item.call_count, 'The mocked_process_item() method should not have been called'
def test_add_service_item_with_song_edit(self):
"""
@ -477,7 +482,7 @@ class TestSlideController(TestCase):
# THEN: The item is processed, the slide number is correct, and the song is not editable (or something)
mocked_item.render.assert_called_once_with()
self.assertFalse(slide_controller.song_edit, 'song_edit should be False')
assert slide_controller.song_edit is False, 'song_edit should be False'
mocked_process_item.assert_called_once_with(mocked_item, 2)
def test_add_service_item_without_song_edit(self):
@ -497,7 +502,7 @@ class TestSlideController(TestCase):
# THEN: The item is processed, the slide number is correct, and the song is not editable (or something)
mocked_item.render.assert_called_once_with()
self.assertFalse(slide_controller.song_edit, 'song_edit should be False')
assert slide_controller.song_edit is False, 'song_edit should be False'
mocked_process_item.assert_called_once_with(mocked_item, 0)
def test_replace_service_manager_item_different_items(self):
@ -517,9 +522,9 @@ class TestSlideController(TestCase):
slide_controller.replace_service_manager_item(mocked_item)
# THEN: The service item should not be processed
self.assertEqual(0, mocked_process_item.call_count, 'The _process_item() method should not have been called')
self.assertEqual(0, mocked_preview_widget.current_slide_number.call_count,
'The preview_widgetcurrent_slide_number.() method should not have been called')
assert 0 == mocked_process_item.call_count, 'The _process_item() method should not have been called'
assert 0 == mocked_preview_widget.current_slide_number.call_count, \
'The preview_widget current_slide_number.() method should not have been called'
def test_replace_service_manager_item_same_item(self):
"""
@ -583,7 +588,7 @@ class TestSlideController(TestCase):
slide_controller.on_slide_selected_index([10])
# THEN: It should have exited early
self.assertEqual(0, mocked_item.is_command.call_count, 'The service item should have not been called')
assert 0 == mocked_item.is_command.call_count, 'The service item should have not been called'
@patch.object(Registry, 'execute')
def test_on_slide_selected_index_service_item_command(self, mocked_execute):
@ -612,8 +617,8 @@ class TestSlideController(TestCase):
mocked_item.is_command.assert_called_once_with()
mocked_execute.assert_called_once_with('mocked item_slide', [mocked_item, True, 9])
mocked_update_preview.assert_called_once_with()
self.assertEqual(0, mocked_preview_widget.change_slide.call_count, 'Change slide should not have been called')
self.assertEqual(0, mocked_slide_selected.call_count, 'slide_selected should not have been called')
assert 0 == mocked_preview_widget.change_slide.call_count, 'Change slide should not have been called'
assert 0 == mocked_slide_selected.call_count, 'slide_selected should not have been called'
@patch.object(Registry, 'execute')
def test_on_slide_selected_index_service_item_not_command(self, mocked_execute):
@ -639,8 +644,8 @@ class TestSlideController(TestCase):
# THEN: It should have sent a notification
mocked_item.is_command.assert_called_once_with()
self.assertEqual(0, mocked_execute.call_count, 'Execute should not have been called')
self.assertEqual(0, mocked_update_preview.call_count, 'Update preview should not have been called')
assert 0 == mocked_execute.call_count, 'Execute should not have been called'
assert 0 == mocked_update_preview.call_count, 'Update preview should not have been called'
mocked_preview_widget.change_slide.assert_called_once_with(7)
mocked_slide_selected.assert_called_once_with()
@ -685,9 +690,9 @@ class TestSlideController(TestCase):
slide_controller._process_item(mocked_media_item, 0)
# THEN: Registry.execute should have been called to stop the presentation
self.assertEqual(2, mocked_execute.call_count, 'Execute should have been called 2 times')
self.assertEqual('mocked_presentation_item_stop', mocked_execute.call_args_list[1][0][0],
'The presentation should have been stopped.')
assert 2 == mocked_execute.call_count, 'Execute should have been called 2 times'
assert 'mocked_presentation_item_stop' == mocked_execute.call_args_list[1][0][0], \
'The presentation should have been stopped.'
def test_live_stolen_focus_shortcuts(self):
"""
@ -737,8 +742,8 @@ class TestSlideController(TestCase):
slide_controller.on_preview_double_click()
# THEN: The call to addActions should be correct
self.assertEqual(1, slide_controller.on_go_live.call_count, 'on_go_live should have been called once.')
self.assertEqual(0, slide_controller.on_preview_add_to_service.call_count, 'Should have not been called.')
assert 1 == slide_controller.on_go_live.call_count, 'on_go_live should have been called once.'
assert 0 == slide_controller.on_preview_add_to_service.call_count, 'Should have not been called.'
@patch('openlp.core.ui.slidecontroller.Settings')
def test_on_preview_double_click_add_to_service(self, MockedSettings):
@ -760,8 +765,8 @@ class TestSlideController(TestCase):
slide_controller.on_preview_double_click()
# THEN: The call to addActions should be correct
self.assertEqual(0, slide_controller.on_go_live.call_count, 'on_go_live Should have not been called.')
self.assertEqual(1, slide_controller.on_preview_add_to_service.call_count, 'Should have been called once.')
assert 0 == slide_controller.on_go_live.call_count, 'on_go_live Should have not been called.'
assert 1 == slide_controller.on_preview_add_to_service.call_count, 'Should have been called once.'
@patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
@ -800,11 +805,10 @@ class TestSlideController(TestCase):
slide_controller.update_preview()
# THEN: A screen_grab should have been called
self.assertEqual(0, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should not be called')
self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called')
self.assertEqual(2, mocked_singleShot.call_count,
'Timer to grab_maindisplay should have been called 2 times')
self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager not be called')
assert 0 == slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should not be called'
assert 0 == slide_controller.display.preview.call_count, 'display.preview() should not be called'
assert 2 == mocked_singleShot.call_count, 'Timer to grab_maindisplay should have been called 2 times'
assert 0 == mocked_image_manager.get_image.call_count, 'image_manager not be called'
@patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
@ -843,10 +847,10 @@ class TestSlideController(TestCase):
slide_controller.update_preview()
# THEN: setPixmap and the image_manager should have been called
self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called')
self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called')
self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called')
self.assertEqual(1, mocked_image_manager.get_image.call_count, 'image_manager should be called')
assert 1 == slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called'
assert 0 == slide_controller.display.preview.call_count, 'display.preview() should not be called'
assert 0 == mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called'
assert 1 == mocked_image_manager.get_image.call_count, 'image_manager should be called'
@patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
@ -885,10 +889,10 @@ class TestSlideController(TestCase):
slide_controller.update_preview()
# THEN: setPixmap should have been called
self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called')
self.assertEqual(0, slide_controller.display.preview.call_count, 'display.preview() should not be called')
self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called')
self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager should not be called')
assert 1 == slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called'
assert 0 == slide_controller.display.preview.call_count, 'display.preview() should not be called'
assert 0 == mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called'
assert 0 == mocked_image_manager.get_image.call_count, 'image_manager should not be called'
@patch(u'openlp.core.ui.slidecontroller.SlideController.image_manager')
@patch(u'PyQt5.QtCore.QTimer.singleShot')
@ -927,10 +931,10 @@ class TestSlideController(TestCase):
slide_controller.update_preview()
# THEN: setPixmap and display.preview should have been called
self.assertEqual(1, slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called')
self.assertEqual(1, slide_controller.display.preview.call_count, 'display.preview() should be called')
self.assertEqual(0, mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called')
self.assertEqual(0, mocked_image_manager.get_image.call_count, 'image_manager should not be called')
assert 1 == slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called'
assert 1 == slide_controller.display.preview.call_count, 'display.preview() should be called'
assert 0 == mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called'
assert 0 == mocked_image_manager.get_image.call_count, 'image_manager should not be called'
class TestInfoLabel(TestCase):
@ -1023,7 +1027,7 @@ class TestLiveController(TestCase):
# WHEN: the default controller is built.
# THEN: The controller should not be a live controller.
self.assertEqual(live_controller.is_live, True, 'The slide controller should be a live controller')
assert live_controller.is_live is True, 'The slide controller should be a live controller'
class TestPreviewLiveController(TestCase):
@ -1038,4 +1042,4 @@ class TestPreviewLiveController(TestCase):
# WHEN: the default controller is built.
# THEN: The controller should not be a live controller.
self.assertEqual(preview_controller.is_live, False, 'The slide controller should be a Preview controller')
assert preview_controller.is_live is False, 'The slide controller should be a Preview controller'

View File

@ -49,5 +49,5 @@ class TestThemeManager(TestCase):
self.instance.on_image_path_edit_path_changed(Path('/', 'new', 'pat.h'))
# THEN: The theme background file should be set and `set_background_page_values` should have been called
self.assertEqual(self.instance.theme.background_filename, Path('/', 'new', 'pat.h'))
assert self.instance.theme.background_filename == Path('/', 'new', 'pat.h')
mocked_set_background_page_values.assert_called_once_with()

View File

@ -80,7 +80,7 @@ class TestThemeManager(TestCase):
# WHEN: the default theme manager is built.
# THEN: The the controller should be registered in the registry.
self.assertIsNotNone(Registry().get('theme_manager'), 'The base theme manager should be registered')
assert Registry().get('theme_manager') is not None, 'The base theme manager should be registered'
@patch('openlp.core.ui.thememanager.copyfile')
@patch('openlp.core.ui.thememanager.create_paths')
@ -147,8 +147,8 @@ class TestThemeManager(TestCase):
theme_manager._write_theme(mocked_theme, None, None)
# THEN: It should have been created
self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')),
'Theme with special characters should have been created!')
assert os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')) is True, \
'Theme with special characters should have been created!'
@patch('openlp.core.ui.thememanager.QtWidgets.QMessageBox.question', return_value=QtWidgets.QMessageBox.Yes)
@patch('openlp.core.ui.thememanager.translate')
@ -206,8 +206,8 @@ class TestThemeManager(TestCase):
theme_manager.unzip_theme(theme_file, folder_path)
# THEN: Files should be unpacked
self.assertTrue((folder_path / 'Moss on tree' / 'Moss on tree.xml').exists())
self.assertEqual(mocked_critical_error_message_box.call_count, 0, 'No errors should have happened')
assert (folder_path / 'Moss on tree' / 'Moss on tree.xml').exists() is True
assert mocked_critical_error_message_box.call_count == 0, 'No errors should have happened'
folder_path.rmtree()
def test_unzip_theme_invalid_version(self):
@ -228,4 +228,4 @@ class TestThemeManager(TestCase):
theme_manager.unzip_theme('theme.file', 'folder')
# THEN: The critical_error_message_box should have been called
self.assertEqual(mocked_critical_error_message_box.call_count, 1, 'Should have been called once')
assert mocked_critical_error_message_box.call_count == 1, 'Should have been called once'

View File

@ -51,7 +51,7 @@ class TestThemeTab(TestCase, TestMixin):
themes_tab = ThemesTab(settings_form)
# THEN:
self.assertEqual("Themes", themes_tab.tab_title, 'The tab title should be Theme')
assert "Themes" == themes_tab.tab_title, 'The tab title should be Theme'
def test_save_triggers_processes_true(self):
"""
@ -66,7 +66,7 @@ class TestThemeTab(TestCase, TestMixin):
themes_tab.save()
# THEN: we should have two post save processed to run
self.assertEqual(1, len(settings_form.processes), 'One post save processes should be created')
assert 1 == len(settings_form.processes), 'One post save processes should be created'
def test_save_triggers_processes_false(self):
"""
@ -81,4 +81,4 @@ class TestThemeTab(TestCase, TestMixin):
themes_tab.save()
# THEN: we should have two post save processed to run
self.assertEqual(0, len(settings_form.processes), 'No post save processes should be created')
assert 0 == len(settings_form.processes), 'No post save processes should be created'

View File

@ -60,8 +60,7 @@ class TestColorDialog(TestCase):
widget = ColorButton()
# THEN: The widget __init__ method should have the correct properties and methods called
self.assertEqual(widget.parent, None,
'The parent should be the same as the one that the class was instianted with')
assert widget.parent is None, 'The parent should be the same as the one that the class was instianted with'
self.mocked_change_color.assert_called_once_with('#ffffff')
mocked_set_tool_tip.assert_called_once_with('Tool Tip Text')
self.mocked_clicked.connect.assert_called_once_with(widget.on_clicked)
@ -80,7 +79,7 @@ class TestColorDialog(TestCase):
widget.change_color('#000000')
# THEN: The _color attribute should be set to #000000 and setStyleSheet should have been called twice
self.assertEqual(widget._color, '#000000', '_color should have been set to #000000')
assert widget._color == '#000000', '_color should have been set to #000000'
mocked_set_style_sheet.assert_has_calls(
[call('background-color: #ffffff'), call('background-color: #000000')])
@ -98,7 +97,7 @@ class TestColorDialog(TestCase):
value = widget.color
# THEN: The value set in _color should be returned
self.assertEqual(value, '#000000', 'The value returned should be equal to the one we set')
assert value == '#000000', 'The value returned should be equal to the one we set'
# @patch('openlp.core.widgets.buttons.ColorButton.__init__', **{'return_value': None})
def test_color_setter(self):
@ -130,10 +129,10 @@ class TestColorDialog(TestCase):
widget.on_clicked()
# THEN: change_color should not have been called and the colorChanged signal should not have been emitted
self.assertFalse(self.mocked_change_color.called,
'change_color should not have been called with an invalid color')
self.assertFalse(self.mocked_color_changed.emit.called,
'colorChange signal should not have been emitted with an invalid color')
assert self.mocked_change_color.called is False, \
'change_color should not have been called with an invalid color'
assert self.mocked_color_changed.emit.called is False, \
'colorChange signal should not have been emitted with an invalid color'
def test_on_clicked_same_color(self):
"""
@ -152,10 +151,10 @@ class TestColorDialog(TestCase):
widget.on_clicked()
# THEN: change_color should not have been called and the colorChanged signal should not have been emitted
self.assertFalse(self.mocked_change_color.called,
'change_color should not have been called when the color has not changed')
self.assertFalse(self.mocked_color_changed.emit.called,
'colorChange signal should not have been emitted when the color has not changed')
assert self.mocked_change_color.called is False, \
'change_color should not have been called when the color has not changed'
assert self.mocked_color_changed.emit.called is False, \
'colorChange signal should not have been emitted when the color has not changed'
def test_on_clicked_new_color(self):
"""

View File

@ -22,7 +22,7 @@ class TestFileDialogPatches(TestCase):
instance = FileDialog()
# THEN: The instance should be an instance of QFileDialog
self.assertIsInstance(instance, QtWidgets.QFileDialog)
assert isinstance(instance, QtWidgets.QFileDialog)
def test_get_existing_directory_user_abort(self):
"""
@ -34,7 +34,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getExistingDirectory()
# THEN: The result should be None
self.assertEqual(result, None)
assert result is None
def test_get_existing_directory_user_accepts(self):
"""
@ -47,7 +47,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getExistingDirectory()
# THEN: getExistingDirectory() should return a Path object pointing to the chosen file
self.assertEqual(result, Path('test', 'dir'))
assert result == Path('test', 'dir')
def test_get_existing_directory_param_order(self):
"""
@ -77,7 +77,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getOpenFileName()
# THEN: First value should be None
self.assertEqual(result[0], None)
assert result[0] is None
def test_get_open_file_name_user_accepts(self):
"""
@ -92,7 +92,7 @@ class TestFileDialogPatches(TestCase):
# THEN: getOpenFileName() should return a tuple with the first value set to a Path object pointing to the
# chosen file
self.assertEqual(result[0], Path('test', 'chosen.file'))
assert result[0] == Path('test', 'chosen.file')
def test_get_open_file_name_selected_filter(self):
"""
@ -104,7 +104,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getOpenFileName()
# THEN: getOpenFileName() should return a tuple with the second value set to a the selected filter
self.assertEqual(result[1], 'selected filter')
assert result[1] == 'selected filter'
def test_get_open_file_names_user_abort(self):
"""
@ -117,7 +117,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getOpenFileNames()
# THEN: First value should be an empty list
self.assertEqual(result[0], [])
assert result[0] == []
def test_get_open_file_names_user_accepts(self):
"""
@ -132,7 +132,7 @@ class TestFileDialogPatches(TestCase):
# THEN: getOpenFileNames() should return a tuple with the first value set to a list of Path objects pointing
# to the chosen file
self.assertEqual(result[0], [Path('test', 'chosen.file1'), Path('test', 'chosen.file2')])
assert result[0] == [Path('test', 'chosen.file1'), Path('test', 'chosen.file2')]
def test_get_open_file_names_selected_filter(self):
"""
@ -145,7 +145,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getOpenFileNames()
# THEN: getOpenFileNames() should return a tuple with the second value set to a the selected filter
self.assertEqual(result[1], 'selected filter')
assert result[1] == 'selected filter'
def test_get_save_file_name_user_abort(self):
"""
@ -158,7 +158,7 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getSaveFileName()
# THEN: First value should be None
self.assertEqual(result[0], None)
assert result[0] is None
def test_get_save_file_name_user_accepts(self):
"""
@ -173,7 +173,7 @@ class TestFileDialogPatches(TestCase):
# THEN: getSaveFileName() should return a tuple with the first value set to a Path object pointing to the
# chosen file
self.assertEqual(result[0], Path('test', 'chosen.file'))
assert result[0] == Path('test', 'chosen.file')
def test_get_save_file_name_selected_filter(self):
"""
@ -185,4 +185,4 @@ class TestFileDialogPatches(TestCase):
result = FileDialog.getSaveFileName()
# THEN: getSaveFileName() should return a tuple with the second value set to a the selected filter
self.assertEqual(result[1], 'selected filter')
assert result[1] == 'selected filter'

View File

@ -27,9 +27,9 @@ from unittest import TestCase
from unittest.mock import MagicMock, PropertyMock, patch
from openlp.core.common.path import Path
from openlp.core.widgets.edits import PathEdit
from openlp.core.widgets.enums import PathEditType
from openlp.core.widgets.dialogs import FileDialog
from openlp.core.widgets.edits import PathEdit
class TestPathEdit(TestCase):
@ -49,7 +49,7 @@ class TestPathEdit(TestCase):
# WHEN: Reading the `path` property
# THEN: The value that we set should be returned
self.assertEqual(self.widget.path, Path('getter', 'test', 'pat.h'))
assert self.widget.path == Path('getter', 'test', 'pat.h')
def test_path_setter(self):
"""
@ -63,7 +63,7 @@ class TestPathEdit(TestCase):
# THEN: The `_path` instance variable should be set with the test data. The `line_edit` text and tooltip
# should have also been set.
self.assertEqual(self.widget._path, Path('setter', 'test', 'pat.h'))
assert self.widget._path == Path('setter', 'test', 'pat.h')
self.widget.line_edit.setToolTip.assert_called_once_with(os.path.join('setter', 'test', 'pat.h'))
self.widget.line_edit.setText.assert_called_once_with(os.path.join('setter', 'test', 'pat.h'))
@ -74,7 +74,7 @@ class TestPathEdit(TestCase):
# GIVEN: An instance of PathEdit
# WHEN: Reading the `path` property
# THEN: The default value should be returned
self.assertEqual(self.widget.path_type, PathEditType.Files)
assert self.widget.path_type == PathEditType.Files
def test_path_type_setter(self):
"""
@ -88,7 +88,7 @@ class TestPathEdit(TestCase):
# THEN: The `_path_type` instance variable should be set with the test data and not the default. The
# update_button_tool_tips should have been called.
self.assertEqual(self.widget._path_type, PathEditType.Directories)
assert self.widget._path_type == PathEditType.Directories
mocked_update_button_tool_tips.assert_called_once_with()
def test_update_button_tool_tips_directories(self):
@ -139,7 +139,7 @@ class TestPathEdit(TestCase):
mocked_get_existing_directory.assert_called_once_with(self.widget, 'Select Directory',
Path('test', 'path'),
FileDialog.ShowDirsOnly)
self.assertFalse(mocked_get_open_file_name.called)
assert mocked_get_open_file_name.called is False
def test_on_browse_button_clicked_directory_custom_caption(self):
"""
@ -162,7 +162,7 @@ class TestPathEdit(TestCase):
mocked_get_existing_directory.assert_called_once_with(self.widget, 'Directory Caption',
Path('test', 'path'),
FileDialog.ShowDirsOnly)
self.assertFalse(mocked_get_open_file_name.called)
assert mocked_get_open_file_name.called is False
def test_on_browse_button_clicked_file(self):
"""
@ -181,7 +181,7 @@ class TestPathEdit(TestCase):
# THEN: The FileDialog.getOpenFileName should have been called with the default caption
mocked_get_open_file_name.assert_called_once_with(self.widget, 'Select File', Path('test', 'pat.h'),
self.widget.filters)
self.assertFalse(mocked_get_existing_directory.called)
assert mocked_get_existing_directory.called is False
def test_on_browse_button_clicked_file_custom_caption(self):
"""
@ -203,7 +203,7 @@ class TestPathEdit(TestCase):
# THEN: The FileDialog.getOpenFileName should have been called with the custom caption
mocked_get_open_file_name.assert_called_once_with(self.widget, 'File Caption', Path('test', 'pat.h'),
self.widget.filters)
self.assertFalse(mocked_get_existing_directory.called)
assert mocked_get_existing_directory.called is False
def test_on_browse_button_clicked_user_cancels(self):
"""
@ -219,7 +219,7 @@ class TestPathEdit(TestCase):
self.widget.on_browse_button_clicked()
# THEN: normpath should not have been called
self.assertTrue(mocked_get_open_file_name.called)
assert mocked_get_open_file_name.called is True
def test_on_browse_button_clicked_user_accepts(self):
"""
@ -236,8 +236,8 @@ class TestPathEdit(TestCase):
self.widget.on_browse_button_clicked()
# THEN: normpath and `on_new_path` should have been called
self.assertTrue(mocked_get_open_file_name.called)
self.assertTrue(self.widget.on_new_path.called)
assert mocked_get_open_file_name.called is True
assert self.widget.on_new_path.called is True
def test_on_revert_button_clicked(self):
"""
@ -280,7 +280,7 @@ class TestPathEdit(TestCase):
self.widget.on_new_path(Path('/old', 'test', 'pat.h'))
# THEN: The `pathChanged` signal should not be emitted
self.assertFalse(self.widget.pathChanged.emit.called)
assert self.widget.pathChanged.emit.called is False
def test_on_new_path_change(self):
"""

View File

@ -124,8 +124,8 @@ class TestListPreviewWidget(TestCase):
list_preview_widget = ListPreviewWidget(None, 1)
# THEN: The object is not None, and the _setup() method was called.
self.assertIsNotNone(list_preview_widget, 'The ListPreviewWidget object should not be None')
self.assertEquals(list_preview_widget.screen_ratio, 1, 'Should not be called')
assert list_preview_widget is not None, 'The ListPreviewWidget object should not be None'
assert list_preview_widget.screen_ratio == 1, 'Should not be called'
@patch(u'openlp.core.widgets.views.ListPreviewWidget.image_manager')
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
@ -169,7 +169,7 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.replace_service_item(mocked_cmd_service_item, 200, 0)
# THEN: The ImageManager should be called in the appriopriate manner for each service item.
self.assertEquals(mocked_image_manager.get_image.call_count, 4, 'Should be called once for each slide')
assert mocked_image_manager.get_image.call_count == 4, 'Should be called once for each slide'
calls = [call('TEST1', ImageSource.ImagePlugin), call('TEST2', ImageSource.ImagePlugin),
call('TEST3', ImageSource.CommandPlugins), call('TEST4', ImageSource.CommandPlugins)]
mocked_image_manager.get_image.assert_has_calls(calls)
@ -203,8 +203,8 @@ class TestListPreviewWidget(TestCase):
# THEN: setRowHeight() should not be called, while resizeRowsToContents() should be called twice
# (once each in __recalculate_layout and replace_service_item)
self.assertEquals(mocked_resizeRowsToContents.call_count, 2, 'Should be called')
self.assertEquals(mocked_setRowHeight.call_count, 0, 'Should not be called')
assert mocked_resizeRowsToContents.call_count == 2, 'Should be called'
assert mocked_setRowHeight.call_count == 0, 'Should not be called'
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
@ -238,8 +238,8 @@ class TestListPreviewWidget(TestCase):
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
# twice for each slide.
self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called')
self.assertEquals(mocked_setRowHeight.call_count, 6, 'Should be called 3 times for each slide')
assert mocked_resizeRowsToContents.call_count == 0, 'Should not be called'
assert mocked_setRowHeight.call_count == 6, 'Should be called 3 times for each slide'
calls = [call(0, 200), call(1, 200), call(0, 400), call(1, 400), call(0, 400), call(1, 400)]
mocked_setRowHeight.assert_has_calls(calls)
@ -273,8 +273,8 @@ class TestListPreviewWidget(TestCase):
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
# twice for each slide.
self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called')
self.assertEquals(mocked_setRowHeight.call_count, 4, 'Should be called twice for each slide')
assert mocked_resizeRowsToContents.call_count == 0, 'Should not be called'
assert mocked_setRowHeight.call_count == 4, 'Should be called twice for each slide'
calls = [call(0, 100), call(1, 100), call(0, 100), call(1, 100)]
mocked_setRowHeight.assert_has_calls(calls)
@ -311,8 +311,8 @@ class TestListPreviewWidget(TestCase):
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
# twice for each slide.
self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called')
self.assertEquals(mocked_setRowHeight.call_count, 6, 'Should be called 3 times for each slide')
assert mocked_resizeRowsToContents.call_count == 0, 'Should not be called'
assert mocked_setRowHeight.call_count == 6, 'Should be called 3 times for each slide'
calls = [call(0, 100), call(1, 100), call(0, 150), call(1, 150), call(0, 100), call(1, 100)]
mocked_setRowHeight.assert_has_calls(calls)
@ -348,7 +348,7 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.row_resized(0, 100, 150)
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called')
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
@ -385,7 +385,7 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.row_resized(0, 100, 150)
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called')
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
@ -488,10 +488,10 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.change_slide(0)
# THEN: no further functions should be called
self.assertEquals(mocked_slide_count.call_count, 0, 'Should not be called')
self.assertEquals(mocked_scrollToItem.call_count, 0, 'Should not be called')
self.assertEquals(mocked_selectRow.call_count, 0, 'Should not be called')
self.assertEquals(mocked_item.call_count, 0, 'Should not be called')
assert mocked_slide_count.call_count == 0, 'Should not be called'
assert mocked_scrollToItem.call_count == 0, 'Should not be called'
assert mocked_selectRow.call_count == 0, 'Should not be called'
assert mocked_item.call_count == 0, 'Should not be called'
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
@ -516,10 +516,10 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.change_slide(0)
# THEN: no further functions should be called
self.assertEquals(mocked_slide_count.call_count, 3, 'Should be called')
self.assertEquals(mocked_scrollToItem.call_count, 2, 'Should be called')
self.assertEquals(mocked_selectRow.call_count, 2, 'Should be called')
self.assertEquals(mocked_item.call_count, 2, 'Should be called')
assert mocked_slide_count.call_count == 3, 'Should be called'
assert mocked_scrollToItem.call_count == 2, 'Should be called'
assert mocked_selectRow.call_count == 2, 'Should be called'
assert mocked_item.call_count == 2, 'Should be called'
calls = [call(0, 0), call(0, 0)]
mocked_item.assert_has_calls(calls)
@ -548,10 +548,10 @@ class TestListPreviewWidget(TestCase):
list_preview_widget.change_slide(1)
# THEN: no further functions should be called
self.assertEquals(mocked_slide_count.call_count, 3, 'Should be called')
self.assertEquals(mocked_scrollToItem.call_count, 3, 'Should be called')
self.assertEquals(mocked_selectRow.call_count, 3, 'Should be called')
self.assertEquals(mocked_item.call_count, 3, 'Should be called')
assert mocked_slide_count.call_count == 3, 'Should be called'
assert mocked_scrollToItem.call_count == 3, 'Should be called'
assert mocked_selectRow.call_count == 3, 'Should be called'
assert mocked_item.call_count == 3, 'Should be called'
calls = [call(0, 0), call(1, 0), call(2, 0)]
mocked_item.assert_has_calls(calls)
@ -571,7 +571,7 @@ class TestListWidgetWithDnD(TestCase):
widget.clear()
# THEN: The results text should be the standard 'no results' text.
self.assertEqual(widget.no_results_text, UiStrings().NoResults)
assert widget.no_results_text == UiStrings().NoResults
def test_clear_search_while_typing(self):
"""
@ -584,7 +584,7 @@ class TestListWidgetWithDnD(TestCase):
widget.clear(search_while_typing=True)
# THEN: The results text should be the 'short results' text.
self.assertEqual(widget.no_results_text, UiStrings().ShortResults)
assert widget.no_results_text == UiStrings().ShortResults
def test_all_items_no_list_items(self):
"""
@ -599,8 +599,8 @@ class TestListWidgetWithDnD(TestCase):
result = widget.allItems()
# THEN: An instance of a Generator object should be returned. The generator should not yeild any results
self.assertIsInstance(result, GeneratorType)
self.assertEqual(list(result), [])
assert isinstance(result, GeneratorType)
assert list(result) == []
def test_all_items_list_items(self):
"""
@ -615,8 +615,8 @@ class TestListWidgetWithDnD(TestCase):
result = widget.allItems()
# THEN: An instance of a Generator object should be returned. The generator should not yeild any results
self.assertIsInstance(result, GeneratorType)
self.assertEqual(list(result), [5, 3])
assert isinstance(result, GeneratorType)
assert list(result) == [5, 3]
def test_paint_event(self):
"""
@ -635,7 +635,7 @@ class TestListWidgetWithDnD(TestCase):
# THEN: The overridden paintEvnet should have been called
mocked_paint_event.assert_called_once_with(mocked_event)
self.assertFalse(mocked_viewport.called)
assert mocked_viewport.called is False
def test_paint_event_no_items(self):
"""

View File

@ -23,7 +23,7 @@
Functional tests to test the Impress class and related methods.
"""
from unittest import TestCase
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
import shutil
from tempfile import mkdtemp
@ -72,6 +72,60 @@ class TestImpressController(TestCase, TestMixin):
self.assertEqual('Impress', controller.name,
'The name of the presentation controller should be correct')
@patch('openlp.plugins.presentations.lib.impresscontroller.log')
def test_check_available(self, mocked_log):
"""
Test `ImpressController.check_available` on Windows
"""
# GIVEN: An instance of :class:`ImpressController`
controller = ImpressController(plugin=self.mock_plugin)
# WHEN: `check_available` is called on Windows and `get_com_servicemanager` returns None
with patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=True), \
patch.object(controller, 'get_com_servicemanager', return_value=None) as mocked_get_com_servicemanager:
result = controller.check_available()
# THEN: `check_available` should return False
assert mocked_get_com_servicemanager.called is True
assert result is False
@patch('openlp.plugins.presentations.lib.impresscontroller.log')
def test_check_available1(self, mocked_log):
"""
Test `ImpressController.check_available` on Windows
"""
# GIVEN: An instance of :class:`ImpressController`
controller = ImpressController(plugin=self.mock_plugin)
# WHEN: `check_available` is called on Windows and `get_com_servicemanager` returns an object
mocked_com_object = MagicMock()
with patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=True), \
patch.object(controller, 'get_com_servicemanager', return_value=mocked_com_object) \
as mocked_get_com_servicemanager:
result = controller.check_available()
# THEN: `check_available` should return True
assert mocked_get_com_servicemanager.called is True
assert result is True
@patch('openlp.plugins.presentations.lib.impresscontroller.log')
@patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=False)
def test_check_available2(self, mocked_is_win, mocked_log):
"""
Test `ImpressController.check_available` when not on Windows
"""
# GIVEN: An instance of :class:`ImpressController`
controller = ImpressController(plugin=self.mock_plugin)
# WHEN: `check_available` is called on Windows and `uno_available` is True
with patch('openlp.plugins.presentations.lib.impresscontroller.uno_available', True), \
patch.object(controller, 'get_com_servicemanager') as mocked_get_com_servicemanager:
result = controller.check_available()
# THEN: `check_available` should return True
assert mocked_get_com_servicemanager.called is False
assert result is True
class TestImpressDocument(TestCase):
"""

View File

@ -109,7 +109,7 @@ class EasyWorshipSongImportLogger(EasyWorshipSongImport):
self._title_assignment_list.append(title)
class TestFieldDesc:
class DataTestFieldDesc:
def __init__(self, name, field_type, size):
self.name = name
self.field_type = field_type
@ -121,11 +121,11 @@ CODE_PAGE_MAPPINGS = [
(852, 'cp1250'), (737, 'cp1253'), (775, 'cp1257'), (855, 'cp1251'), (857, 'cp1254'),
(866, 'cp1251'), (869, 'cp1253'), (862, 'cp1255'), (874, 'cp874')]
TEST_FIELD_DESCS = [
TestFieldDesc('Title', FieldType.String, 50),
TestFieldDesc('Text Percentage Bottom', FieldType.Int16, 2), TestFieldDesc('RecID', FieldType.Int32, 4),
TestFieldDesc('Default Background', FieldType.Logical, 1), TestFieldDesc('Words', FieldType.Memo, 250),
TestFieldDesc('Words', FieldType.Memo, 250), TestFieldDesc('BK Bitmap', FieldType.Blob, 10),
TestFieldDesc('Last Modified', FieldType.Timestamp, 10)]
DataTestFieldDesc('Title', FieldType.String, 50),
DataTestFieldDesc('Text Percentage Bottom', FieldType.Int16, 2), DataTestFieldDesc('RecID', FieldType.Int32, 4),
DataTestFieldDesc('Default Background', FieldType.Logical, 1), DataTestFieldDesc('Words', FieldType.Memo, 250),
DataTestFieldDesc('Words', FieldType.Memo, 250), DataTestFieldDesc('BK Bitmap', FieldType.Blob, 10),
DataTestFieldDesc('Last Modified', FieldType.Timestamp, 10)]
TEST_FIELDS = [
b'A Heart Like Thine\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', 32868, 2147483750,
129, b'{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}'

View File

@ -34,7 +34,7 @@ except ImportError:
CAN_RUN_TESTS = False
class TestRecord(object):
class DBTestRecord(object):
"""
Microsoft Access Driver is not available on non Microsoft Systems for this reason the :class:`TestRecord` is used
to simulate a recordset that would be returned by pyobdc.
@ -66,12 +66,12 @@ if CAN_RUN_TESTS:
self._title_assignment_list.append(title)
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
TestRecord(1, 'AUTHOR', 'John Newton'),
TestRecord(1, 'CCLISONGID', '12345'),
TestRecord(1, 'COMMENTS', 'The original version'),
TestRecord(1, 'COPY', 'Public Domain'),
TestRecord(
RECORDSET_TEST_DATA = [DBTestRecord(1, 'TITLE', 'Amazing Grace'),
DBTestRecord(1, 'AUTHOR', 'John Newton'),
DBTestRecord(1, 'CCLISONGID', '12345'),
DBTestRecord(1, 'COMMENTS', 'The original version'),
DBTestRecord(1, 'COPY', 'Public Domain'),
DBTestRecord(
1, 'LYRICS',
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
'I once was lost,&crlf;but now am found;&crlf;Was blind, but now I see.&crlf;&crlf;'
@ -88,8 +88,8 @@ RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
'Shall be forever mine.&crlf;&crlf;When we\'ve been there&crlf;ten thousand years,&crlf;'
'Bright shining as the sun,&crlf;We\'ve no less days to&crlf;sing God\'s praise&crlf;'
'Than when we\'d first begun.&crlf;&crlf;'),
TestRecord(2, 'TITLE', 'Beautiful Garden Of Prayer, The'),
TestRecord(
DBTestRecord(2, 'TITLE', 'Beautiful Garden Of Prayer, The'),
DBTestRecord(
2, 'LYRICS',
'There\'s a garden where&crlf;Jesus is waiting,&crlf;'
'There\'s a place that&crlf;is wondrously fair,&crlf;For it glows with the&crlf;'