57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
"""Tests for notes loading."""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
import debian_todo
|
|
|
|
|
|
class TestLoadNotes:
|
|
"""Tests for load_notes function."""
|
|
|
|
def test_loads_notes_from_file(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
notes_file.write_text("foo some note\nbar another note\n")
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {"foo": "some note", "bar": "another note"}
|
|
|
|
def test_returns_empty_when_file_missing(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {}
|
|
|
|
def test_handles_package_without_note(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
notes_file.write_text("foo\n")
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {"foo": ""}
|
|
|
|
def test_joins_multiple_notes(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
notes_file.write_text("foo first note\nfoo second note\n")
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {"foo": "first note; second note"}
|
|
|
|
def test_skips_blank_lines(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
notes_file.write_text("foo note one\n\nbar note two\n\n")
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {"foo": "note one", "bar": "note two"}
|
|
|
|
def test_handles_multiword_notes(self, tmp_path, monkeypatch):
|
|
notes_file = tmp_path / "notes"
|
|
notes_file.write_text("foo this is a long note with many words\n")
|
|
monkeypatch.setattr(debian_todo, "NOTES_PATH", notes_file)
|
|
|
|
result = debian_todo.load_notes()
|
|
assert result == {"foo": "this is a long note with many words"}
|