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