Add tests.
This commit is contained in:
parent
e80f511155
commit
a7d4bc4ae9
10 changed files with 915 additions and 418 deletions
57
tests/test_notes.py
Normal file
57
tests/test_notes.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"""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"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue