← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/cleanups into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/cleanups into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/cleanups/+merge/152781

Fix an import issue after the last cleanup.

- Fix an issue with an import that changed in the last cleanup effort (as a side note, the plugins manager test is a good one to use to check for import regressions).
- Clean up some test comments.
-- 
https://code.launchpad.net/~raoul-snyman/openlp/cleanups/+merge/152781
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/cleanups into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/editsongform.py'
--- openlp/plugins/songs/forms/editsongform.py	2013-03-08 08:14:39 +0000
+++ openlp/plugins/songs/forms/editsongform.py	2013-03-11 21:28:19 +0000
@@ -578,9 +578,9 @@
         self.verse_delete_button.setEnabled(True)
 
     def on_verse_add_button_clicked(self):
-        self.verse_form.setVerse(u'', True)
+        self.verse_form.set_verse(u'', True)
         if self.verse_form.exec_():
-            after_text, verse_tag, verse_num = self.verse_form.getVerse()
+            after_text, verse_tag, verse_num = self.verse_form.get_verse()
             verse_def = u'%s%s' % (verse_tag, verse_num)
             item = QtGui.QTableWidgetItem(after_text)
             item.setData(QtCore.Qt.UserRole, verse_def)
@@ -596,9 +596,9 @@
         if item:
             temp_text = item.text()
             verse_id = item.data(QtCore.Qt.UserRole)
-            self.verse_form.setVerse(temp_text, True, verse_id)
+            self.verse_form.set_verse(temp_text, True, verse_id)
             if self.verse_form.exec_():
-                after_text, verse_tag, verse_num = self.verse_form.getVerse()
+                after_text, verse_tag, verse_num = self.verse_form.get_verse()
                 verse_def = u'%s%s' % (verse_tag, verse_num)
                 item.setData(QtCore.Qt.UserRole, verse_def)
                 item.setText(after_text)
@@ -630,12 +630,12 @@
                 verse_list += u'---[%s:%s]---\n' % (verse_tag, verse_num)
                 verse_list += item.text()
                 verse_list += u'\n'
-            self.verse_form.setVerse(verse_list)
+            self.verse_form.set_verse(verse_list)
         else:
-            self.verse_form.setVerse(u'')
+            self.verse_form.set_verse(u'')
         if not self.verse_form.exec_():
             return
-        verse_list = self.verse_form.getVerseAll()
+        verse_list = self.verse_form.get_all_verses()
         verse_list = unicode(verse_list.replace(u'\r\n', u'\n'))
         self.verse_list_widget.clear()
         self.verse_list_widget.setRowCount(0)

=== modified file 'openlp/plugins/songs/forms/editversedialog.py'
--- openlp/plugins/songs/forms/editversedialog.py	2013-02-24 18:13:50 +0000
+++ openlp/plugins/songs/forms/editversedialog.py	2013-03-11 21:28:19 +0000
@@ -33,56 +33,57 @@
 from openlp.core.lib.ui import UiStrings, create_button_box
 from openlp.plugins.songs.lib import VerseType
 
+
 class Ui_EditVerseDialog(object):
-    def setupUi(self, editVerseDialog):
-        editVerseDialog.setObjectName(u'editVerseDialog')
-        editVerseDialog.resize(400, 400)
-        editVerseDialog.setModal(True)
-        self.dialogLayout = QtGui.QVBoxLayout(editVerseDialog)
-        self.dialogLayout.setObjectName(u'dialog_layout')
-        self.verseTextEdit = SpellTextEdit(editVerseDialog)
-        self.verseTextEdit.setObjectName(u'verseTextEdit')
-        self.dialogLayout.addWidget(self.verseTextEdit)
-        self.verseTypeLayout = QtGui.QHBoxLayout()
-        self.verseTypeLayout.setObjectName(u'verseTypeLayout')
-        self.splitButton = QtGui.QPushButton(editVerseDialog)
-        self.splitButton.setIcon(build_icon(u':/general/general_add.png'))
-        self.splitButton.setObjectName(u'splitButton')
-        self.verseTypeLayout.addWidget(self.splitButton)
-        self.verseTypeLabel = QtGui.QLabel(editVerseDialog)
-        self.verseTypeLabel.setObjectName(u'verseTypeLabel')
-        self.verseTypeLayout.addWidget(self.verseTypeLabel)
-        self.verseTypeComboBox = QtGui.QComboBox(editVerseDialog)
-        self.verseTypeComboBox.addItems([u'', u'', u'', u'', u'', u'', u''])
-        self.verseTypeComboBox.setObjectName(u'verseTypeComboBox')
-        self.verseTypeLabel.setBuddy(self.verseTypeComboBox)
-        self.verseTypeLayout.addWidget(self.verseTypeComboBox)
-        self.verseNumberBox = QtGui.QSpinBox(editVerseDialog)
-        self.verseNumberBox.setMinimum(1)
-        self.verseNumberBox.setObjectName(u'verseNumberBox')
-        self.verseTypeLayout.addWidget(self.verseNumberBox)
-        self.insertButton = QtGui.QPushButton(editVerseDialog)
-        self.insertButton.setIcon(build_icon(u':/general/general_add.png'))
-        self.insertButton.setObjectName(u'insertButton')
-        self.verseTypeLayout.addWidget(self.insertButton)
-        self.verseTypeLayout.addStretch()
-        self.dialogLayout.addLayout(self.verseTypeLayout)
-        self.button_box = create_button_box(editVerseDialog, u'button_box', [u'cancel', u'ok'])
-        self.dialogLayout.addWidget(self.button_box)
-        self.retranslateUi(editVerseDialog)
+    def setupUi(self, edit_verse_dialog):
+        edit_verse_dialog.setObjectName(u'editVerseDialog')
+        edit_verse_dialog.resize(400, 400)
+        edit_verse_dialog.setModal(True)
+        self.dialog_layout = QtGui.QVBoxLayout(edit_verse_dialog)
+        self.dialog_layout.setObjectName(u'dialog_layout')
+        self.verse_text_edit = SpellTextEdit(edit_verse_dialog)
+        self.verse_text_edit.setObjectName(u'verseTextEdit')
+        self.dialog_layout.addWidget(self.verse_text_edit)
+        self.verse_type_layout = QtGui.QHBoxLayout()
+        self.verse_type_layout.setObjectName(u'verseTypeLayout')
+        self.split_button = QtGui.QPushButton(edit_verse_dialog)
+        self.split_button.setIcon(build_icon(u':/general/general_add.png'))
+        self.split_button.setObjectName(u'splitButton')
+        self.verse_type_layout.addWidget(self.split_button)
+        self.verse_type_label = QtGui.QLabel(edit_verse_dialog)
+        self.verse_type_label.setObjectName(u'verseTypeLabel')
+        self.verse_type_layout.addWidget(self.verse_type_label)
+        self.verse_type_combo_box = QtGui.QComboBox(edit_verse_dialog)
+        self.verse_type_combo_box.addItems([u'', u'', u'', u'', u'', u'', u''])
+        self.verse_type_combo_box.setObjectName(u'verseTypeComboBox')
+        self.verse_type_label.setBuddy(self.verse_type_combo_box)
+        self.verse_type_layout.addWidget(self.verse_type_combo_box)
+        self.verse_number_box = QtGui.QSpinBox(edit_verse_dialog)
+        self.verse_number_box.setMinimum(1)
+        self.verse_number_box.setObjectName(u'verseNumberBox')
+        self.verse_type_layout.addWidget(self.verse_number_box)
+        self.insert_button = QtGui.QPushButton(edit_verse_dialog)
+        self.insert_button.setIcon(build_icon(u':/general/general_add.png'))
+        self.insert_button.setObjectName(u'insertButton')
+        self.verse_type_layout.addWidget(self.insert_button)
+        self.verse_type_layout.addStretch()
+        self.dialog_layout.addLayout(self.verse_type_layout)
+        self.button_box = create_button_box(edit_verse_dialog, u'button_box', [u'cancel', u'ok'])
+        self.dialog_layout.addWidget(self.button_box)
+        self.retranslateUi(edit_verse_dialog)
 
-    def retranslateUi(self, editVerseDialog):
-        editVerseDialog.setWindowTitle(translate('SongsPlugin.EditVerseForm', 'Edit Verse'))
-        self.verseTypeLabel.setText(translate('SongsPlugin.EditVerseForm', '&Verse type:'))
-        self.verseTypeComboBox.setItemText(VerseType.Verse, VerseType.translated_names[VerseType.Verse])
-        self.verseTypeComboBox.setItemText(VerseType.Chorus, VerseType.translated_names[VerseType.Chorus])
-        self.verseTypeComboBox.setItemText(VerseType.Bridge, VerseType.translated_names[VerseType.Bridge])
-        self.verseTypeComboBox.setItemText(VerseType.PreChorus, VerseType.translated_names[VerseType.PreChorus])
-        self.verseTypeComboBox.setItemText(VerseType.Intro, VerseType.translated_names[VerseType.Intro])
-        self.verseTypeComboBox.setItemText(VerseType.Ending, VerseType.translated_names[VerseType.Ending])
-        self.verseTypeComboBox.setItemText(VerseType.Other, VerseType.translated_names[VerseType.Other])
-        self.splitButton.setText(UiStrings().Split)
-        self.splitButton.setToolTip(UiStrings().SplitToolTip)
-        self.insertButton.setText(translate('SongsPlugin.EditVerseForm', '&Insert'))
-        self.insertButton.setToolTip(translate('SongsPlugin.EditVerseForm',
+    def retranslateUi(self, edit_verse_dialog):
+        edit_verse_dialog.setWindowTitle(translate('SongsPlugin.EditVerseForm', 'Edit Verse'))
+        self.verse_type_label.setText(translate('SongsPlugin.EditVerseForm', '&Verse type:'))
+        self.verse_type_combo_box.setItemText(VerseType.Verse, VerseType.translated_names[VerseType.Verse])
+        self.verse_type_combo_box.setItemText(VerseType.Chorus, VerseType.translated_names[VerseType.Chorus])
+        self.verse_type_combo_box.setItemText(VerseType.Bridge, VerseType.translated_names[VerseType.Bridge])
+        self.verse_type_combo_box.setItemText(VerseType.PreChorus, VerseType.translated_names[VerseType.PreChorus])
+        self.verse_type_combo_box.setItemText(VerseType.Intro, VerseType.translated_names[VerseType.Intro])
+        self.verse_type_combo_box.setItemText(VerseType.Ending, VerseType.translated_names[VerseType.Ending])
+        self.verse_type_combo_box.setItemText(VerseType.Other, VerseType.translated_names[VerseType.Other])
+        self.split_button.setText(UiStrings().Split)
+        self.split_button.setToolTip(UiStrings().SplitToolTip)
+        self.insert_button.setText(translate('SongsPlugin.EditVerseForm', '&Insert'))
+        self.insert_button.setToolTip(translate('SongsPlugin.EditVerseForm',
             'Split a slide into two by inserting a verse splitter.'))

=== modified file 'openlp/plugins/songs/forms/editverseform.py'
--- openlp/plugins/songs/forms/editverseform.py	2013-03-08 08:14:39 +0000
+++ openlp/plugins/songs/forms/editverseform.py	2013-03-11 21:28:19 +0000
@@ -50,56 +50,56 @@
         """
         QtGui.QDialog.__init__(self, parent)
         self.setupUi(self)
-        self.verseTextEdit.customContextMenuRequested.connect(self.contextMenu)
-        self.insertButton.clicked.connect(self.onInsertButtonClicked)
-        self.splitButton.clicked.connect(self.onSplitButtonClicked)
-        self.verseTextEdit.cursorPositionChanged.connect(self.onCursorPositionChanged)
-        self.verseTypeComboBox.currentIndexChanged.connect(self.onVerseTypeComboBoxChanged)
+        self.verse_text_edit.customContextMenuRequested.connect(self.context_menu)
+        self.insert_button.clicked.connect(self.on_insert_button_clicked)
+        self.split_button.clicked.connect(self.on_split_button_clicked)
+        self.verse_text_edit.cursorPositionChanged.connect(self.on_cursor_position_changed)
+        self.verse_type_combo_box.currentIndexChanged.connect(self.on_verse_type_combo_box_changed)
 
-    def contextMenu(self, point):
+    def context_menu(self, point):
         item = self.serviceManagerList.itemAt(point)
 
-    def insertVerse(self, verse_tag, verse_num=1):
-        if self.verseTextEdit.textCursor().columnNumber() != 0:
-            self.verseTextEdit.insertPlainText(u'\n')
+    def insert_verse(self, verse_tag, verse_num=1):
+        if self.verse_text_edit.textCursor().columnNumber() != 0:
+            self.verse_text_edit.insertPlainText(u'\n')
         verse_tag = VerseType.translated_name(verse_tag)
-        self.verseTextEdit.insertPlainText(u'---[%s:%s]---\n' % (verse_tag, verse_num))
-        self.verseTextEdit.setFocus()
+        self.verse_text_edit.insertPlainText(u'---[%s:%s]---\n' % (verse_tag, verse_num))
+        self.verse_text_edit.setFocus()
 
-    def onSplitButtonClicked(self):
-        text = self.verseTextEdit.toPlainText()
-        position = self.verseTextEdit.textCursor().position()
+    def on_split_button_clicked(self):
+        text = self.verse_text_edit.toPlainText()
+        position = self.verse_text_edit.textCursor().position()
         insert_string = u'[---]'
         if position and text[position-1] != u'\n':
-             insert_string = u'\n' + insert_string
+            insert_string = u'\n' + insert_string
         if position ==  len(text) or text[position] != u'\n':
-             insert_string += u'\n'
-        self.verseTextEdit.insertPlainText(insert_string)
-        self.verseTextEdit.setFocus()
-
-    def onInsertButtonClicked(self):
-        verse_type_index = self.verseTypeComboBox.currentIndex()
-        self.insertVerse(VerseType.tags[verse_type_index], self.verseNumberBox.value())
-
-    def onVerseTypeComboBoxChanged(self):
-        self.updateSuggestedVerseNumber()
-
-    def onCursorPositionChanged(self):
-        self.updateSuggestedVerseNumber()
-
-    def updateSuggestedVerseNumber(self):
+            insert_string += u'\n'
+        self.verse_text_edit.insertPlainText(insert_string)
+        self.verse_text_edit.setFocus()
+
+    def on_insert_button_clicked(self):
+        verse_type_index = self.verse_type_combo_box.currentIndex()
+        self.insert_verse(VerseType.tags[verse_type_index], self.verse_number_box.value())
+
+    def on_verse_type_combo_box_changed(self):
+        self.update_suggested_verse_number()
+
+    def on_cursor_position_changed(self):
+        self.update_suggested_verse_number()
+
+    def update_suggested_verse_number(self):
         """
         Adjusts the verse number SpinBox in regard to the selected verse type and the cursor's position.
         """
-        position = self.verseTextEdit.textCursor().position()
-        text = self.verseTextEdit.toPlainText()
+        position = self.verse_text_edit.textCursor().position()
+        text = self.verse_text_edit.toPlainText()
         verse_name = VerseType.translated_names[
-            self.verseTypeComboBox.currentIndex()]
+            self.verse_type_combo_box.currentIndex()]
         if not text:
             return
         position = text.rfind(u'---[%s' % verse_name, 0, position)
         if position == -1:
-            self.verseNumberBox.setValue(1)
+            self.verse_number_box.setValue(1)
             return
         text = text[position:]
         position = text.find(u']---')
@@ -108,38 +108,39 @@
         text = text[:position + 4]
         match = VERSE_REGEX.match(text)
         if match:
-            verse_tag = match.group(1)
+            # TODO: Not used, remove?
+            # verse_tag = match.group(1)
             try:
                 verse_num = int(match.group(2)) + 1
             except ValueError:
                 verse_num = 1
-            self.verseNumberBox.setValue(verse_num)
+            self.verse_number_box.setValue(verse_num)
 
-    def setVerse(self, text, single=False, tag=u'%s1' % VerseType.tags[VerseType.Verse]):
-        self.hasSingleVerse = single
+    def set_verse(self, text, single=False, tag=u'%s1' % VerseType.tags[VerseType.Verse]):
+        self.has_single_verse = single
         if single:
             verse_type_index = VerseType.from_tag(tag[0], None)
             verse_number = tag[1:]
             if verse_type_index is not None:
-                self.verseTypeComboBox.setCurrentIndex(verse_type_index)
-            self.verseNumberBox.setValue(int(verse_number))
-            self.insertButton.setVisible(False)
+                self.verse_type_combo_box.setCurrentIndex(verse_type_index)
+            self.verse_number_box.setValue(int(verse_number))
+            self.insert_button.setVisible(False)
         else:
             if not text:
                 text = u'---[%s:1]---\n' % VerseType.translated_names[VerseType.Verse]
-            self.verseTypeComboBox.setCurrentIndex(0)
-            self.verseNumberBox.setValue(1)
-            self.insertButton.setVisible(True)
-        self.verseTextEdit.setPlainText(text)
-        self.verseTextEdit.setFocus()
-        self.verseTextEdit.moveCursor(QtGui.QTextCursor.End)
-
-    def getVerse(self):
-        return self.verseTextEdit.toPlainText(), VerseType.tags[self.verseTypeComboBox.currentIndex()], \
-            unicode(self.verseNumberBox.value())
-
-    def getVerseAll(self):
-        text = self.verseTextEdit.toPlainText()
+            self.verse_type_combo_box.setCurrentIndex(0)
+            self.verse_number_box.setValue(1)
+            self.insert_button.setVisible(True)
+        self.verse_text_edit.setPlainText(text)
+        self.verse_text_edit.setFocus()
+        self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
+
+    def get_verse(self):
+        return self.verse_text_edit.toPlainText(), VerseType.tags[self.verse_type_combo_box.currentIndex()], \
+            unicode(self.verse_number_box.value())
+
+    def get_all_verses(self):
+        text = self.verse_text_edit.toPlainText()
         if not text.startswith(u'---['):
             text = u'---[%s:1]---\n%s' % (VerseType.translated_names[VerseType.Verse], text)
         return text

=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py	2013-03-07 21:04:19 +0000
+++ openlp/plugins/songs/lib/__init__.py	2013-03-11 21:28:19 +0000
@@ -386,6 +386,8 @@
     ``song``
         The song object.
     """
+    from xml import SongXML
+
     if isinstance(song.title, buffer):
         song.title = unicode(song.title)
     if isinstance(song.alternate_title, buffer):

=== modified file 'tests/interfaces/openlp_core_lib/test_pluginmanager.py'
--- tests/interfaces/openlp_core_lib/test_pluginmanager.py	2013-03-07 12:34:35 +0000
+++ tests/interfaces/openlp_core_lib/test_pluginmanager.py	2013-03-11 21:28:19 +0000
@@ -42,7 +42,7 @@
 
     def find_plugins_test(self):
         """
-        Test the find_plugins() method to ensure it imports the correct plugins.
+        Test the find_plugins() method to ensure it imports the correct plugins
         """
         # GIVEN: A plugin manager
         plugin_manager = PluginManager()

=== modified file 'tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py'
--- tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py	2013-03-07 12:34:35 +0000
+++ tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py	2013-03-11 21:28:19 +0000
@@ -39,7 +39,7 @@
 
     def get_first_name_property_test(self):
         """
-        Test that getting the first name property on the AuthorForm works correctly.
+        Test that getting the first name property on the AuthorForm works correctly
         """
         # GIVEN: A first name to set
         first_name = u'John'
@@ -52,7 +52,7 @@
 
     def set_first_name_property_test(self):
         """
-        Test that setting the first name property on the AuthorForm works correctly.
+        Test that setting the first name property on the AuthorForm works correctly
         """
         # GIVEN: A first name to set
         first_name = u'James'
@@ -65,7 +65,7 @@
 
     def get_last_name_property_test(self):
         """
-        Test that getting the last name property on the AuthorForm works correctly.
+        Test that getting the last name property on the AuthorForm works correctly
         """
         # GIVEN: A last name to set
         last_name = u'Smith'
@@ -78,7 +78,7 @@
 
     def set_last_name_property_test(self):
         """
-        Test that setting the last name property on the AuthorForm works correctly.
+        Test that setting the last name property on the AuthorForm works correctly
         """
         # GIVEN: A last name to set
         last_name = u'Potter'
@@ -91,7 +91,7 @@
 
     def get_display_name_property_test(self):
         """
-        Test that getting the display name property on the AuthorForm works correctly.
+        Test that getting the display name property on the AuthorForm works correctly
         """
         # GIVEN: A display name to set
         display_name = u'John'
@@ -104,7 +104,7 @@
 
     def set_display_name_property_test(self):
         """
-        Test that setting the display name property on the AuthorForm works correctly.
+        Test that setting the display name property on the AuthorForm works correctly
         """
         # GIVEN: A display name to set
         display_name = u'John'

=== modified file 'tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py'
--- tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py	2013-03-07 12:34:35 +0000
+++ tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py	2013-03-11 21:28:19 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtCore, QtGui, QtTest
 
 from openlp.core.lib import Registry
 from openlp.plugins.songs.forms.editverseform import EditVerseForm
@@ -32,4 +32,32 @@
         """
         Test the EditVerseForm defaults are correct
         """
-        self.assertEqual(self.form.verseTextEdit.toPlainText(), u'', u'The verse edit box is empty.')
+        # GIVEN: An EditVerseForm instance
+        # WHEN: The form is shown
+        # THEN: The default value is correct
+        self.assertEqual(self.form.verse_text_edit.toPlainText(), u'', u'The verse edit box is empty.')
+
+    def insert_verse_test(self):
+        """
+        Test that clicking the insert button inserts the correct verse marker
+        """
+        # GIVEN: An instance of the EditVerseForm
+        # WHEN: The Insert button is clicked
+        QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
+
+        # THEN: The verse text edit should have a Verse:1 in it
+        self.assertIn(u'---[Verse:1]---', self.form.verse_text_edit.toPlainText(),
+                      u'The verse text edit should have a verse marker')
+
+    def insert_verse_2_test(self):
+        """
+        Test that clicking the up button on the spin box and then clicking the insert button inserts the correct marker
+        """
+        # GIVEN: An instance of the EditVerseForm
+        # WHEN: The spin button and then the Insert button are clicked
+        QtTest.QTest.keyClick(self.form.verse_number_box, QtCore.Qt.Key_Up)
+        QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
+
+        # THEN: The verse text edit should have a Verse:1 in it
+        self.assertIn(u'---[Verse:2]---', self.form.verse_text_edit.toPlainText(),
+                      u'The verse text edit should have a "Verse 2" marker')


Follow ups