Skip to content

Commit

Permalink
Merge pull request #562 from tangkong/bug_notes_blank_env
Browse files Browse the repository at this point in the history
BUG/TST: allow new note to be written if no data exists, add unit test
  • Loading branch information
tangkong authored Aug 7, 2023
2 parents 7fa80c5 + fe1b80d commit 3058673
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/source/upcoming_release_notes/562-bug_notes_blank_env.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
562 bug_notes_blank_env
#######################

API Changes
-----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- Creates new notes file if requested note file does not exist

Maintenance
-----------
- N/A

Contributors
------------
- tangkong
7 changes: 6 additions & 1 deletion typhos/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +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 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 info: {ex}')
logger.warning(f'Unable to open existing device notes, aborting: {ex}')
return

device_notes[device_name] = data

Expand Down
17 changes: 17 additions & 0 deletions typhos/tests/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3058673

Please sign in to comment.