2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2013-09-19 21:02:28 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2013-02-19 12:49:21 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Songs plugin.
|
|
|
|
"""
|
2013-02-12 20:38:43 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
|
2016-06-07 20:21:21 +00:00
|
|
|
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf, transpose_chord
|
2013-02-28 22:20:48 +00:00
|
|
|
from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length
|
2013-09-19 21:02:28 +00:00
|
|
|
from tests.functional import patch, MagicMock
|
2013-02-12 20:38:43 +00:00
|
|
|
|
2013-02-21 08:54:16 +00:00
|
|
|
|
2013-02-12 20:38:43 +00:00
|
|
|
class TestLib(TestCase):
|
2013-02-21 08:54:16 +00:00
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`lib` module.
|
|
|
|
"""
|
2013-02-18 21:42:04 +00:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Mock up two songs and provide a set of lyrics for the songs_probably_equal tests.
|
|
|
|
"""
|
2014-04-02 19:35:09 +00:00
|
|
|
self.full_lyrics = '''amazing grace how sweet the sound that saved a wretch like me i once was lost but now am
|
2013-02-18 21:42:04 +00:00
|
|
|
found was blind but now i see twas grace that taught my heart to fear and grace my fears relieved how
|
2014-04-02 19:35:09 +00:00
|
|
|
precious did that grace appear the hour i first believed through many dangers toils and snares i have
|
|
|
|
already come tis grace that brought me safe thus far and grace will lead me home'''
|
|
|
|
self.short_lyrics = '''twas grace that taught my heart to fear and grace my fears relieved how precious did
|
|
|
|
that grace appear the hour i first believed'''
|
|
|
|
self.error_lyrics = '''amazing how sweet the trumpet that saved a wrench like me i once was losst but now am
|
2013-02-18 21:42:04 +00:00
|
|
|
found waf blind but now i see it was grace that taught my heart to fear and grace my fears relieved how
|
|
|
|
precious did that grace appppppppear the hour i first believedxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx snares i have
|
|
|
|
already come to this grace that brought me safe so far and grace will lead me home'''
|
2014-04-02 19:35:09 +00:00
|
|
|
self.different_lyrics = '''on a hill far away stood an old rugged cross the emblem of suffering and shame and
|
|
|
|
i love that old cross where the dearest and best for a world of lost sinners was slain so ill cherish the
|
|
|
|
old rugged cross till my trophies at last i lay down i will cling to the old rugged cross and exchange it
|
|
|
|
some day for a crown'''
|
2013-02-13 23:15:21 +00:00
|
|
|
|
2013-02-21 08:54:16 +00:00
|
|
|
def clean_string_test(self):
|
|
|
|
"""
|
|
|
|
Test the clean_string() function
|
|
|
|
"""
|
|
|
|
# GIVEN: A "dirty" string
|
2013-08-31 18:17:38 +00:00
|
|
|
dirty_string = 'Ain\'t gonna find\t you there.'
|
2013-02-21 08:54:16 +00:00
|
|
|
|
|
|
|
# WHEN: We run the string through the function
|
|
|
|
result = clean_string(dirty_string)
|
|
|
|
|
|
|
|
# THEN: The string should be cleaned up and lower-cased
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'aint gonna find you there ', 'The string should be cleaned up properly')
|
2013-02-21 08:54:16 +00:00
|
|
|
|
|
|
|
def clean_title_test(self):
|
|
|
|
"""
|
|
|
|
Test the clean_title() function
|
|
|
|
"""
|
|
|
|
# GIVEN: A "dirty" string
|
2013-08-31 18:17:38 +00:00
|
|
|
dirty_string = 'This\u0000 is a\u0014 dirty \u007Fstring\u009F'
|
2013-02-21 08:54:16 +00:00
|
|
|
|
|
|
|
# WHEN: We run the string through the function
|
|
|
|
result = clean_title(dirty_string)
|
|
|
|
|
|
|
|
# THEN: The string should be cleaned up
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'This is a dirty string', 'The title should be cleaned up properly: "%s"' % result)
|
2013-02-20 23:29:54 +00:00
|
|
|
|
2013-02-18 21:42:04 +00:00
|
|
|
def songs_probably_equal_same_song_test(self):
|
2013-02-13 23:15:21 +00:00
|
|
|
"""
|
2013-02-18 21:42:04 +00:00
|
|
|
Test the songs_probably_equal function with twice the same song.
|
2013-02-13 23:15:21 +00:00
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: Two equal songs.
|
2014-11-05 08:42:33 +00:00
|
|
|
song_tuple1 = (2, self.full_lyrics)
|
|
|
|
song_tuple2 = (4, self.full_lyrics)
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We compare those songs for equality.
|
2014-11-05 08:42:33 +00:00
|
|
|
result = songs_probably_equal((song_tuple1, song_tuple2))
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2014-03-31 15:36:11 +00:00
|
|
|
# THEN: The result should be a tuple..
|
2014-11-05 08:42:33 +00:00
|
|
|
assert result == (2, 4), 'The result should be the tuble of song positions'
|
2013-02-18 21:42:04 +00:00
|
|
|
|
|
|
|
def songs_probably_equal_short_song_test(self):
|
|
|
|
"""
|
|
|
|
Test the songs_probably_equal function with a song and a shorter version of the same song.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A song and a short version of the same song.
|
2014-11-05 08:42:33 +00:00
|
|
|
song_tuple1 = (1, self.full_lyrics)
|
|
|
|
song_tuple2 = (3, self.short_lyrics)
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We compare those songs for equality.
|
2014-11-05 08:42:33 +00:00
|
|
|
result = songs_probably_equal((song_tuple1, song_tuple2))
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2014-03-31 15:36:11 +00:00
|
|
|
# THEN: The result should be a tuple..
|
2014-11-05 08:42:33 +00:00
|
|
|
assert result == (1, 3), 'The result should be the tuble of song positions'
|
2013-02-18 21:42:04 +00:00
|
|
|
|
|
|
|
def songs_probably_equal_error_song_test(self):
|
|
|
|
"""
|
|
|
|
Test the songs_probably_equal function with a song and a very erroneous version of the same song.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A song and the same song with lots of errors.
|
2014-11-05 08:42:33 +00:00
|
|
|
song_tuple1 = (4, self.full_lyrics)
|
|
|
|
song_tuple2 = (7, self.error_lyrics)
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We compare those songs for equality.
|
2014-11-05 08:42:33 +00:00
|
|
|
result = songs_probably_equal((song_tuple1, song_tuple2))
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2014-11-05 08:42:33 +00:00
|
|
|
# THEN: The result should be a tuple of song positions.
|
|
|
|
assert result == (4, 7), 'The result should be the tuble of song positions'
|
2013-02-18 21:42:04 +00:00
|
|
|
|
|
|
|
def songs_probably_equal_different_song_test(self):
|
|
|
|
"""
|
|
|
|
Test the songs_probably_equal function with two different songs.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: Two different songs.
|
2014-11-05 08:42:33 +00:00
|
|
|
song_tuple1 = (5, self.full_lyrics)
|
|
|
|
song_tuple2 = (8, self.different_lyrics)
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We compare those songs for equality.
|
2014-11-05 08:42:33 +00:00
|
|
|
result = songs_probably_equal((song_tuple1, song_tuple2))
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2014-04-14 19:36:07 +00:00
|
|
|
# THEN: The result should be None.
|
2014-03-22 09:24:52 +00:00
|
|
|
assert result is None, 'The result should be None'
|
2013-02-20 23:29:54 +00:00
|
|
|
|
|
|
|
def remove_typos_beginning_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a typo at the beginning.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a difference at the beginning.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('replace', 0, 2, 0, 1), ('equal', 2, 11, 1, 10)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-20 23:29:54 +00:00
|
|
|
result = _remove_typos(diff)
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There should be no typos at the beginning anymore.
|
2013-08-31 18:17:38 +00:00
|
|
|
assert len(result) == 1, 'The result should contain only one element.'
|
|
|
|
assert result[0][0] == 'equal', 'The result should contain an equal element.'
|
2013-02-20 23:29:54 +00:00
|
|
|
|
|
|
|
def remove_typos_beginning_negated_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a large difference at the beginning.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a large difference at the beginning.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('replace', 0, 20, 0, 1), ('equal', 20, 29, 1, 10)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-28 22:46:55 +00:00
|
|
|
result = _remove_typos(list(diff))
|
2013-02-20 23:29:54 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There diff should not have changed.
|
2013-02-20 23:29:54 +00:00
|
|
|
assert result == diff
|
|
|
|
|
|
|
|
def remove_typos_end_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a typo at the end.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a difference at the end.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('equal', 0, 10, 0, 10), ('replace', 10, 12, 10, 11)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-20 23:29:54 +00:00
|
|
|
result = _remove_typos(diff)
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There should be no typos at the end anymore.
|
2013-08-31 18:17:38 +00:00
|
|
|
assert len(result) == 1, 'The result should contain only one element.'
|
|
|
|
assert result[0][0] == 'equal', 'The result should contain an equal element.'
|
2013-02-20 23:29:54 +00:00
|
|
|
|
|
|
|
def remove_typos_end_negated_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a large difference at the end.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a large difference at the end.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('equal', 0, 10, 0, 10), ('replace', 10, 20, 10, 1)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-28 22:46:55 +00:00
|
|
|
result = _remove_typos(list(diff))
|
2013-02-20 23:29:54 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There diff should not have changed.
|
2013-02-20 23:29:54 +00:00
|
|
|
assert result == diff
|
|
|
|
|
|
|
|
def remove_typos_middle_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a typo in the middle.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a difference in the middle.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('equal', 0, 10, 0, 10), ('replace', 10, 12, 10, 11), ('equal', 12, 22, 11, 21)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-20 23:29:54 +00:00
|
|
|
result = _remove_typos(diff)
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There should be no typos in the middle anymore. The remaining equals should have been merged.
|
2013-08-31 18:17:38 +00:00
|
|
|
assert len(result) is 1, 'The result should contain only one element.'
|
|
|
|
assert result[0][0] == 'equal', 'The result should contain an equal element.'
|
|
|
|
assert result[0][1] == 0, 'The start indices should be kept.'
|
|
|
|
assert result[0][2] == 22, 'The stop indices should be kept.'
|
|
|
|
assert result[0][3] == 0, 'The start indices should be kept.'
|
|
|
|
assert result[0][4] == 21, 'The stop indices should be kept.'
|
2013-02-20 23:29:54 +00:00
|
|
|
|
|
|
|
def remove_typos_beginning_negated_test(self):
|
|
|
|
"""
|
|
|
|
Test the _remove_typos function with a large difference in the middle.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diffset with a large difference in the middle.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff = [('equal', 0, 10, 0, 10), ('replace', 10, 20, 10, 11), ('equal', 20, 30, 11, 21)]
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We remove the typos in there.
|
2013-02-28 22:46:55 +00:00
|
|
|
result = _remove_typos(list(diff))
|
2013-02-20 23:29:54 +00:00
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: There diff should not have changed.
|
2013-02-20 23:29:54 +00:00
|
|
|
assert result == diff
|
|
|
|
|
|
|
|
def op_length_test(self):
|
|
|
|
"""
|
|
|
|
Test the _op_length function.
|
|
|
|
"""
|
2013-02-28 21:46:36 +00:00
|
|
|
# GIVEN: A diff entry.
|
2013-02-20 23:29:54 +00:00
|
|
|
diff_entry = ('replace', 0, 2, 4, 14)
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# WHEN: We calculate the length of that diff.
|
2013-02-20 23:29:54 +00:00
|
|
|
result = _op_length(diff_entry)
|
|
|
|
|
2013-02-28 21:46:36 +00:00
|
|
|
# THEN: The maximum length should be returned.
|
2013-08-31 18:17:38 +00:00
|
|
|
assert result == 10, 'The length should be 10.'
|
2013-04-06 10:20:17 +00:00
|
|
|
|
2013-09-08 03:50:51 +00:00
|
|
|
def strip_rtf_charsets_test(self):
|
|
|
|
"""
|
|
|
|
Test that the strip_rtf() method properly decodes the supported charsets.
|
|
|
|
"""
|
|
|
|
test_charset_table = [
|
|
|
|
('0', 'weor\\\'F0-myndum \\\'FEah\\par ', 'weorð-myndum þah\n'),
|
|
|
|
('128', '\\\'83C\\\'83G\\\'83X\\\'A5\\\'83L\\\'83\\\'8A\\\'83X\\\'83g\\\'A1 '
|
|
|
|
'\\\\ \\\'95\\\\ \\\'8E\\} \\\'8E\\{ \\\'A1\\par ', 'イエス・キリスト。 ¥ 表 枝 施 。\n'),
|
|
|
|
('129', '\\\'BF\\\'B9\\\'BC\\\'F6 \\\'B1\\\'D7\\\'B8\\\'AE\\\'BD\\\'BA\\\'B5\\\'B5\\par ', '예수 그리스도\n'),
|
|
|
|
('134', '\\\'D2\\\'AE\\\'F6\\\'D5\\\'BB\\\'F9\\\'B6\\\'BD\\\'CA\\\'C7\\\'D6\\\'F7\\par ', '耶稣基督是主\n'),
|
|
|
|
('161', '\\\'D7\\\'F1\\\'E9\\\'F3\\\'F4\\\'FC\\\'F2\\par ', 'Χριστός\n'),
|
|
|
|
('162', 'Hazreti \\\'DDsa\\par ', 'Hazreti İsa\n'),
|
|
|
|
('163', 'ph\\\'FD\\\'F5ng\\par ', 'phương\n'),
|
|
|
|
('177', '\\\'E1\\\'F8\\\'E0\\\'F9\\\'E9\\\'FA\\par ', 'בראשית\n'),
|
|
|
|
('178', '\\\'ED\\\'D3\\\'E6\\\'DA \\\'C7\\\'E1\\\'E3\\\'D3\\\'ED\\\'CD\\par ', 'يسوع المسيح\n'),
|
|
|
|
('186', 'J\\\'EBzus Kristus yra Vie\\\'F0pats\\par ', 'Jėzus Kristus yra Viešpats\n'),
|
|
|
|
('204', '\\\'D0\\\'EE\\\'F1\\\'F1\\\'E8\\\'FF\\par ', 'Россия\n'),
|
|
|
|
('222', '\\\'A4\\\'C3\\\'D4\\\'CA\\\'B5\\\'EC\\par ', 'คริสต์\n'),
|
|
|
|
('238', 'Z\\\'E1v\\\'ECre\\\'E8n\\\'E1 zkou\\\'9Aka\\par ', 'Závěrečná zkouška\n')
|
|
|
|
]
|
|
|
|
|
|
|
|
# GIVEN: For each character set and input
|
|
|
|
for charset, input, exp_result in test_charset_table:
|
|
|
|
|
|
|
|
# WHEN: We call strip_rtf on the input RTF
|
|
|
|
result, result_enc = strip_rtf(
|
2014-04-02 19:35:09 +00:00
|
|
|
'{\\rtf1 \\ansi \\ansicpg1252 {\\fonttbl \\f0 \\fswiss \\fcharset%s Helvetica;}'
|
|
|
|
'{\\colortbl ;\\red0 \\green0 \\blue0 ;}\\pard \\f0 %s}' % (charset, input))
|
2013-09-08 03:50:51 +00:00
|
|
|
|
|
|
|
# THEN: The stripped text matches thed expected result
|
|
|
|
assert result == exp_result, 'The result should be %s' % exp_result
|
|
|
|
|
2016-06-07 20:21:21 +00:00
|
|
|
def transpose_chord_up_test(self):
|
|
|
|
"""
|
|
|
|
Test that the transpose_chord() method works when transposing up
|
|
|
|
"""
|
|
|
|
# GIVEN: A Chord
|
|
|
|
chord = 'C'
|
|
|
|
|
|
|
|
# WHEN: Transposing it 1 up
|
|
|
|
new_chord = transpose_chord(chord, 1, 'english')
|
|
|
|
|
|
|
|
# THEN: The chord should be transposed up one note
|
|
|
|
self.assertEqual(new_chord, 'C#', 'The chord should be transposed up.')
|
|
|
|
|
|
|
|
def transpose_chord_down_test(self):
|
|
|
|
"""
|
|
|
|
Test that the transpose_chord() method works when transposing down
|
|
|
|
"""
|
|
|
|
# GIVEN: A Chord
|
|
|
|
chord = 'C'
|
|
|
|
|
|
|
|
# WHEN: Transposing it 1 down
|
|
|
|
new_chord = transpose_chord(chord, -1, 'english')
|
|
|
|
|
|
|
|
# THEN: The chord should be transposed down one note
|
|
|
|
self.assertEqual(new_chord, 'B', 'The chord should be transposed down.')
|
|
|
|
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
class TestVerseType(TestCase):
|
|
|
|
"""
|
|
|
|
This is a test case to test various methods in the VerseType enumeration class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def translated_tag_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_tag() method returns the correct tags
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 12:49:21 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_tag() method with a "verse"
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_tag('v')
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "V"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'V', 'The result should be "V"')
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
# WHEN: We run the translated_tag() method with a "chorus"
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_tag('c')
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "C"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'C', 'The result should be "C"')
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
def translated_invalid_tag_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_tag() method returns the default tag when passed an invalid tag
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 12:49:21 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_tag() method with an invalid verse type
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_tag('z')
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "O"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'O', 'The result should be "O", but was "%s"' % result)
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
def translated_invalid_tag_with_specified_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_tag() method returns the specified default tag when passed an invalid tag
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 12:49:21 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_tag() method with an invalid verse type and specify a default
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_tag('q', VerseType.Bridge)
|
2013-02-19 12:49:21 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "B"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'B', 'The result should be "B", but was "%s"' % result)
|
2013-02-19 12:49:21 +00:00
|
|
|
|
2013-02-19 14:07:34 +00:00
|
|
|
def translated_invalid_tag_with_invalid_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_tag() method returns a sane default tag when passed an invalid default
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_tag() method with an invalid verse type and an invalid default
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_tag('q', 29)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "O"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'O', 'The result should be "O", but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def translated_name_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_name() method returns the correct name
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_name() method with a "verse"
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_name('v')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "Verse"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'Verse', 'The result should be "Verse"')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# WHEN: We run the translated_name() method with a "chorus"
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_name('c')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "Chorus"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'Chorus', 'The result should be "Chorus"')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def translated_invalid_name_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_name() method returns the default name when passed an invalid tag
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_name() method with an invalid verse type
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_name('z')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "Other"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def translated_invalid_name_with_specified_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_name() method returns the specified default name when passed an invalid tag
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_name() method with an invalid verse type and specify a default
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_name('q', VerseType.Bridge)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "Bridge"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'Bridge', 'The result should be "Bridge", but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def translated_invalid_name_with_invalid_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the translated_name() method returns the specified default tag when passed an invalid tag
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the translated_name() method with an invalid verse type and specify an invalid default
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.translated_name('q', 29)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be "Other"
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def from_tag_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns the correct VerseType.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with a valid verse type, we get the name back
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.from_tag('v')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be VerseType.Verse
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, VerseType.Verse, 'The result should be VerseType.Verse, but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def from_tag_with_invalid_tag_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns the default VerseType when it is passed an invalid tag.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with a valid verse type, we get the name back
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.from_tag('w')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be VerseType.Other
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
def from_tag_with_specified_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns the specified default when passed an invalid tag.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with an invalid verse type, we get the specified default back
|
2013-08-31 18:17:38 +00:00
|
|
|
result = VerseType.from_tag('x', VerseType.Chorus)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be VerseType.Chorus
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, VerseType.Chorus, 'The result should be VerseType.Chorus, but was "%s"' % result)
|
2013-02-19 14:07:34 +00:00
|
|
|
|
2014-04-25 20:04:43 +00:00
|
|
|
def from_tag_with_invalid_intdefault_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns a sane default when passed an invalid tag and an invalid int default.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with an invalid verse type, we get the specified default back
|
|
|
|
result = VerseType.from_tag('m', 29)
|
|
|
|
|
|
|
|
# THEN: The result should be VerseType.Other
|
|
|
|
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
|
|
|
|
|
2013-02-19 14:07:34 +00:00
|
|
|
def from_tag_with_invalid_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns a sane default when passed an invalid tag and an invalid default.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
2013-02-19 14:07:34 +00:00
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with an invalid verse type, we get the specified default back
|
2014-04-25 20:04:43 +00:00
|
|
|
result = VerseType.from_tag('@', 'asdf')
|
2013-02-19 14:07:34 +00:00
|
|
|
|
|
|
|
# THEN: The result should be VerseType.Other
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(result, VerseType.Other, 'The result should be VerseType.Other, but was "%s"' % result)
|
2014-04-25 20:04:43 +00:00
|
|
|
|
|
|
|
def from_tag_with_none_default_test(self):
|
|
|
|
"""
|
|
|
|
Test that the from_tag() method returns a sane default when passed an invalid tag and None as default.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out translate() function that just returns what it was given
|
|
|
|
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
|
|
|
|
mocked_translate.side_effect = lambda x, y: y
|
|
|
|
|
|
|
|
# WHEN: We run the from_tag() method with an invalid verse type, we get the specified default back
|
|
|
|
result = VerseType.from_tag('m', None)
|
|
|
|
|
2014-04-26 05:07:08 +00:00
|
|
|
# THEN: The result should be None
|
2014-04-25 20:04:43 +00:00
|
|
|
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
|