Fix importing ChordPro files with the correct encoding on Windows

This commit is contained in:
Raoul Snyman 2022-05-20 18:19:13 +00:00 committed by Tomas Groth
parent 59dde255a4
commit 36efab9407
2 changed files with 35 additions and 1 deletions

View File

@ -50,7 +50,7 @@ class ChordProImport(SongImport):
for file_path in self.import_source:
if self.stop_import_flag:
return
with file_path.open('rt') as song_file:
with file_path.open('rt', encoding='utf8') as song_file:
self.do_import_file(song_file)
def do_import_file(self, song_file):

View File

@ -1229,6 +1229,24 @@ def test_load_service_modified_cancel_save(registry):
assert result is False, 'The method did not exit early'
@patch('openlp.core.ui.servicemanager.FileDialog.getOpenFileName')
def test_load_service_without_file_path_canceled(mocked_get_open_file_name, registry):
"""Test that the load_service() method does nothing when no file is loaded and the load dialog is canceled"""
# GIVEN: A modified ServiceManager
mocked_settings = MagicMock()
registry.register('settings', mocked_settings)
service_manager = ServiceManager(None)
service_manager.is_modified = MagicMock(return_value=False)
mocked_get_open_file_name.return_value = None, None
# WHEN: A service is loaded but not path specified, and the load dialog is canceled
result = service_manager.load_service(file_path=None)
# THEN: The result should be False
mocked_get_open_file_name.assert_called_once()
assert result is False
def test_load_service_modified_saved_with_file_path(registry):
"""Test that the load_service() method saves the file and loads the specified file"""
# GIVEN: A modified ServiceManager
@ -1376,6 +1394,22 @@ def test_service_manager_decide_save_method_save_as(registry):
assert service_manager.save_file.call_count == 0, 'The save_file method should not have been called'
def test_load_last_file(registry):
"""Test the load_last_file() method"""
# GIVEN: Mocked out settings and a ServiceManager
mocked_settings = MagicMock()
mocked_settings.value.return_value = Path('filename.osz')
registry.register('settings', mocked_settings)
service_manager = ServiceManager(None)
service_manager.load_file = MagicMock()
# WHEN: load_last_file() is called
service_manager.load_last_file()
# THEN: The file should have been loaded
service_manager.load_file.assert_called_once_with(Path('filename.osz'))
class TestServiceManager(TestCase, TestMixin):
"""
Test the service manager