1
0
mirror of https://gitlab.com/openlp/openlp.git synced 2024-09-28 19:07:35 +00:00

more ui bits

This commit is contained in:
Tim Bentley 2017-12-20 21:18:44 +00:00
parent ffb23a4575
commit bb25804165
5 changed files with 72 additions and 68 deletions

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 SlideController, LiveController, PreviewController
from openlp.core.ui.slidecontroller import InfoLabel, WIDE_MENU, NON_TEXT_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'