Skip to content

Commit

Permalink
Check if autosave directory exists on configure call
Browse files Browse the repository at this point in the history
stop autosave IOC test from running forever
  • Loading branch information
jsouter committed Sep 2, 2024
1 parent 6064c9c commit 8fd797b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions softioc/autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def configure(
enabled: boolean which enables or disables autosave, set to True by
default, or False if configure not called.
"""
Autosave.directory = Path(directory)
directory_path = Path(directory)
if not directory_path.is_dir():
raise FileNotFoundError(
f"{directory} is not a valid autosave directory"
)
Autosave.directory = directory_path
Autosave.timestamped_backups = timestamped_backups
Autosave.save_period = save_period
Autosave.enabled = enabled
Expand Down Expand Up @@ -136,7 +141,7 @@ def __exit__(self, A, B, C):

@classmethod
def __backup_sav_file(cls):
if not cls.directory and cls.directory.is_dir():
if not cls.directory or not cls.directory.is_dir():
print(
f"Could not back up autosave as {cls.directory} is"
" not a valid directory",
Expand Down
6 changes: 4 additions & 2 deletions tests/test_autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ def test_autosave_defaults():
def test_configure_dir_doesnt_exist(tmp_path):
DEVICE_NAME = "MY_DEVICE"
builder.aOut("MY-RECORD", autosave=True)
autosave.configure(tmp_path / "subdir-doesnt-exist", DEVICE_NAME)
with pytest.raises(FileNotFoundError):
autosave.load_autosave()
autosave.configure(tmp_path / "subdir-doesnt-exist", DEVICE_NAME)


def test_returns_if_init_called_before_configure():
Expand Down Expand Up @@ -374,6 +373,8 @@ def check_all_record_types_save_properly(device_name, autosave_dir, conn):
assert saved["Action"] == 1
assert (saved["WaveformIn"] == numpy.array([1, 2, 3, 4])).all()
assert (saved["WaveformOut"] == numpy.array([1, 2, 3, 4])).all()
autosave.Autosave._stop()
# force autosave thread to stop to ensure pytest exits
conn.send("D")


Expand Down Expand Up @@ -403,6 +404,7 @@ def check_autosave_field_names_contain_device_prefix(
saved = yaml.full_load(f)
assert "BEFORE" in saved.keys()
assert f"{device_name}:AFTER" in saved.keys()
autosave.Autosave._stop()
conn.send("D")


Expand Down

0 comments on commit 8fd797b

Please sign in to comment.