forked from openlp/openlp
Fix tag detection. Fixes bug 1549549.
Fixes: https://launchpad.net/bugs/1549549
This commit is contained in:
parent
b74221daff
commit
7c6e1902c4
@ -256,6 +256,7 @@ class VerseType(object):
|
|||||||
for num, translation in enumerate(VerseType.translated_names):
|
for num, translation in enumerate(VerseType.translated_names):
|
||||||
if verse_name == translation.lower():
|
if verse_name == translation.lower():
|
||||||
return num
|
return num
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_loose_input(verse_name, default=Other):
|
def from_loose_input(verse_name, default=Other):
|
||||||
@ -271,7 +272,7 @@ class VerseType(object):
|
|||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_string(verse_name, default)
|
verse_index = VerseType.from_string(verse_name, default)
|
||||||
elif len(verse_name) == 1:
|
elif len(verse_name) == 1:
|
||||||
verse_index = VerseType.from_translated_tag(verse_name, default)
|
verse_index = VerseType.from_translated_tag(verse_name, None)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_tag(verse_name, default)
|
verse_index = VerseType.from_tag(verse_name, default)
|
||||||
else:
|
else:
|
||||||
|
@ -26,12 +26,12 @@ import sys
|
|||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
if sys.version_info[1] >= 3:
|
if sys.version_info[1] >= 3:
|
||||||
from unittest.mock import ANY, MagicMock, patch, mock_open, call
|
from unittest.mock import ANY, MagicMock, patch, mock_open, call, PropertyMock
|
||||||
else:
|
else:
|
||||||
from mock import ANY, MagicMock, patch, mock_open, call
|
from mock import ANY, MagicMock, patch, mock_open, call, PropertyMock
|
||||||
|
|
||||||
# Only one QApplication can be created. Use QtWidgets.QApplication.instance() when you need to "create" a QApplication.
|
# Only one QApplication can be created. Use QtWidgets.QApplication.instance() when you need to "create" a QApplication.
|
||||||
application = QtWidgets.QApplication([])
|
application = QtWidgets.QApplication([])
|
||||||
application.setApplicationName('OpenLP')
|
application.setApplicationName('OpenLP')
|
||||||
|
|
||||||
__all__ = ['ANY', 'MagicMock', 'patch', 'mock_open', 'call', 'application']
|
__all__ = ['ANY', 'MagicMock', 'patch', 'mock_open', 'call', 'application', 'PropertyMock']
|
||||||
|
@ -26,7 +26,7 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf
|
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf
|
||||||
from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length
|
from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length
|
||||||
from tests.functional import patch, MagicMock
|
from tests.functional import patch, MagicMock, PropertyMock
|
||||||
|
|
||||||
|
|
||||||
class TestLib(TestCase):
|
class TestLib(TestCase):
|
||||||
@ -477,3 +477,27 @@ class TestVerseType(TestCase):
|
|||||||
|
|
||||||
# THEN: The result should be None
|
# THEN: The result should be None
|
||||||
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
|
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
|
||||||
|
|
||||||
|
@patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x'])
|
||||||
|
def from_loose_input_with_invalid_input_test(self, mocked_translated_tags):
|
||||||
|
"""
|
||||||
|
Test that the from_loose_input() method returns a sane default when passed an invalid tag and None as default.
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked VerseType.translated_tags
|
||||||
|
# WHEN: We run the from_loose_input() method with an invalid verse type, we get the specified default back
|
||||||
|
result = VerseType.from_loose_input('m', None)
|
||||||
|
|
||||||
|
# THEN: The result should be None
|
||||||
|
self.assertIsNone(result, 'The result should be None, but was "%s"' % result)
|
||||||
|
|
||||||
|
@patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x'])
|
||||||
|
def from_loose_input_with_valid_input_test(self, mocked_translated_tags):
|
||||||
|
"""
|
||||||
|
Test that the from_loose_input() method returns valid output on valid input.
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked VerseType.translated_tags
|
||||||
|
# WHEN: We run the from_loose_input() method with a valid verse type, we get the expected VerseType back
|
||||||
|
result = VerseType.from_loose_input('v')
|
||||||
|
|
||||||
|
# THEN: The result should be a Verse
|
||||||
|
self.assertEqual(result, VerseType.Verse, 'The result should be a verse, but was "%s"' % result)
|
||||||
|
Loading…
Reference in New Issue
Block a user