From 9887764d51af4e4951c8552630946366b815bc78 Mon Sep 17 00:00:00 2001 From: Carsten Tinggaard Date: Tue, 6 Jan 2009 20:10:03 +0000 Subject: [PATCH] Refactored+update part 1; from UpperCaseWords to lower_case_words Added attribute songid and changed names bzr-revno: 275 --- openlp/plugins/songs/lib/songxml.py | 1294 +++++++++-------- openlp/plugins/songs/test/test_song_basic.py | 363 +++-- .../plugins/songs/test/test_song_opensong.py | 66 +- openlp/plugins/songs/test/test_song_text.py | 24 +- openlp/plugins/songs/test/test_song_verse.py | 74 +- 5 files changed, 919 insertions(+), 902 deletions(-) diff --git a/openlp/plugins/songs/lib/songxml.py b/openlp/plugins/songs/lib/songxml.py index 73056e57c..976e421f6 100644 --- a/openlp/plugins/songs/lib/songxml.py +++ b/openlp/plugins/songs/lib/songxml.py @@ -1,631 +1,663 @@ -# -*- coding:iso-8859-1 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 -""" -OpenLP - Open Source Lyrics Projection -Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -""" - -import sys -import os -from types import StringType, ListType, NoneType - -sys.path.append(os.path.abspath("./../../../..")) - -from openlp.core.lib import XmlRootClass - -class SongException(Exception): - pass - -class SongTitleError(SongException): - pass - -class SongTypeError(SongException): - pass - -class SongSlideError(SongException): - pass - -# TODO: Song: Logging - not all, but enough -# TODO: Song: Handle OpenLP2 format -# TODO: Song: Import OpenLP1 -# TODO: Song: Export OpenLP1 -# TODO: Song: Export Song to CCLI -# TODO: Song: Export Song to OpenSong -# TODO: Song: Import ChangingSong -# TODO: Song: Export ChangingSong - -_blankSongXml = \ -''' - - BlankSong - - - - - 1 - 1 - 1 - 1 - - - - - - - - -''' - -_blankOpenSongXml = \ -''' - - - - - - - - - - -''' - -class _OpenSong(XmlRootClass): - """Class for import of OpenSogn""" - - def __init__(self, xmlContent = None): - """Initialize from given xml content""" - super(_OpenSong, self).__init__() - self.FromBuffer(xmlContent) - - def _reset(self): - """Reset all song attributes""" - global _blankOpenSongXml - self._setFromXml(_blankOpenSongXml, "song") - - def FromBuffer(self, xmlContent): - """Initialize from buffer(string) with xml content""" - self._reset() - if xmlContent != None : - self._setFromXml(xmlContent, "song") - - def GetAuthorList(self): - """Convert author field to an authorlist - - in OpenSong an author list may be separated by '/' - return as a string - """ - res = [] - if self.author != None : - lst = self.author.split(' and ') - for l in lst : - res.append(l.strip()) - s = ", ".join(res) - return s - - def GetCategoryArray(self): - """Convert theme and alttheme into categoryArray - - return as a string - """ - res = [] - if self.theme != None : - res.append(self.theme) - if self.alttheme != None : - res.append(self.alttheme) - s = ", ".join(res) - return s - - def _reorderVerse(self, tag, tmpVerse): - """Reorder the verse in case of first char is a number - - tag -- the tag of this verse / verse group - tmpVerse -- list of strings - """ - res = [] - for c in '1234567890 ': - tagPending = True - for l in tmpVerse : - if l.startswith(c) : - if tagPending : - tagPending = False - t = tag.strip("[]").lower() - if 'v' == t : - newtag = "Verse" - elif 'c' == t : - newtag = "Chorus" - elif 'b' == t : - newtag = "Bridge" - elif 'p' == t : - newtag = "Pre-chorus" - else : - newtag = t - s = ("# %s %s"%(newtag, c)).rstrip() - res.append(s) - res.append(l[1:]) - if (len(l) == 0) and (not tagPending) : - res.append(l) - return res - - def GetLyrics(self): - """Convert the lyrics to openlp lyrics format - - return as list of strings - """ - lyrics = self.lyrics.split("\n") - tmpVerse = [] - finalLyrics = [] - tag = "" - for l in lyrics: - line = l.rstrip() - if not line.startswith('.') : - # drop all chords - tmpVerse.append(line) - if len(line) > 0 : - if line.startswith('['): - tag = line - else : - r = self._reorderVerse(tag, tmpVerse) - finalLyrics.extend(r) - tag = "" - tmpVerse = [] - # catch up final verse - r = self._reorderVerse(tag, tmpVerse) - finalLyrics.extend(r) - return finalLyrics - - -class Song(XmlRootClass) : - """Class for handling song properties""" - - def __init__(self, xmlContent = None): - """Initialize from given xml content - - xmlContent (string) -- xml formatted string - - title -- title of the song - searchableTitle -- title without punctuation chars - authorList -- list of authors - songCcliNo -- CCLI number for this song - copyright -- copyright string - showTitle -- 0: no show, 1: show - showAuthorList -- 0: no show, 1: show - showCopyright -- 0: no show, 1: show - showSongCcliNo -- 0: no show, 1: show - theme -- name of theme or blank - categoryArray -- list of user defined properties (hymn, gospel) - songBook -- name of originating book - songNumber -- number of the song, related to a songbook - comments -- free comment - verseOrder -- presentation order of the slides - lyrics -- simple or formatted (tbd) - """ - super(Song, self).__init__() - self._reset() - if xmlContent != None : - self._setFromXml(xmlContent, "Song") - self._parseLyrics() - - def _reset(self): - """Reset all song attributes""" - global _blankSongXml - self.slideList = [] - self._setFromXml(_blankSongXml, "Song") - - def FromOpenSongBuffer(self, xmlcontent): - """Initialize from buffer(string) of xml lines in opensong format""" - self._reset() - opensong = _OpenSong(xmlcontent) - if opensong.title != None: - self.SetTitle(opensong.title) - if opensong.copyright != None : - self.SetCopyright(opensong.copyright) - if opensong.presentation != None: - self.SetVerseOrder(opensong.presentation) - if opensong.ccli != None: - self.SetSongCcliNo(opensong.ccli) - self.SetAuthorList(opensong.GetAuthorList()) - self.SetCategoryArray(opensong.GetCategoryArray()) - self.SetLyrics(opensong.GetLyrics()) - - def FromOpenSongFile(self, xmlfilename): - """Initialize from file containing xml - - xmlfilename -- path to xml file - """ - lst = [] - f = open(xmlfilename, 'r') - for line in f : - lst.append(line) - f.close() - xml = "".join(lst) - self.FromOpenSongBuffer(xml) - - def _RemovePunctuation(self, title): - """Remove the puntuation chars from title - - chars are: .,:;!?&%#/\@`$'|"^~* - """ - punctuation = ".,:;!?&%#'\"/\\@`$|^~*" - s = title - for c in punctuation : - s = s.replace(c, '') - return s - - def SetTitle(self, title): - """Set the song title - - title (string) - """ - self.title = title.strip() - self.searchableTitle = self._RemovePunctuation(title).strip() - if len(self.title) < 1 : - raise SongTitleError("The title is empty") - if len(self.searchableTitle) < 1 : - raise SongTitleError("The searchable title is empty") - - def GetTitle(self): - """Return title value""" - return self.title - - def GetSearchableTitle(self): - """Return searchableTitle""" - return self.searchableTitle - - def FromTextList(self, textList): - """Create song from a list of texts (strings) - CCLI text format expected - - textList (list of strings) -- the song - """ - self._reset() - # extract the following fields - # - name - # - author - # - CCLI no - sName = "" - sAuthor = "" - sCopyright = "" - sCcli = "" - lastpart = 0 - n = 0 - metMisc = False - lyrics = [] - for l in textList : - n += 1 - if lastpart > 0 : - lastpart += 1 - if lastpart == 2 : - sCopyright = l[1:].strip() - if lastpart == 3 : - sAuthor = l - elif l.startswith('CCLI Song') : - sCcli = l[13:].strip() - lastpart = 1 - else : - if metMisc : - metMisc = False - if l.upper().startswith("(BRIDGE)") : - lyrics.append("# Bridge") - # otherwise unknown misc keyword - elif l.startswith("Misc") : - metMisc = True - elif l.startswith("Verse") or l.startswith("Chorus"): - lyrics.append("# %s"%l) - else : - # should we remove multiple blank lines? - if n == 1 : - sName = l - else : - lyrics.append(l) - # split on known separators - lst = sAuthor.split('/') - if len(lst) < 2: - lst = sAuthor.split('|') - authorList = ", ".join(lst) - self.SetTitle(sName) - self.SetAuthorList(authorList) - self.SetCopyright(sCopyright) - self.SetSongCcliNo(sCcli) - self.SetLyrics(lyrics) - - def FromTextFile(self, textFileName): - """Create song from a list of texts read from given file - - textFileName -- path to text file - """ - lines = [] - f = open(textFileName, 'r') - for orgline in f: - lines.append(orgline.rstrip()) - f.close() - self.FromTextList(lines) - - def _assureString(self, s): - """Force a string is returned""" - if s == None : - r = "" - else : - r = str(s) - return r - - def _splitToList(self, aString): - """Split a string into a list - comma separated""" - res = [] - if aString != None : - lst = aString.split(',') - for l in lst : - # remove whitespace - res.append(l.strip()) - return res - - def _listToString(self, strOrList): - """Force a possibly list into a string""" - if type(strOrList) == StringType : - lst = self._splitToList(strOrList) - elif type(strOrList) == ListType : - lst = strOrList - elif type(strOrList) == NoneType : - lst = [] - else : - raise SongTypeError("Variable not String or List") - s = ", ".join(lst) - return s - - def GetCopyright(self): - """Return copyright info string""" - return self._assureString(self.copyright) - - def SetCopyright(self, copyright): - """Set the copyright string""" - self.copyright = copyright - - def GetSongCcliNo(self): - """Return the songCclino""" - return self._assureString(self.songCcliNo) - - def SetSongCcliNo(self, songCcliNo): - """Set the songCcliNo""" - self.songCcliNo = songCcliNo - - def GetTheme(self): - """Return the theme name for the song""" - return self._assureString(self.theme) - - def SetTheme(self, theme): - """Set the theme name (string)""" - self.theme = theme - - def GetSongBook(self): - """Return the songBook (string)""" - return self._assureString(self.songBook) - - def SetSongBook(self, songBook): - """Set the songBook (string)""" - self.songBook = songBook - - def GetSongNumber(self): - """Return the songNumber (string)""" - return self._assureString(self.songNumber) - - def SetSongNumber(self, songNumber): - """Set the songNumber (string)""" - self.songNumber = songNumber - - def GetComments(self): - """Return the comments (string)""" - return self._assureString(self.comments) - - def SetComments(self, comments): - """Set the comments (string)""" - self.comments = comments - - def GetVerseOrder(self): - """Get the verseOrder (string) - preferably space delimited""" - return self._assureString(self.verseOrder) - - def SetVerseOrder(self, verseOrder): - """Set the verseOrder (string) - space delimited""" - self.verseOrder = verseOrder - - def GetAuthorList(self, asOneString = True): - """Return the list of authors as a string - - asOneString - True -- string: - "John Newton, A Parker" - False -- list of strings - ["John Newton", "A Parker"] - """ - if asOneString : - res = self._assureString(self.authorList) - else : - res = self._splitToList(self.authorList) - return res - - def SetAuthorList(self, authorList): - """Set the authorList - - authorList -- a string or list of strings - """ - if authorList == None : - self.authorList = None - else : - self.authorList = self._listToString(authorList) - - def GetCategoryArray(self, asOneString = True): - """Return the list of categories as a string - - asOneString - True -- string: - "Hymn, Gospel" - False -- list of strings - ["Hymn", "Gospel"] - """ - if asOneString : - res = self._assureString(self.categoryArray) - else : - res = self._splitToList(self.categoryArray) - return res - - def SetCategoryArray(self, categoryArray): - """Set the categoryArray - - categoryArray -- a string or list of strings - """ - if categoryArray == None : - self.categoryArray = None - else : - self.categoryArray = self._listToString(categoryArray) - - def GetShowTitle(self): - """Return the showTitle flag (bool)""" - return self.showTitle - - def SetShowTitle(self, showTitle): - """Set the showTitle flag (bool)""" - self.showTitle = showTitle - - def GetShowAuthorList(self): - """Return the showAuthorList flag""" - return self.showAuthorList - - def SetShowAuthorList(self, showAuthorList): - """Set the showAuthorList flag (bool)""" - self.showAuthorList = showAuthorList - - def GetShowCopyright(self): - """Return the showCopyright flag""" - return self.showCopyright - - def SetShowCopyright(self, showCopyright): - """Set the showCopyright flag (bool)""" - self.showCopyright = showCopyright - - def GetShowSongCcliNo(self): - """Return the showSongCclino (string)""" - return self.showSongCcliNo - - def SetShowSongCcliNo(self, showSongCcliNo): - """Set the showSongCcliNo flag (bool)""" - self.showSongCcliNo = showSongCcliNo - - def GetLyrics(self): - """Return the lyrics as a list of strings - - this will return all the strings in the song - """ - return self.lyrics - - def SetLyrics(self, lyrics): - """Set the lyrics as a list of strings""" - self.lyrics = lyrics - self._parseLyrics() - - def _parseLyrics(self): - """Parse lyrics into the slidelist""" - # TODO: check font formatting - self.slideList = [] - tmpSlide = [] - metContent = False - for l in self.lyrics : - if len(l) > 0 : - metContent = True - tmpSlide.append(l) - else : - if metContent : - metContent = False - self.slideList.append(tmpSlide) - tmpSlide = [] - # - if len(tmpSlide) > 0: - self.slideList.append(tmpSlide) - - def GetNumberOfSlides(self): - """Return the number of slides in the song (int)""" - numOfSlides = len(self.slideList) - return numOfSlides - - def GetPreviewSlide(self, slideNumber): - """Return the preview text for specified slide number - - slideNumber -- 0: all slides, 1..n : specific slide - a list of strings are returned - """ - num = len(self.slideList) - if num < 1 : - raise SongSlideError("No slides in this song") - elif slideNumber > num : - raise SongSlideError("Slide number too high") - if slideNumber > 0 : - # return this slide - res = self.slideList[slideNumber-1] - # find theme in this slide - else : - res = [] - for i in range(num): - if i > 0 : - res.append("") - res.extend() - # remove formattingincluding themes - return res - - def GetRenderSlide(self, slideNumber): - """Return the slide to be rendered including the additional - properties - - slideNumber -- 1 .. numberOfSlides - Returns a list as: - [theme (string), - title (string), - authorlist (string), - copyright (string), - cclino (string), - lyric-part as a list of strings] - """ - num = len(self.slideList) - if num < 1 : - raise SongSlideError("No slides in this song") - elif slideNumber > num : - raise SongSlideError("Slide number too high") - res = [] - if self.showTitle : - title = self.GetTitle() - else : - title = "" - if self.showAuthorList : - author = self.GetAuthorList(True) - else : - author = "" - if self.showCopyright : - cpright = self.GetCopyright() - else : - cpright = "" - if self.showSongCcliNo : - ccli = self.GetSongCcliNo() - else : - ccli = "" - theme = self.GetTheme() - # examine the slide for a theme - res.append(theme) - res.append(title) - res.append(author) - res.append(cpright) - res.append(ccli) - # append the correct slide - return res - -__all__ = ['SongException', 'SongTitleError', 'SongSlideError', 'SongTypeError', - 'Song'] +# -*- coding:iso-8859-1 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2008 Raoul Snyman +Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import sys +import os +from types import StringType, ListType, NoneType + +sys.path.append(os.path.abspath("./../../../..")) + +from openlp.core.lib import XmlRootClass + +class SongException(Exception): + pass + +class SongTitleError(SongException): + pass + +class SongTypeError(SongException): + pass + +class SongSlideError(SongException): + pass + +class SongFeatureError(SongException): + pass + +# TODO: Song: Logging - not all, but enough +# TODO: Song: Handle OpenLP2 format +# TODO: Song: Import OpenLP1 +# TODO: Song: Export OpenLP1 +# TODO: Song: Export Song to CCLI +# TODO: Song: Export Song to OpenSong +# TODO: Song: Import ChangingSong +# TODO: Song: Export ChangingSong + +_blankOpenSongXml = \ +''' + + + + + + + + + + +''' + +class _OpenSong(XmlRootClass): + """Class for import of OpenSogn""" + + def __init__(self, xmlContent = None): + """Initialize from given xml content""" + super(_OpenSong, self).__init__() + self.from_buffer(xmlContent) + + def _reset(self): + """Reset all song attributes""" + global _blankOpenSongXml + self._setFromXml(_blankOpenSongXml, "song") + + def from_buffer(self, xmlContent): + """Initialize from buffer(string) with xml content""" + self._reset() + if xmlContent != None : + self._setFromXml(xmlContent, "song") + + def get_author_list(self): + """Convert author field to an authorlist + + in OpenSong an author list may be separated by '/' + return as a string + """ + res = [] + if self.author != None : + lst = self.author.split(' and ') + for l in lst : + res.append(l.strip()) + s = ", ".join(res) + return s + + def get_category_array(self): + """Convert theme and alttheme into category_array + + return as a string + """ + res = [] + if self.theme != None : + res.append(self.theme) + if self.alttheme != None : + res.append(self.alttheme) + s = ", ".join(res) + return s + + def _reorder_verse(self, tag, tmpVerse): + """Reorder the verse in case of first char is a number + + tag -- the tag of this verse / verse group + tmpVerse -- list of strings + """ + res = [] + for c in '1234567890 ': + tagPending = True + for l in tmpVerse : + if l.startswith(c) : + if tagPending : + tagPending = False + t = tag.strip("[]").lower() + if 'v' == t : + newtag = "Verse" + elif 'c' == t : + newtag = "Chorus" + elif 'b' == t : + newtag = "Bridge" + elif 'p' == t : + newtag = "Pre-chorus" + else : + newtag = t + s = ("# %s %s"%(newtag, c)).rstrip() + res.append(s) + res.append(l[1:]) + if (len(l) == 0) and (not tagPending) : + res.append(l) + return res + + def get_lyrics(self): + """Convert the lyrics to openlp lyrics format + + return as list of strings + """ + lyrics = self.lyrics.split("\n") + tmpVerse = [] + finalLyrics = [] + tag = "" + for l in lyrics: + line = l.rstrip() + if not line.startswith('.') : + # drop all chords + tmpVerse.append(line) + if len(line) > 0 : + if line.startswith('['): + tag = line + else : + r = self._reorder_verse(tag, tmpVerse) + finalLyrics.extend(r) + tag = "" + tmpVerse = [] + # catch up final verse + r = self._reorder_verse(tag, tmpVerse) + finalLyrics.extend(r) + return finalLyrics + + +class Song(object) : + """Handling song properties and methods + + handles all conversions between various input and output formats + + CCLI : + from_ccli_text_file + to_ccli_text_file + from_ccli_text_buffer + to_ccli_text_buffer + + OpenSong: + from_opensong_file + to_opensong_file + from_opensong_buffer + to_opensong_buffer + + presentation (screen): + get_number_of_slides + get_preview_slide + get_render_slide + + openlp1 : + from_openlp1_lyrics_buffer + to_openlp1_lyrics_buffer + set_author_list + get_author_list + + editing and openlp2 : + set_* + get_* + """ + + def __init__(self, songid = 0): + """Initialize song object + + songid -- database id for this song + title -- title of the song + search_title -- title without punctuation chars + author_list -- list of authors + song_cclino -- CCLI number for this song + copyright -- copyright string + show_title -- 0: no show, 1: show + show_author_list -- 0: no show, 1: show + show_copyright -- 0: no show, 1: show + show_song_cclino -- 0: no show, 1: show + theme -- name of theme or blank + category_array -- list of user defined properties (hymn, gospel) + song_book -- name of originating book + song_number -- number of the song, related to a songbook + comments -- free comment + verse_order -- presentation order of the slides + lyrics -- text format + search_lyrics -- lowercase lyrics without punctuation + """ + self.songid = songid + self._reset() + + def _reset(self): + """Reset all song attributes""" + self.slideList = [] + self.set_title("BlankSong") + self.author_list = None + self.song_cclino = "" + self.copyright = "" + self.show_author_list = 1 + self.show_copyright = 1 + self.show_song_cclino = 1 + self.show_title = 1 + self.theme = "" + self.category_array = None + self.song_book = "" + self.song_number = "" + self.comments = "" + self.verse_order = "" + self.set_lyrics("") + return + + def set_songid(self, songid): + """Set the songid for the database""" + self.songid = songid + + def get_songid(self): + """Return the songid for the database""" + return self.songid + + def from_opensong_buffer(self, xmlcontent): + """Initialize from buffer(string) of xml lines in opensong format""" + self._reset() + opensong = _OpenSong(xmlcontent) + if opensong.title != None: + self.set_title(opensong.title) + if opensong.copyright != None : + self.set_copyright(opensong.copyright) + if opensong.presentation != None: + self.set_verse_order(opensong.presentation) + if opensong.ccli != None: + self.set_song_cclino(opensong.ccli) + self.set_author_list(opensong.get_author_list()) + self.set_category_array(opensong.get_category_array()) + self.set_lyrics(opensong.get_lyrics()) + + def from_opensong_file(self, xmlfilename): + """Initialize from file containing xml + + xmlfilename -- path to xml file + """ + lst = [] + f = open(xmlfilename, 'r') + for line in f : + lst.append(line) + f.close() + xml = "".join(lst) + self.from_opensong_buffer(xml) + + def _remove_punctuation(self, title): + """Remove the puntuation chars from title + + chars are: .,:;!?&%#/\@`$'|"^~*- + """ + punctuation = ".,:;!?&%#'\"/\\@`$|^~*-" + s = title + for c in punctuation : + s = s.replace(c, '') + return s + + def set_title(self, title): + """Set the song title + + title (string) + raises SongTitleError if the title is empty + raises SongTitleError if the seach_title is empty + """ + self.title = title.strip() + self.search_title = self._remove_punctuation(title).strip() + if len(self.title) < 1 : + raise SongTitleError("The title is empty") + if len(self.search_title) < 1 : + raise SongTitleError("The searchable title is empty") + + def get_title(self): + """Return title value""" + return self.title + + def get_search_title(self): + """Return search_title""" + return self.search_title + + def from_ccli_text_buffer(self, textList): + """Create song from a list of texts (strings) - CCLI text format expected + + textList (list of strings) -- the song + """ + self._reset() + # extract the following fields + # - name + # - author + # - CCLI no + sName = "" + sAuthor = "" + sCopyright = "" + sCcli = "" + lastpart = 0 + n = 0 + metMisc = False + lyrics = [] + for l in textList : + n += 1 + if lastpart > 0 : + lastpart += 1 + if lastpart == 2 : + sCopyright = l[1:].strip() + if lastpart == 3 : + sAuthor = l + elif l.startswith('CCLI Song') : + sCcli = l[13:].strip() + lastpart = 1 + else : + if metMisc : + metMisc = False + if l.upper().startswith("(BRIDGE)") : + lyrics.append("# Bridge") + # otherwise unknown misc keyword + elif l.startswith("Misc") : + metMisc = True + elif l.startswith("Verse") or l.startswith("Chorus"): + lyrics.append("# %s"%l) + else : + # should we remove multiple blank lines? + if n == 1 : + sName = l + else : + lyrics.append(l) + # split on known separators + lst = sAuthor.split('/') + if len(lst) < 2: + lst = sAuthor.split('|') + author_list = ", ".join(lst) + self.set_title(sName) + self.set_author_list(author_list) + self.set_copyright(sCopyright) + self.set_song_cclino(sCcli) + self.set_lyrics(lyrics) + + def from_ccli_text_file(self, textFileName): + """Create song from a list of texts read from given file + + textFileName -- path to text file + """ + lines = [] + f = open(textFileName, 'r') + for orgline in f: + lines.append(orgline.rstrip()) + f.close() + self.from_ccli_text_buffer(lines) + + def _assure_string(self, s): + """Force a string is returned""" + if s == None : + r = "" + else : + r = str(s) + return r + + def _split_to_list(self, aString): + """Split a string into a list - comma separated""" + res = [] + if aString != None : + lst = aString.split(',') + for l in lst : + # remove whitespace + res.append(l.strip()) + return res + + def _list_to_string(self, strOrList): + """Force a possibly list into a string""" + if type(strOrList) == StringType : + lst = self._split_to_list(strOrList) + elif type(strOrList) == ListType : + lst = strOrList + elif type(strOrList) == NoneType : + lst = [] + else : + raise SongTypeError("Variable not String or List") + s = ", ".join(lst) + return s + + def get_copyright(self): + """Return copyright info string""" + return self._assure_string(self.copyright) + + def set_copyright(self, copyright): + """Set the copyright string""" + self.copyright = copyright + + def get_song_cclino(self): + """Return the songCclino""" + return self._assure_string(self.song_cclino) + + def set_song_cclino(self, song_cclino): + """Set the song_cclino""" + self.song_cclino = song_cclino + + def get_theme(self): + """Return the theme name for the song""" + return self._assure_string(self.theme) + + def set_theme(self, theme): + """Set the theme name (string)""" + self.theme = theme + + def get_song_book(self): + """Return the song_book (string)""" + return self._assure_string(self.song_book) + + def set_song_book(self, song_book): + """Set the song_book (string)""" + self.song_book = song_book + + def get_song_number(self): + """Return the song_number (string)""" + return self._assure_string(self.song_number) + + def set_song_number(self, song_number): + """Set the song_number (string)""" + self.song_number = song_number + + def get_comments(self): + """Return the comments (string)""" + return self._assure_string(self.comments) + + def set_comments(self, comments): + """Set the comments (string)""" + self.comments = comments + + def get_verse_order(self): + """Get the verseOrder (string) - preferably space delimited""" + return self._assure_string(self.verse_order) + + def set_verse_order(self, verse_order): + """Set the verse order (string) - space delimited""" + self.verse_order = verse_order + + def get_author_list(self, asOneString = True): + """Return the list of authors as a string + + asOneString + True -- string: + "John Newton, A Parker" + False -- list of strings + ["John Newton", "A Parker"] + """ + if asOneString : + res = self._assure_string(self.author_list) + else : + res = self._split_to_list(self.author_list) + return res + + def set_author_list(self, author_list): + """Set the author_list + + author_list -- a string or list of strings + """ + if author_list == None : + self.author_list = None + else : + self.author_list = self._list_to_string(author_list) + + def get_category_array(self, asOneString = True): + """Return the list of categories as a string + + asOneString + True -- string: + "Hymn, Gospel" + False -- list of strings + ["Hymn", "Gospel"] + """ + if asOneString : + res = self._assure_string(self.category_array) + else : + res = self._split_to_list(self.category_array) + return res + + def set_category_array(self, category_array): + """Set the category_array + + category_array -- a string or list of strings + """ + if category_array == None : + self.category_array = None + else : + self.category_array = self._list_to_string(category_array) + + def get_show_title(self): + """Return the show_title flag (bool)""" + return self.show_title + + def set_show_title(self, show_title): + """Set the show_title flag (bool)""" + self.show_title = show_title + + def get_show_author_list(self): + """Return the show_author_list flag""" + return self.show_author_list + + def set_show_author_list(self, show_author_list): + """Set the show_author_list flag (bool)""" + self.show_author_list = show_author_list + + def get_show_copyright(self): + """Return the show_copyright flag""" + return self.show_copyright + + def set_show_copyright(self, show_copyright): + """Set the show_copyright flag (bool)""" + self.show_copyright = show_copyright + + def get_show_song_cclino(self): + """Return the showSongCclino (string)""" + return self.show_song_cclino + + def set_show_song_cclino(self, show_song_cclino): + """Set the show_song_cclino flag (bool)""" + self.show_song_cclino = show_song_cclino + + def get_lyrics(self): + """Return the lyrics as a list of strings + + this will return all the strings in the song + """ + return self.lyrics + + def set_lyrics(self, lyrics): + """Set the lyrics as a list of strings""" + self.lyrics = lyrics + self._parse_lyrics() + + def _parse_lyrics(self): + """Parse lyrics into the slidelist""" + # TODO: check font formatting + self.slideList = [] + tmpSlide = [] + metContent = False + for l in self.lyrics : + if len(l) > 0 : + metContent = True + tmpSlide.append(l) + else : + if metContent : + metContent = False + self.slideList.append(tmpSlide) + tmpSlide = [] + # + if len(tmpSlide) > 0: + self.slideList.append(tmpSlide) + + def get_number_of_slides(self): + """Return the number of slides in the song (int)""" + numOfSlides = len(self.slideList) + return numOfSlides + + def get_preview_slide(self, slideNumber): + """Return the preview text for specified slide number + + slideNumber -- 0: all slides, 1..n : specific slide + a list of strings are returned + """ + num = len(self.slideList) + if num < 1 : + raise SongSlideError("No slides in this song") + elif slideNumber > num : + raise SongSlideError("Slide number too high") + if slideNumber > 0 : + # return this slide + res = self.slideList[slideNumber-1] + # find theme in this slide + else : + res = [] + for i in range(num): + if i > 0 : + res.append("") + res.extend() + # remove formattingincluding themes + return res + + def get_render_slide(self, slideNumber): + """Return the slide to be rendered including the additional + properties + + slideNumber -- 1 .. numberOfSlides + Returns a list as: + [theme (string), + title (string), + authorlist (string), + copyright (string), + cclino (string), + lyric-part as a list of strings] + """ + num = len(self.slideList) + if num < 1 : + raise SongSlideError("No slides in this song") + elif slideNumber > num : + raise SongSlideError("Slide number too high") + res = [] + if self.show_title : + title = self.get_title() + else : + title = "" + if self.show_author_list : + author = self.get_author_list(True) + else : + author = "" + if self.show_copyright : + cpright = self.get_copyright() + else : + cpright = "" + if self.show_song_cclino : + ccli = self.get_song_cclino() + else : + ccli = "" + theme = self.get_theme() + # examine the slide for a theme + res.append(theme) + res.append(title) + res.append(author) + res.append(cpright) + res.append(ccli) + # append the correct slide + return res + +__all__ = ['SongException', 'SongTitleError', 'SongSlideError', 'SongTypeError', + 'SongFeatureError', 'Song'] diff --git a/openlp/plugins/songs/test/test_song_basic.py b/openlp/plugins/songs/test/test_song_basic.py index d6c53312e..04bb26b8a 100644 --- a/openlp/plugins/songs/test/test_song_basic.py +++ b/openlp/plugins/songs/test/test_song_basic.py @@ -1,189 +1,174 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 -""" -OpenLP - Open Source Lyrics Projection -Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -""" - -import py.test -import os -import sys - -__ThisDir__ = os.path.dirname(__file__) -if "" == __ThisDir__ : - __ThisDir__ = os.path.abspath(".") - -sys.path.append(os.path.abspath("%s/../../../.."%__ThisDir__)) - -from openlp.plugins.songs.lib.songxml import * - -class Test_Basic(object): - """Class for first initialization check - set-get functions - """ - - def test_Creation(self): - """Init: Create as empty""" - s = Song() - assert(True) - - def test_str(self): - """Init: Empty, use __str__ to count public attributes & methods""" - s = Song() - r = s.__str__() - l = r.split("\n") - assert(len(l) == 55) - - def test_asString(self): - """Init: Empty asString - initial values""" - s = Song() - r = s._get_as_string() - #print r - flag = r.endswith("__None__None__None__None__None__None__1__1__1__1__[]__None__None__None__None__BlankSong__None_") - assert(flag) - - def test_Title1(self): - """Set an empty title - raises an exception""" - s = Song() - py.test.raises(SongTitleError, s.SetTitle, "") - - def test_Title2(self): - """Set a normal title""" - s = Song() - t = "A normal title" - s.SetTitle(t) - assert(s.GetTitle() == t) - assert(s.GetSearchableTitle() == t) - - def test_Title3(self): - """Set a titel with punctuation 1""" - s = Song() - t1 = "Hey! Come on, ya programmers*" - t2 = "Hey Come on ya programmers" - s.SetTitle(t1) - assert(s.GetTitle() == t1) - assert(s.GetSearchableTitle() == t2) - - def test_Title4(self): - """Set a titel with punctuation 2""" - s = Song() - t1 = "??#Hey! Come on, ya programmers*" - t2 = "Hey Come on ya programmers" - s.SetTitle(t1) - assert(s.GetTitle() == t1) - assert(s.GetSearchableTitle() == t2) - - def test_Title5(self): - """Set a title, where searchable title becomes empty - raises an exception""" - s = Song() - py.test.raises(SongTitleError, s.SetTitle, ",*") - - def test_Copyright(self): - """Set a copyright string""" - s = Song() - assert(s.GetCopyright() == "") - s.SetCopyright("A B Car") - assert(s.GetCopyright() == "A B Car") - - def test_SongCclino(self): - """Set a SongCcliNo""" - s = Song() - assert(s.GetSongCcliNo() == "") - s.SetSongCcliNo(12345) - assert(s.GetSongCcliNo() == "12345") - - def test_SongBook(self): - """Set a songbook value""" - s = Song() - assert(s.GetSongBook() == "") - s.SetSongBook("Hymns") - assert(s.GetSongBook() == "Hymns") - - def test_SongNumber(self): - """Set a song number""" - s = Song() - assert(s.GetSongNumber() == "") - s.SetSongNumber(278) - assert(s.GetSongNumber() == "278") - - def test_Theme(self): - """Set a theme name""" - s = Song() - assert(s.GetTheme() == "") - s.SetTheme("Red") - assert(s.GetTheme() == "Red") - - def test_VerseOrder(self): - """Set a verse order""" - s = Song() - assert(s.GetVerseOrder() == "") - s.SetVerseOrder("V1 C V2") - assert(s.GetVerseOrder() == "V1 C V2") - - def test_Comments(self): - """Set a comment""" - s = Song() - assert(s.GetComments() == "") - s.SetComments("a comment") - assert(s.GetComments() == "a comment") - - def test_AuthorList(self): - """Set author lists""" - s = Song() - assert(s.GetAuthorList(True) == "") - assert(s.GetAuthorList(False) == []) - t1 = "John Newton" - s.SetAuthorList(t1) - assert(s.GetAuthorList(True) == t1) - assert(s.GetAuthorList(False) == [t1]) - s.SetAuthorList(" Peter Done , John Newton") - assert(s.GetAuthorList(True)== "Peter Done, John Newton") - assert(s.GetAuthorList(False) == ["Peter Done", "John Newton"]) - s.SetAuthorList(None) - assert(s.GetAuthorList(True) == "") - assert(s.GetAuthorList(False) == []) - s.SetAuthorList("") - assert(s.GetAuthorList(True) == "") - assert(s.GetAuthorList(False) == [""]) - s.SetAuthorList([]) - assert(s.GetAuthorList(True) == "") - assert(s.GetAuthorList(False) == [""]) - - def test_CategoryArray(self): - """Set categories""" - s = Song() - assert(s.GetCategoryArray(True) == "") - assert(s.GetCategoryArray(False) == []) - t1 = "Gospel" - s.SetCategoryArray(t1) - assert(s.GetCategoryArray(True) == t1) - assert(s.GetCategoryArray(False) == [t1]) - s.SetCategoryArray(" Gospel, Hymns ") - assert(s.GetCategoryArray(True) == "Gospel, Hymns") - assert(s.GetCategoryArray(False) == ["Gospel", "Hymns"]) - s.SetCategoryArray(None) - assert(s.GetCategoryArray(True) == "") - assert(s.GetCategoryArray(False) == []) - s.SetCategoryArray("") - assert(s.GetCategoryArray(True) == "") - assert(s.GetCategoryArray(False) == [""]) - s.SetCategoryArray([]) - assert(s.GetCategoryArray(True) == "") - assert(s.GetCategoryArray(False) == [""]) - -if '__main__' == __name__: - r = Test_Basic() - r.test_asString() +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2008 Raoul Snyman +Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import py.test +import os +import sys + +__ThisDir__ = os.path.dirname(__file__) +if "" == __ThisDir__ : + __ThisDir__ = os.path.abspath(".") + +sys.path.append(os.path.abspath("%s/../../../.."%__ThisDir__)) + +from openlp.plugins.songs.lib.songxml import * + +class Test_Basic(object): + """Class for first initialization check + set-get functions + """ + + def test_Creation(self): + """Init: Create as empty""" + s = Song() + assert(True) + + def test_Title1(self): + """Set an empty title - raises an exception""" + s = Song() + py.test.raises(SongTitleError, s.set_title, "") + + def test_Title2(self): + """Set a normal title""" + s = Song() + t = "A normal title" + s.set_title(t) + assert(s.get_title() == t) + assert(s.get_search_title() == t) + + def test_Title3(self): + """Set a titel with punctuation 1""" + s = Song() + t1 = "Hey! Come on, ya programmers*" + t2 = "Hey Come on ya programmers" + s.set_title(t1) + assert(s.get_title() == t1) + assert(s.get_search_title() == t2) + + def test_Title4(self): + """Set a titel with punctuation 2""" + s = Song() + t1 = "??#Hey! Come on, ya programmers*" + t2 = "Hey Come on ya programmers" + s.set_title(t1) + assert(s.get_title() == t1) + assert(s.get_search_title() == t2) + + def test_Title5(self): + """Set a title, where searchable title becomes empty - raises an exception""" + s = Song() + py.test.raises(SongTitleError, s.set_title, ",*") + + def test_Copyright(self): + """Set a copyright string""" + s = Song() + assert(s.get_copyright() == "") + s.set_copyright("A B Car") + assert(s.get_copyright() == "A B Car") + + def test_SongCclino(self): + """Set a SongCcliNo""" + s = Song() + assert(s.get_song_cclino() == "") + s.set_song_cclino(12345) + assert(s.get_song_cclino() == "12345") + + def test_SongBook(self): + """Set a songbook value""" + s = Song() + assert(s.get_song_book() == "") + s.set_song_book("Hymns") + assert(s.get_song_book() == "Hymns") + + def test_SongNumber(self): + """Set a song number""" + s = Song() + assert(s.get_song_number() == "") + s.set_song_number(278) + assert(s.get_song_number() == "278") + + def test_Theme(self): + """Set a theme name""" + s = Song() + assert(s.get_theme() == "") + s.set_theme("Red") + assert(s.get_theme() == "Red") + + def test_VerseOrder(self): + """Set a verse order""" + s = Song() + assert(s.get_verse_order() == "") + s.set_verse_order("V1 C V2") + assert(s.get_verse_order() == "V1 C V2") + + def test_Comments(self): + """Set a comment""" + s = Song() + assert(s.get_comments() == "") + s.set_comments("a comment") + assert(s.get_comments() == "a comment") + + def test_AuthorList(self): + """Set author lists""" + s = Song() + assert(s.get_author_list(True) == "") + assert(s.get_author_list(False) == []) + t1 = "John Newton" + s.set_author_list(t1) + assert(s.get_author_list(True) == t1) + assert(s.get_author_list(False) == [t1]) + s.set_author_list(" Peter Done , John Newton") + assert(s.get_author_list(True)== "Peter Done, John Newton") + assert(s.get_author_list(False) == ["Peter Done", "John Newton"]) + s.set_author_list(None) + assert(s.get_author_list(True) == "") + assert(s.get_author_list(False) == []) + s.set_author_list("") + assert(s.get_author_list(True) == "") + assert(s.get_author_list(False) == [""]) + s.set_author_list([]) + assert(s.get_author_list(True) == "") + assert(s.get_author_list(False) == [""]) + + def test_CategoryArray(self): + """Set categories""" + s = Song() + assert(s.get_category_array(True) == "") + assert(s.get_category_array(False) == []) + t1 = "Gospel" + s.set_category_array(t1) + assert(s.get_category_array(True) == t1) + assert(s.get_category_array(False) == [t1]) + s.set_category_array(" Gospel, Hymns ") + assert(s.get_category_array(True) == "Gospel, Hymns") + assert(s.get_category_array(False) == ["Gospel", "Hymns"]) + s.set_category_array(None) + assert(s.get_category_array(True) == "") + assert(s.get_category_array(False) == []) + s.set_category_array("") + assert(s.get_category_array(True) == "") + assert(s.get_category_array(False) == [""]) + s.set_category_array([]) + assert(s.get_category_array(True) == "") + assert(s.get_category_array(False) == [""]) + +if '__main__' == __name__: + r = Test_Basic() + r.test_asString() diff --git a/openlp/plugins/songs/test/test_song_opensong.py b/openlp/plugins/songs/test/test_song_opensong.py index a3f8d0138..33ca13589 100644 --- a/openlp/plugins/songs/test/test_song_opensong.py +++ b/openlp/plugins/songs/test/test_song_opensong.py @@ -122,64 +122,64 @@ class Test_OpenSong(object): def test_sample1(self): """OpenSong: handwritten sample1""" s = Song() - s.FromOpenSongBuffer(_sample1) - l = s.GetLyrics() + s.from_opensong_buffer(_sample1) + l = s.get_lyrics() assert(len(l) == (4*3+3)) - assert(s.GetNumberOfSlides() == 4) + assert(s.get_number_of_slides() == 4) def test_sample2(self): """OpenSong: handwritten sample2 - with verses and chorus""" s = Song() - s.FromOpenSongBuffer(_sample2) - l = s.GetLyrics() + s.from_opensong_buffer(_sample2) + l = s.get_lyrics() assert(len(l) == (4*3+3)) - assert(s.GetNumberOfSlides() == 4) + assert(s.get_number_of_slides() == 4) def test_sample3(self): """OpenSong: handwritten sample3 - with verses, chorus, bridge and pre-chorus""" s = Song() - s.FromOpenSongBuffer(_sample3) - l = s.GetLyrics() + s.from_opensong_buffer(_sample3) + l = s.get_lyrics() assert(len(l) == (4*3+4+5+4)) - assert(s.GetNumberOfSlides() == 6) + assert(s.get_number_of_slides() == 6) def test_file1(self): """OpenSong: parse Amazing Grace""" global __ThisDir__ s = Song() - s.FromOpenSongFile("%s/data_opensong/Amazing Grace"%(__ThisDir__)) - assert(s.GetTitle() == "Amazing Grace") - assert(s.GetCopyright() == "1982 Jubilate Hymns Limited") - assert(s.GetSongCcliNo() == "1037882") - assert(s.GetCategoryArray(True) == "God: Attributes") - assert(s.GetAuthorList(True) == "John Newton") - assert(s.GetVerseOrder() == "") - assert(s.GetNumberOfSlides() == 4) + s.from_opensong_file("%s/data_opensong/Amazing Grace"%(__ThisDir__)) + assert(s.get_title() == "Amazing Grace") + assert(s.get_copyright() == "1982 Jubilate Hymns Limited") + assert(s.get_song_cclino() == "1037882") + assert(s.get_category_array(True) == "God: Attributes") + assert(s.get_author_list(True) == "John Newton") + assert(s.get_verse_order() == "") + assert(s.get_number_of_slides() == 4) def test_file2(self): """OpenSong: parse The Solid Rock""" s = Song() - s.FromOpenSongFile("%s/data_opensong/The Solid Rock"%(__ThisDir__)) - assert(s.GetTitle() == "The Solid Rock") - assert(s.GetCopyright() == "Public Domain") - assert(s.GetSongCcliNo() == "101740") - assert(s.GetCategoryArray(True) == "Christ: Victory, Fruit: Peace/Comfort") - assert(s.GetAuthorList(True) == "Edward Mote, John B. Dykes") - assert(s.GetVerseOrder() == "V1 C V2 C V3 C V4 C") - assert(s.GetNumberOfSlides() == 5) + s.from_opensong_file("%s/data_opensong/The Solid Rock"%(__ThisDir__)) + assert(s.get_title() == "The Solid Rock") + assert(s.get_copyright() == "Public Domain") + assert(s.get_song_cclino() == "101740") + assert(s.get_category_array(True) == "Christ: Victory, Fruit: Peace/Comfort") + assert(s.get_author_list(True) == "Edward Mote, John B. Dykes") + assert(s.get_verse_order() == "V1 C V2 C V3 C V4 C") + assert(s.get_number_of_slides() == 5) def test_file3(self): """OpenSong: parse 'På en fjern ensom høj' (danish)""" #FIXME: problem with XML convert and danish characters s = Song() - s.FromOpenSongFile("%s/data_opensong/På en fjern ensom høj"%(__ThisDir__)) - assert(s.GetTitle() == u"På en fjern ensom høj") - assert(s.GetCopyright() == "") - assert(s.GetSongCcliNo() == "") - assert(s.GetCategoryArray(True) == "") - assert(s.GetAuthorList(True) == "") - assert(s.GetVerseOrder() == "V1 C1 V2 C2 V3 C3 V4 C4") - assert(s.GetNumberOfSlides() == 8) + s.from_opensong_file("%s/data_opensong/På en fjern ensom høj"%(__ThisDir__)) + assert(s.get_title() == u"På en fjern ensom høj") + assert(s.get_copyright() == "") + assert(s.get_song_cclino() == "") + assert(s.get_category_array(True) == "") + assert(s.get_author_list(True) == "") + assert(s.get_verse_order() == "V1 C1 V2 C2 V3 C3 V4 C4") + assert(s.get_number_of_slides() == 8) if '__main__' == __name__: r = Test_OpenSong() diff --git a/openlp/plugins/songs/test/test_song_text.py b/openlp/plugins/songs/test/test_song_text.py index f17e5c989..b7234b9f8 100644 --- a/openlp/plugins/songs/test/test_song_text.py +++ b/openlp/plugins/songs/test/test_song_text.py @@ -35,23 +35,23 @@ class Test_Text(object): """OpenSong: parse CCLI example""" global __ThisDir__ s = Song() - s.FromTextFile("%s/data_text/CCLI example.txt"%(__ThisDir__)) - assert(s.GetTitle() == "Song Title Here") - assert(s.GetAuthorList(True) == "Author, artist name") - assert(s.GetCopyright() == "1996 Publisher Info") - assert(s.GetSongCcliNo() == "1234567") - assert(s.GetNumberOfSlides() == 4) + s.from_ccli_text_file("%s/data_text/CCLI example.txt"%(__ThisDir__)) + assert(s.get_title() == "Song Title Here") + assert(s.get_author_list(True) == "Author, artist name") + assert(s.get_copyright() == "1996 Publisher Info") + assert(s.get_song_cclino() == "1234567") + assert(s.get_number_of_slides() == 4) def test_file2(self): """OpenSong: parse PåEnFjern (danish)""" global __ThisDir__ s = Song() - s.FromTextFile("%s/data_text/PåEnFjern.txt"%(__ThisDir__)) - assert(s.GetTitle() == "På en fjern ensom høj") - assert(s.GetAuthorList(True) == "Georg Bennard") - assert(s.GetCopyright() == "") - assert(s.GetSongCcliNo() == "") - assert(s.GetNumberOfSlides() == 8) + s.from_ccli_text_file("%s/data_text/PåEnFjern.txt"%(__ThisDir__)) + assert(s.get_title() == "På en fjern ensom høj") + assert(s.get_author_list(True) == "Georg Bennard") + assert(s.get_copyright() == "") + assert(s.get_song_cclino() == "") + assert(s.get_number_of_slides() == 8) if '__main__' == __name__: # for local debugging diff --git a/openlp/plugins/songs/test/test_song_verse.py b/openlp/plugins/songs/test/test_song_verse.py index d0a9fdd33..cefebf4c8 100644 --- a/openlp/plugins/songs/test/test_song_verse.py +++ b/openlp/plugins/songs/test/test_song_verse.py @@ -39,11 +39,11 @@ class Test_Verse(object): self.author = "John Newton" self.copyright = "Peter Hamil" self.ccli = "123456" - s.SetLyrics(["# verse","a single line"]) - s.SetTitle(self.title) - s.SetCopyright(self.copyright) - s.SetAuthorList(self.author) - s.SetSongCcliNo(self.ccli) + s.set_lyrics(["# verse","a single line"]) + s.set_title(self.title) + s.set_copyright(self.copyright) + s.set_author_list(self.author) + s.set_song_cclino(self.ccli) return s def check_allfields(self, r, isblank = 0): @@ -69,84 +69,84 @@ class Test_Verse(object): def test_title_show_noshow(self): """Test the show title flag""" s = self.stdSong() - r = s.GetRenderSlide(1) + r = s.get_render_slide(1) self.check_allfields(r) - s.SetShowTitle(False) - r = s.GetRenderSlide(1) + s.set_show_title(False) + r = s.get_render_slide(1) self.check_allfields(r, 1) - s.SetShowTitle(True) - r = s.GetRenderSlide(1) + s.set_show_title(True) + r = s.get_render_slide(1) self.check_allfields(r) def test_author_show_noshow(self): """Test the show author flag""" s = self.stdSong() - r = s.GetRenderSlide(1) + r = s.get_render_slide(1) self.check_allfields(r) - s.SetShowAuthorList(False) - r = s.GetRenderSlide(1) + s.set_show_author_list(False) + r = s.get_render_slide(1) self.check_allfields(r, 2) - s.SetShowAuthorList(True) - r = s.GetRenderSlide(1) + s.set_show_author_list(True) + r = s.get_render_slide(1) self.check_allfields(r) def test_copyright_show_noshow(self): """Test the show copyright flag""" s = self.stdSong() - r = s.GetRenderSlide(1) + r = s.get_render_slide(1) self.check_allfields(r) - s.SetShowCopyright(False) - r = s.GetRenderSlide(1) + s.set_show_copyright(False) + r = s.get_render_slide(1) self.check_allfields(r, 3) - s.SetShowCopyright(True) - r = s.GetRenderSlide(1) + s.set_show_copyright(True) + r = s.get_render_slide(1) self.check_allfields(r) def test_ccli_show_noshow(self): """Test the show copyright flag""" s = self.stdSong() - r = s.GetRenderSlide(1) + r = s.get_render_slide(1) self.check_allfields(r) - s.SetShowSongCcliNo(False) - r = s.GetRenderSlide(1) + s.set_show_song_cclino(False) + r = s.get_render_slide(1) self.check_allfields(r, 4) - s.SetShowSongCcliNo(True) - r = s.GetRenderSlide(1) + s.set_show_song_cclino(True) + r = s.get_render_slide(1) self.check_allfields(r) def test_verse1(self): """Test an empty verse list""" s = Song() - s.SetLyrics([]) - assert(s.GetNumberOfSlides() == 0) + s.set_lyrics([]) + assert(s.get_number_of_slides() == 0) def test_verse2(self): """Test a list with an empty string""" s = Song() - s.SetLyrics([""]) - assert(s.GetNumberOfSlides() == 0) + s.set_lyrics([""]) + assert(s.get_number_of_slides() == 0) def test_verse3a(self): """Test a one liner song""" s = Song() - s.SetLyrics(["Single verse"]) - assert(s.GetNumberOfSlides() == 1) + s.set_lyrics(["Single verse"]) + assert(s.get_number_of_slides() == 1) def test_verse3b(self): """Test a one liner song""" s = Song() - s.SetLyrics(["", "Single verse"]) - assert(s.GetNumberOfSlides() == 1) + s.set_lyrics(["", "Single verse"]) + assert(s.get_number_of_slides() == 1) def test_verse3c(self): """Test a one liner song""" s = Song() - s.SetLyrics(["", "Single verse", "", ""]) - assert(s.GetNumberOfSlides() == 1) + s.set_lyrics(["", "Single verse", "", ""]) + assert(s.get_number_of_slides() == 1) def test_verse3d(self): """Test a one liner song""" s = Song() - s.SetLyrics(["", "# Verse", "", ""]) - assert(s.GetNumberOfSlides() == 1) + s.set_lyrics(["", "# Verse", "", ""]) + assert(s.get_number_of_slides() == 1) \ No newline at end of file