Refactored+update part 1; from UpperCaseWords to lower_case_words

Added attribute songid and changed names

bzr-revno: 275
This commit is contained in:
Carsten Tinggaard 2009-01-06 20:10:03 +00:00
parent 41977dad1c
commit 9887764d51
5 changed files with 919 additions and 902 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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)