forked from openlp/openlp
Invalid chord throws KeyError, not ValueError
This commit is contained in:
parent
cd6fcc31ef
commit
f35dc8c43d
@ -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,28 +791,28 @@ 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]:
|
||||
note_number = notenumbers[notation][note]
|
||||
note_number += transpose_value
|
||||
while note_number > 11:
|
||||
note_number -= 12
|
||||
while note_number < 0:
|
||||
note_number += 12
|
||||
if isbass:
|
||||
if lastchord:
|
||||
note = scales[notation][lastchord][note_number]
|
||||
elif key:
|
||||
note = scales[notation][key][note_number]
|
||||
else:
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
#if note in notenumbers[notation]:
|
||||
note_number = notenumbers[notation][note]
|
||||
note_number += transpose_value
|
||||
while note_number > 11:
|
||||
note_number -= 12
|
||||
while note_number < 0:
|
||||
note_number += 12
|
||||
if isbass:
|
||||
if lastchord:
|
||||
note = scales[notation][lastchord][note_number]
|
||||
elif key:
|
||||
note = scales[notation][key][note_number]
|
||||
else:
|
||||
if not key or thischordchangeskey:
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
else:
|
||||
note = scales[notation][key][note_number]
|
||||
transposed_chord += note + minor + chord
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
else:
|
||||
transposed_chord += note + chord
|
||||
if not key or thischordchangeskey:
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
else:
|
||||
note = scales[notation][key][note_number]
|
||||
transposed_chord += note + minor + 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