-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Handle settings on read-only filesystem (#465)
* Handle settings on read-only filesystems * Cleanup
- Loading branch information
1 parent
17273de
commit 26fdad7
Showing
6 changed files
with
83 additions
and
12 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,3 @@ | ||
# File: __init__.py | ||
# Created Date: Tuesday September 17th 2024 | ||
# Author: Steven Atkinson ([email protected]) |
File renamed without changes.
Empty file.
44 changes: 44 additions & 0 deletions
44
tests/test_nam/test_train/test_gui/test_resources/test_settings.py
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,44 @@ | ||
# File: test_resources.py | ||
# Created Date: Tuesday September 17th 2024 | ||
# Author: Steven Atkinson ([email protected]) | ||
|
||
from contextlib import contextmanager | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from nam.train.gui._resources import settings | ||
|
||
|
||
class TestReadOnly(object): | ||
""" | ||
Issue 448 | ||
""" | ||
|
||
@pytest.mark.parametrize("path_key", tuple(pk for pk in settings.PathKey)) | ||
def test_get_last_path(self, path_key: settings.PathKey): | ||
with self._mock_read_only(): | ||
last_path = settings.get_last_path(path_key) | ||
assert last_path is None or isinstance(last_path, Path) | ||
|
||
@pytest.mark.parametrize("path_key", tuple(pk for pk in settings.PathKey)) | ||
def test_set_last_path(self, path_key: settings.PathKey): | ||
path = Path(__file__).parent / Path("dummy.txt") | ||
with self._mock_read_only(): | ||
settings.set_last_path(path_key, path) | ||
|
||
@contextmanager | ||
def _mock_read_only(self): | ||
def write_settings(*args, **kwargs): | ||
raise OSError("Read-only filesystem") | ||
|
||
try: | ||
tmp = settings._write_settings_unsafe | ||
settings._write_settings_unsafe = write_settings | ||
yield | ||
finally: | ||
settings._write_settings_unsafe = tmp | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main() |