neural-amp-modeler

Neural network emulator for guitar amplifiers
Log | Files | Refs | README | LICENSE

test_settings.py (1294B)


      1 # File: test_resources.py
      2 # Created Date: Tuesday September 17th 2024
      3 # Author: Steven Atkinson (steven@atkinson.mn)
      4 
      5 from contextlib import contextmanager
      6 from pathlib import Path
      7 
      8 import pytest
      9 
     10 from nam.train.gui._resources import settings
     11 
     12 
     13 class TestReadOnly(object):
     14     """
     15     Issue 448
     16     """
     17 
     18     @pytest.mark.parametrize("path_key", tuple(pk for pk in settings.PathKey))
     19     def test_get_last_path(self, path_key: settings.PathKey):
     20         with self._mock_read_only():
     21             last_path = settings.get_last_path(path_key)
     22         assert last_path is None or isinstance(last_path, Path)
     23 
     24     @pytest.mark.parametrize("path_key", tuple(pk for pk in settings.PathKey))
     25     def test_set_last_path(self, path_key: settings.PathKey):
     26         path = Path(__file__).parent / Path("dummy.txt")
     27         with self._mock_read_only():
     28             settings.set_last_path(path_key, path)
     29 
     30     @contextmanager
     31     def _mock_read_only(self):
     32         def write_settings(*args, **kwargs):
     33             raise OSError("Read-only filesystem")
     34 
     35         try:
     36             tmp = settings._write_settings_unsafe
     37             settings._write_settings_unsafe = write_settings
     38             yield
     39         finally:
     40             settings._write_settings_unsafe = tmp
     41 
     42 
     43 if __name__ == "__main__":
     44     pytest.main()