def test_font_name_changed_int(self): # GIVEN: An instance of FontSelectPage with a mocked out "font_name_changed" signal instance = FontSelectPage() instance.font_name_changed = MagicMock() # WHEN: The font name changes instance._on_font_name_changed(5) # THEN: The signal should be emitted with the correct value assert instance.font_name_changed.emit.call_count == 0
def test_font_color_changed(self): # GIVEN: An instance of FontSelectPage with a mocked out "font_color_changed" signal instance = FontSelectPage() instance.font_color_changed = MagicMock() # WHEN: The font color changes instance._on_font_color_changed('#fff') # THEN: The signal should be emitted with the correct value instance.font_color_changed.emit.assert_called_once_with('#fff')
def test_shadow_size_changed(self): # GIVEN: An instance of FontSelectPage with a mocked out "shadow_size_changed" signal instance = FontSelectPage() instance.shadow_size_changed = MagicMock() # WHEN: The font name changes instance._on_shadow_size_changed(5) # THEN: The signal should be emitted with the correct value instance.shadow_size_changed.emit.assert_called_once_with(5)
def test_is_italic_changed(self): # GIVEN: An instance of FontSelectPage with a mocked out "style_italic_changed" signal instance = FontSelectPage() instance.is_italic_changed = MagicMock() # WHEN: The font name changes instance._on_style_italic_toggled(False) # THEN: The signal should be emitted with the correct value instance.is_italic_changed.emit.assert_called_once_with(False)
def test_set_shadow_color_property(self): """ Test setting the `shadow_color` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() # WHEN: The `shadow_color` property is set instance.shadow_color = '#fff' # THEN: The correct value should be set instance.shadow_color_button.color == '#fff'
def test_disable_missing_features(self): """ Test that the `disable_features` method correctly raises an error on a non-existent feature """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() mock_label = MagicMock() mock_control = MagicMock() instance.feature_widgets = {'test1': [mock_label, mock_control]} # WHEN: The "test" feature is disabled with pytest.raises(KeyError, match='No such feature'): instance.disable_features('test2')
def test_set_line_spacing_property(self): """ Test setting the `line_spacing` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.line_spacing_spinbox.setValue = MagicMock() # WHEN: The `line_spacing` property is set instance.line_spacing = 2 # THEN: The correct value should be set instance.line_spacing_spinbox.setValue.assert_called_once_with(2)
def test_set_is_italic_property(self): """ Test setting the `is_italic` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.style_italic_button.setChecked = MagicMock() # WHEN: The `is_italic` property is set instance.is_italic = False # THEN: The correct value should be set instance.style_italic_button.setChecked.assert_called_once_with(False)
def test_set_shadow_size_property(self): """ Test setting the `shadow_size` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.shadow_size_spinbox.setValue = MagicMock() # WHEN: The `shadow_size` property is set instance.shadow_size = 10 # THEN: The correct value should be set instance.shadow_size_spinbox.setValue.assert_called_once_with(10)
def test_set_is_shadow_enabled_property(self): """ Test setting the `is_shadow_enabled` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.shadow_groupbox.setChecked = MagicMock() # WHEN: The `is_shadow_enabled` property is set instance.is_shadow_enabled = True # THEN: The correct value should be set instance.shadow_groupbox.setChecked.assert_called_once_with(True)
def test_disable_features(self): """ Test that the `disable_features` method correctly disables widgets based on features """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() mock_label = MagicMock() mock_control = MagicMock() instance.feature_widgets = {'test': [mock_label, mock_control]} # WHEN: The "test" feature is disabled instance.disable_features('test') # THEN: "show()" is called on all the widgets mock_label.hide.assert_called_once() mock_control.hide.assert_called_once()
def test_init_(self): """ Test the initialisation of FontSelectPage """ # GIVEN: The FontSelectPage class # WHEN: Initialising FontSelectPage # THEN: We should have an instance of the widget with no errors FontSelectPage()
def test_set_font_name_property(self): """ Test setting the `font_name` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.font_name_combobox.setCurrentFont = MagicMock() # WHEN: The `font_name` property is set with patch('openlp.core.pages.fontselect.QtGui.QFont') as MockFont: mocked_font = MagicMock() MockFont.return_value = mocked_font instance.font_name = 'Serif' # THEN: The correct value should be set MockFont.assert_called_once_with('Serif') instance.font_name_combobox.setCurrentFont.assert_called_once_with( mocked_font)
def test_get_shadow_size_property(self): """ Test the `shadow_size` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.shadow_size_spinbox.value = MagicMock(return_value=5) # WHEN: The `shadow_size` propert is accessed result = instance.shadow_size # THEN: The value should be correct assert result == 5
def test_get_shadow_color_property(self): """ Test the `shadow_color` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.shadow_color_button.color = '#000' # WHEN: The `shadow_color` propert is accessed result = instance.shadow_color # THEN: The value should be correct assert result == '#000'
def test_get_is_shadow_enabled_property(self): """ Test the `is_shadow_enabled` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.shadow_groupbox.isChecked = MagicMock(return_value=False) # WHEN: The `is_shadow_enabled` propert is accessed result = instance.is_shadow_enabled # THEN: The value should be correct assert result is False
def test_get_line_spacing_property(self): """ Test the `line_spacing` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.line_spacing_spinbox.value = MagicMock(return_value=1) # WHEN: The `line_spacing` propert is accessed result = instance.line_spacing # THEN: The value should be correct assert result == 1
def test_get_is_italic_property(self): """ Test the `is_italic` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.style_italic_button.isChecked = MagicMock(return_value=True) # WHEN: The `is_italic` propert is accessed result = instance.is_italic # THEN: The value should be correct assert result is True
def test_get_font_name_property(self): """ Test the `font_name` property """ # GIVEN: An instance of FontSelectPage with some mocks instance = FontSelectPage() instance.font_name_combobox.currentFont = MagicMock( return_value=MagicMock(**{'family.return_value': 'Sans serif'})) # WHEN: The `font_name` propert is accessed result = instance.font_name # THEN: The value should be correct assert result == 'Sans serif'
class Ui_ThemeWizard(object): """ The Create/Edit theme wizard """ def setup_ui(self, theme_wizard): """ Set up the UI """ theme_wizard.setObjectName('OpenLP.ThemeWizard') theme_wizard.setWindowIcon(UiIcons().main_icon) theme_wizard.setModal(True) theme_wizard.setOptions(QtWidgets.QWizard.IndependentPages | QtWidgets.QWizard.NoBackButtonOnStartPage | QtWidgets.QWizard.HaveCustomButton1) theme_wizard.setFixedWidth(640) if is_macosx(): # pragma: no cover theme_wizard.setPixmap( QtWidgets.QWizard.BackgroundPixmap, QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) else: theme_wizard.setWizardStyle(QtWidgets.QWizard.ModernStyle) self.spacer = QtWidgets.QSpacerItem(10, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) # Welcome Page add_welcome_page(theme_wizard, ':/wizards/wizard_createtheme.bmp') # Background Page self.background_page = BackgroundPage() self.background_page.setObjectName('background_page') theme_wizard.addPage(self.background_page) # Main Area Page self.main_area_page = FontSelectPage() self.main_area_page.setObjectName('main_area_page') theme_wizard.addPage(self.main_area_page) # Footer Area Page self.footer_area_page = FontSelectPage() self.footer_area_page.setObjectName('footer_area_page') self.footer_area_page.disable_features(FontSelectPage.Outline, FontSelectPage.Shadow, FontSelectPage.LineSpacing) theme_wizard.addPage(self.footer_area_page) # Alignment Page self.alignment_page = AlignmentTransitionsPage() self.alignment_page.setObjectName('alignment_page') theme_wizard.addPage(self.alignment_page) # Area Position Page self.area_position_page = AreaPositionPage() self.area_position_page.setObjectName('area_position_page') theme_wizard.addPage(self.area_position_page) # Preview Page self.preview_page = QtWidgets.QWizardPage() self.preview_page.setObjectName('preview_page') self.preview_layout = QtWidgets.QVBoxLayout(self.preview_page) self.preview_layout.setObjectName('preview_layout') self.theme_name_layout = QtWidgets.QFormLayout() self.theme_name_layout.setObjectName('theme_name_layout') self.theme_name_label = QtWidgets.QLabel(self.preview_page) self.theme_name_label.setObjectName('theme_name_label') self.theme_name_edit = QtWidgets.QLineEdit(self.preview_page) self.theme_name_edit.setValidator( QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":<>+%]+'), self)) self.theme_name_edit.setObjectName('ThemeNameEdit') self.theme_name_layout.addRow(self.theme_name_label, self.theme_name_edit) self.preview_layout.addLayout(self.theme_name_layout) self.preview_area = QtWidgets.QWidget(self.preview_page) self.preview_area.setObjectName('PreviewArea') self.preview_area_layout = AspectRatioLayout( self.preview_area, 0.75) # Dummy ratio, will be update self.preview_area_layout.margin = 8 self.preview_area_layout.setSpacing(0) self.preview_area_layout.setObjectName('preview_web_layout') self.preview_box = ThemePreviewRenderer(self) self.preview_box.setObjectName('preview_box') self.preview_area_layout.addWidget(self.preview_box) self.preview_layout.addWidget(self.preview_area) theme_wizard.addPage(self.preview_page) self.retranslate_ui(theme_wizard) def retranslate_ui(self, theme_wizard): """ Translate the UI on the fly """ theme_wizard.setWindowTitle( translate('OpenLP.ThemeWizard', 'Theme Wizard')) text = translate('OpenLP.ThemeWizard', 'Welcome to the Theme Wizard') self.title_label.setText( '<span style="font-size:14pt; font-weight:600;">{text}</span>'. format(text=text)) self.information_label.setText( translate( 'OpenLP.ThemeWizard', 'This wizard will help you to create and edit your themes. Click the next ' 'button below to start the process by setting up your background.' )) self.background_page.setTitle( translate('OpenLP.ThemeWizard', 'Set Up Background')) self.background_page.setSubTitle( translate( 'OpenLP.ThemeWizard', 'Set up your theme\'s background ' 'according to the parameters below.')) self.main_area_page.setTitle( translate('OpenLP.ThemeWizard', 'Main Area Font Details')) self.main_area_page.setSubTitle( translate( 'OpenLP.ThemeWizard', 'Define the font and display ' 'characteristics for the Display text')) self.footer_area_page.setTitle( translate('OpenLP.ThemeWizard', 'Footer Area Font Details')) self.footer_area_page.setSubTitle( translate( 'OpenLP.ThemeWizard', 'Define the font and display ' 'characteristics for the Footer text')) self.alignment_page.setTitle( translate('OpenLP.ThemeWizard', 'Text Formatting Details')) self.alignment_page.setSubTitle( translate( 'OpenLP.ThemeWizard', 'Allows additional display ' 'formatting information to be defined')) self.area_position_page.setTitle( translate('OpenLP.ThemeWizard', 'Output Area Locations')) self.area_position_page.setSubTitle( translate( 'OpenLP.ThemeWizard', 'Allows you to change and move the' ' Main and Footer areas.')) theme_wizard.setOption(QtWidgets.QWizard.HaveCustomButton1, False) theme_wizard.setButtonText( QtWidgets.QWizard.CustomButton1, translate('OpenLP.ThemeWizard', 'Layout Preview')) self.preview_page.setTitle( translate('OpenLP.ThemeWizard', 'Preview and Save')) self.preview_page.setSubTitle( translate('OpenLP.ThemeWizard', 'Preview the theme and save it.')) self.theme_name_label.setText( translate('OpenLP.ThemeWizard', 'Theme name:'))
def setup_ui(self, theme_wizard): """ Set up the UI """ theme_wizard.setObjectName('OpenLP.ThemeWizard') theme_wizard.setWindowIcon(UiIcons().main_icon) theme_wizard.setModal(True) theme_wizard.setOptions(QtWidgets.QWizard.IndependentPages | QtWidgets.QWizard.NoBackButtonOnStartPage | QtWidgets.QWizard.HaveCustomButton1) theme_wizard.setFixedWidth(640) if is_macosx(): # pragma: no cover theme_wizard.setPixmap( QtWidgets.QWizard.BackgroundPixmap, QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) else: theme_wizard.setWizardStyle(QtWidgets.QWizard.ModernStyle) self.spacer = QtWidgets.QSpacerItem(10, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) # Welcome Page add_welcome_page(theme_wizard, ':/wizards/wizard_createtheme.bmp') # Background Page self.background_page = BackgroundPage() self.background_page.setObjectName('background_page') theme_wizard.addPage(self.background_page) # Main Area Page self.main_area_page = FontSelectPage() self.main_area_page.setObjectName('main_area_page') theme_wizard.addPage(self.main_area_page) # Footer Area Page self.footer_area_page = FontSelectPage() self.footer_area_page.setObjectName('footer_area_page') self.footer_area_page.disable_features(FontSelectPage.Outline, FontSelectPage.Shadow, FontSelectPage.LineSpacing) theme_wizard.addPage(self.footer_area_page) # Alignment Page self.alignment_page = AlignmentTransitionsPage() self.alignment_page.setObjectName('alignment_page') theme_wizard.addPage(self.alignment_page) # Area Position Page self.area_position_page = AreaPositionPage() self.area_position_page.setObjectName('area_position_page') theme_wizard.addPage(self.area_position_page) # Preview Page self.preview_page = QtWidgets.QWizardPage() self.preview_page.setObjectName('preview_page') self.preview_layout = QtWidgets.QVBoxLayout(self.preview_page) self.preview_layout.setObjectName('preview_layout') self.theme_name_layout = QtWidgets.QFormLayout() self.theme_name_layout.setObjectName('theme_name_layout') self.theme_name_label = QtWidgets.QLabel(self.preview_page) self.theme_name_label.setObjectName('theme_name_label') self.theme_name_edit = QtWidgets.QLineEdit(self.preview_page) self.theme_name_edit.setValidator( QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":<>+%]+'), self)) self.theme_name_edit.setObjectName('ThemeNameEdit') self.theme_name_layout.addRow(self.theme_name_label, self.theme_name_edit) self.preview_layout.addLayout(self.theme_name_layout) self.preview_area = QtWidgets.QWidget(self.preview_page) self.preview_area.setObjectName('PreviewArea') self.preview_area_layout = AspectRatioLayout( self.preview_area, 0.75) # Dummy ratio, will be update self.preview_area_layout.margin = 8 self.preview_area_layout.setSpacing(0) self.preview_area_layout.setObjectName('preview_web_layout') self.preview_box = ThemePreviewRenderer(self) self.preview_box.setObjectName('preview_box') self.preview_area_layout.addWidget(self.preview_box) self.preview_layout.addWidget(self.preview_area) theme_wizard.addPage(self.preview_page) self.retranslate_ui(theme_wizard)