forked from openlp/openlp
Invalid chord throws KeyError, not ValueError
This commit is contained in:
parent
97f9a8ee34
commit
7adfd3e4dd
@ -124,12 +124,12 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
try:
|
||||
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), 1)
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
except ValueError as ve:
|
||||
except KeyError as ke:
|
||||
# Transposing failed
|
||||
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),
|
||||
message=translate('SongsPlugin.EditVerseForm',
|
||||
'Transposing failed because of invalid chord:\n{err_msg}'
|
||||
.format(err_msg=ve)))
|
||||
.format(err_msg=ke)))
|
||||
return
|
||||
self.verse_text_edit.setFocus()
|
||||
self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
|
||||
@ -141,12 +141,12 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
try:
|
||||
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), -1)
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
except ValueError as ve:
|
||||
except KeyError as ke:
|
||||
# Transposing failed
|
||||
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),
|
||||
message=translate('SongsPlugin.EditVerseForm',
|
||||
'Transposing failed because of invalid chord:\n{err_msg}'
|
||||
.format(err_msg=ve)))
|
||||
.format(err_msg=ke)))
|
||||
return
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
self.verse_text_edit.setFocus()
|
||||
@ -235,11 +235,11 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
try:
|
||||
transpose_lyrics(self.verse_text_edit.toPlainText(), 0)
|
||||
super(EditVerseForm, self).accept()
|
||||
except ValueError as ve:
|
||||
except KeyError as ke:
|
||||
# Transposing failed
|
||||
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Invalid Chord'),
|
||||
message=translate('SongsPlugin.EditVerseForm',
|
||||
'An invalid chord was detected:\n{err_msg}'
|
||||
.format(err_msg=ve)))
|
||||
.format(err_msg=ke)))
|
||||
else:
|
||||
super(EditVerseForm, self).accept()
|
||||
|
@ -791,7 +791,7 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
chord = chord[1:] if len(chord) > 1 else ''
|
||||
else:
|
||||
minor = ''
|
||||
if note in notenumbers[notation]:
|
||||
#if note in notenumbers[notation]:
|
||||
note_number = notenumbers[notation][note]
|
||||
note_number += transpose_value
|
||||
while note_number > 11:
|
||||
@ -811,8 +811,8 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
else:
|
||||
note = scales[notation][key][note_number]
|
||||
transposed_chord += note + minor + chord
|
||||
else:
|
||||
transposed_chord += note + chord
|
||||
#else:
|
||||
# transposed_chord += note + chord
|
||||
if thischordchangeskey:
|
||||
key = note + minor
|
||||
else:
|
||||
|
@ -339,10 +339,10 @@ def test_transpose_chord_error():
|
||||
|
||||
# WHEN: Transposing it 1 down
|
||||
# THEN: An exception should be raised
|
||||
with pytest.raises(ValueError) as err:
|
||||
with pytest.raises(KeyError) as err:
|
||||
transpose_chord(chord, -1, 'english', None, None, False)
|
||||
assert err.value != ValueError('\'T\' is not in list'), \
|
||||
'ValueError exception should have been thrown for invalid chord'
|
||||
assert err.value != KeyError('\'T\' is not in list'), \
|
||||
'KeyError exception should have been thrown for invalid chord'
|
||||
|
||||
|
||||
@patch('openlp.plugins.songs.lib.transpose_verse')
|
||||
|
Loading…
Reference in New Issue
Block a user