-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: for both config editors, catch and alert on file permission erro…
…rs (#105) This fixes a user reported bug whereby config saves with invalid (or impermissible) file paths would fail silently. Tested by: Both unit tests, and a local sim test to make sure the error dialog pops up.
- Loading branch information
Showing
3 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import tempfile | ||
from configparser import ConfigParser | ||
|
||
import pytest | ||
|
||
import tests.control.gui_test_stubs | ||
import control.widgets | ||
|
||
|
||
def test_config_editor_for_acquisitions_save_to_file(qtbot): | ||
config_editor = control.widgets.ConfigEditorForAcquisitions( | ||
tests.control.gui_test_stubs.get_test_configuration_manager() | ||
) | ||
|
||
(good_fd, good_filename) = tempfile.mkstemp() | ||
os.close(good_fd) | ||
assert config_editor.config.write_configuration(good_filename) | ||
os.remove(good_filename) | ||
|
||
(bad_fd, bad_filename) = tempfile.mkstemp() | ||
os.close(bad_fd) | ||
read_only_permissions = 0o444 | ||
os.chmod(bad_filename, read_only_permissions) | ||
|
||
assert not config_editor.config.write_configuration(bad_filename) | ||
|
||
|
||
def test_config_editor_save_to_file(qtbot): | ||
config_editor = control.widgets.ConfigEditor(ConfigParser()) | ||
|
||
(good_fd, good_filename) = tempfile.mkstemp() | ||
os.close(good_fd) | ||
assert config_editor.save_to_filename(good_filename) | ||
os.remove(good_filename) | ||
|
||
(bad_fd, bad_filename) = tempfile.mkstemp() | ||
os.close(bad_fd) | ||
read_only_permissions = 0o444 | ||
os.chmod(bad_filename, read_only_permissions) | ||
|
||
assert not config_editor.save_to_filename(bad_filename) |