"""Tests para read_obsidian_note.""" import pytest from read_obsidian_note import read_obsidian_note def _write(path, content): path.parent.mkdir(parents=True, exist_ok=True) path.write_text(content, encoding="utf-8") return str(path) def test_lee_nota_con_frontmatter_y_wikilinks(tmp_path): # Golden path: nota con frontmatter YAML + body con wikilinks. note = _write( tmp_path / "Idea.md", "---\ntitle: Idea\ntags: [proyecto, wip]\n---\n\n" "Cuerpo con [[Otra Nota]] y [[Tercera|alias]].", ) result = read_obsidian_note(note) assert result["path"] == note assert result["frontmatter"]["title"] == "Idea" assert result["tags"] == ["proyecto", "wip"] assert result["wikilinks"] == ["Otra Nota", "Tercera"] assert "Cuerpo con" in result["body"] def test_normaliza_tags_csv_a_lista(tmp_path): # Edge: tags como CSV en vez de lista YAML. note = _write( tmp_path / "CSV.md", "---\ntitle: CSV\ntags: proyecto, wip , done\n---\n\nTexto.", ) result = read_obsidian_note(note) assert result["tags"] == ["proyecto", "wip", "done"] def test_nota_sin_frontmatter(tmp_path): # Edge: nota plana sin frontmatter -> frontmatter vacio, tags vacios. note = _write(tmp_path / "Plana.md", "Solo cuerpo, [[Enlace]] suelto.") result = read_obsidian_note(note) assert result["frontmatter"] == {} assert result["tags"] == [] assert result["wikilinks"] == ["Enlace"] assert result["body"] == "Solo cuerpo, [[Enlace]] suelto." def test_archivo_inexistente_lanza_filenotfounderror(tmp_path): # Error path: ruta inexistente. with pytest.raises(FileNotFoundError): read_obsidian_note(str(tmp_path / "no_existe.md")) def test_directorio_lanza_isadirectoryerror(tmp_path): # Error path: ruta a directorio, no archivo. sub = tmp_path / "carpeta" sub.mkdir() with pytest.raises(IsADirectoryError): read_obsidian_note(str(sub))