More tests.

This commit is contained in:
Tomas Groth 2017-04-21 21:40:28 +02:00
parent 536a919675
commit f1b34efcac

View File

@ -24,7 +24,7 @@ This module contains tests for the lib submodule of the Songs plugin.
"""
from unittest import TestCase
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf, transpose_chord
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf, transpose_chord, transpose_lyrics
from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length
from tests.functional import patch, MagicMock, PropertyMock
@ -264,7 +264,7 @@ class TestLib(TestCase):
# THEN: The stripped text matches thed expected result
assert result == exp_result, 'The result should be %s' % exp_result
def transpose_chord_up_test(self):
def test_transpose_chord_up(self):
"""
Test that the transpose_chord() method works when transposing up
"""
@ -277,7 +277,20 @@ class TestLib(TestCase):
# 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):
def test_transpose_chord_up_adv(self):
"""
Test that the transpose_chord() method works when transposing up an advanced chord
"""
# GIVEN: An advanced Chord
chord = '(C/D#)'
# 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#/E)', 'The chord should be transposed up.')
def test_transpose_chord_down(self):
"""
Test that the transpose_chord() method works when transposing down
"""
@ -290,6 +303,46 @@ class TestLib(TestCase):
# THEN: The chord should be transposed down one note
self.assertEqual(new_chord, 'B', 'The chord should be transposed down.')
def test_transpose_chord_error(self):
"""
Test that the transpose_chord() raises exception on invalid chord
"""
# GIVEN: A invalid Chord
chord = 'T'
# WHEN: Transposing it 1 down
# THEN: An exception should be raised
with self.assertRaises(ValueError) as err:
new_chord = transpose_chord(chord, -1, 'english')
self.assertEqual(err.exception.args[0], '\'T\' is not in list',
'ValueError exception should have been thrown for invalid chord')
@patch('openlp.plugins.songs.lib.transpose_verse')
@patch('openlp.plugins.songs.lib.Settings')
def test_transpose_lyrics(self, mocked_settings, mocked_transpose_verse):
"""
Test that the transpose_lyrics() splits verses correctly
"""
# GIVEN: Lyrics with verse splitters and a mocked settings
lyrics = '---[Verse:1]---\n'\
'Amazing grace how sweet the sound\n'\
'[---]\n'\
'That saved a wretch like me.\n'\
'---[Verse:2]---\n'\
'I once was lost but now I\'m found.'
mocked_returned_settings = MagicMock()
mocked_returned_settings.value.return_value = 'english'
mocked_settings.return_value = mocked_returned_settings
# WHEN: Transposing the lyrics
transpose_lyrics(lyrics, 1)
# THEN: transpose_verse should have been called
mocked_transpose_verse.assert_any_call('', 1, 'english')
mocked_transpose_verse.assert_any_call('\nAmazing grace how sweet the sound\n', 1, 'english')
mocked_transpose_verse.assert_any_call('\nThat saved a wretch like me.\n', 1, 'english')
mocked_transpose_verse.assert_any_call('\nI once was lost but now I\'m found.', 1, 'english')
class TestVerseType(TestCase):
"""