forked from openlp/openlp
fix up widgets
This commit is contained in:
parent
2ccec6088d
commit
5764551e3e
@ -23,13 +23,12 @@
|
||||
Provides the generic functions for interfacing plugins with the Media Manager.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
|
||||
from openlp.core.common.i18n import UiStrings, translate
|
||||
from openlp.core.common.path import Path, path_to_str, str_to_path
|
||||
from openlp.core.common.path import path_to_str, str_to_path
|
||||
from openlp.core.common.mixins import RegistryProperties
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.common.settings import Settings
|
||||
|
@ -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'
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -71,8 +71,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')
|
||||
@ -116,7 +116,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)
|
||||
@ -150,8 +150,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')
|
||||
@ -185,8 +185,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)
|
||||
|
||||
@ -220,8 +220,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)
|
||||
|
||||
@ -258,8 +258,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)
|
||||
|
||||
@ -295,7 +295,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')
|
||||
@ -332,7 +332,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')
|
||||
@ -435,10 +435,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')
|
||||
@ -463,10 +463,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)
|
||||
|
||||
@ -495,10 +495,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)
|
||||
|
||||
@ -518,7 +518,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):
|
||||
"""
|
||||
@ -531,7 +531,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):
|
||||
"""
|
||||
@ -546,8 +546,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):
|
||||
"""
|
||||
@ -562,8 +562,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):
|
||||
"""
|
||||
@ -582,7 +582,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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user