From 62155c63bae7a9e6a5e334e383d2935faa58e066 Mon Sep 17 00:00:00 2001 From: tangkong Date: Fri, 4 Aug 2023 11:00:45 -0700 Subject: [PATCH 1/4] BUG/TST: allow new note to be written if no data exists, add unit test --- typhos/notes.py | 4 +++- typhos/tests/test_notes.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/typhos/notes.py b/typhos/notes.py index c9944e0f..c0dda772 100644 --- a/typhos/notes.py +++ b/typhos/notes.py @@ -99,7 +99,9 @@ def insert_into_yaml(path: Path, device_name: str, data: dict[str, str]) -> None with open(path, 'r') as f: device_notes = yaml.full_load(f) except Exception as ex: - logger.warning(f'unable to open existing device info: {ex}') + logger.warning(f'Unable to open existing device info: {ex}.' + 'Creating new notes file.') + device_notes = {} device_notes[device_name] = data diff --git a/typhos/tests/test_notes.py b/typhos/tests/test_notes.py index fdb98166..5da958ef 100644 --- a/typhos/tests/test_notes.py +++ b/typhos/tests/test_notes.py @@ -41,6 +41,23 @@ def env_notes_path(tmp_path: Path): os.environ.pop(NOTES_VAR) +def test_new_note(qtbot: QtBot, tmp_path: Path, monkeypatch): + monkeypatch.setattr(platformdirs, 'user_data_path', + lambda: tmp_path) + + user_path = tmp_path / 'device_notes.yaml' + assert not user_path.exists() + + notes_edit = TyphosNotesEdit() + qtbot.addWidget(notes_edit) + notes_edit.setup_data('Syn:Motor') + + notes_edit.setText('hello new text') + notes_edit.save_note() + + assert user_path.exists() + + def test_note_shadowing(qtbot: QtBot, user_notes_path: Path, env_notes_path: Path): # user data shadows all other sources notes_edit = TyphosNotesEdit() From 6f6c8880eab362a4bc05a0d1c9d1f1043a408a5b Mon Sep 17 00:00:00 2001 From: tangkong Date: Fri, 4 Aug 2023 11:04:38 -0700 Subject: [PATCH 2/4] DOC: pre-release notes --- .../562-bug_notes_blank_env.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst diff --git a/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst b/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst new file mode 100644 index 00000000..15da4643 --- /dev/null +++ b/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst @@ -0,0 +1,22 @@ +562 bug_notes_blank_env +####################### + +API Changes +----------- +- N/A + +Features +-------- +- N/A + +Bugfixes +-------- +- allows new notes to be created if requested note file does not exist + +Maintenance +----------- +- N/A + +Contributors +------------ +- tangkong From e4d96991080b12e81e807b702357017806568945 Mon Sep 17 00:00:00 2001 From: Robert Tang-Kong <35379409+tangkong@users.noreply.github.com> Date: Fri, 4 Aug 2023 11:32:01 -0700 Subject: [PATCH 3/4] DOC: update pre-release notes Co-authored-by: Ken Lauer --- docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst b/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst index 15da4643..aba9968d 100644 --- a/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst +++ b/docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst @@ -11,7 +11,7 @@ Features Bugfixes -------- -- allows new notes to be created if requested note file does not exist +- Creates new notes file if requested note file does not exist Maintenance ----------- From d7a99909b71679d2012cb3050230b7abbc9fae57 Mon Sep 17 00:00:00 2001 From: tangkong Date: Fri, 4 Aug 2023 11:43:59 -0700 Subject: [PATCH 4/4] MNT: discern FileNotFoundError from other Exceptions --- typhos/notes.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/typhos/notes.py b/typhos/notes.py index c0dda772..6c7d712c 100644 --- a/typhos/notes.py +++ b/typhos/notes.py @@ -98,10 +98,13 @@ def insert_into_yaml(path: Path, device_name: str, data: dict[str, str]) -> None try: with open(path, 'r') as f: device_notes = yaml.full_load(f) - except Exception as ex: - logger.warning(f'Unable to open existing device info: {ex}.' - 'Creating new notes file.') + except FileNotFoundError: + logger.info(f'No existing device notes found at {path}. ' + 'Creating new notes file.') device_notes = {} + except Exception as ex: + logger.warning(f'Unable to open existing device notes, aborting: {ex}') + return device_notes[device_name] = data