fix file_scanner tests

This commit is contained in:
phernandez
2025-01-09 15:22:41 -06:00
parent b68e7461ef
commit 81c1ceecbe
2 changed files with 0 additions and 132 deletions
-44
View File
@@ -1,44 +0,0 @@
"""Writer for note entity markdown files."""
from typing import Optional
from basic_memory.models import Entity as EntityModel
class NoteWriter:
"""Formats notes into markdown files with frontmatter."""
async def format_frontmatter(self, entity: EntityModel) -> dict:
"""Generate frontmatter for note.
Args:
entity: The note entity to format frontmatter for
Returns:
Dictionary of frontmatter fields
"""
frontmatter = {
"id": entity.path_id,
"type": entity.entity_type,
"created": entity.created_at.isoformat(),
"modified": entity.updated_at.isoformat()
}
# Add any entity_metadata that isn't None
if entity.entity_metadata:
frontmatter.update(entity.entity_metadata)
return frontmatter
async def format_content(
self,
entity: EntityModel,
content: str,
) -> str:
"""Format note content as markdown.
Args:
entity: The note entity
content: Raw content to format
Returns:
Formatted markdown content
"""
return content.strip() # Just return the trimmed content
-88
View File
@@ -1,88 +0,0 @@
"""Tests for NoteWriter."""
from datetime import datetime, UTC
import pytest
from basic_memory.markdown.note_writer import NoteWriter
from basic_memory.models import Entity
@pytest.fixture
def note_writer() -> NoteWriter:
return NoteWriter()
@pytest.fixture
def sample_note() -> Entity:
"""Create a sample note entity for testing."""
return Entity(
id=1,
name="test_note",
entity_type="note",
path_id="notes/test_note",
file_path="notes/test_note.md",
created_at=datetime(2025, 1, 1, tzinfo=UTC),
updated_at=datetime(2025, 1, 2, tzinfo=UTC),
)
@pytest.mark.asyncio
async def test_format_frontmatter_basic(note_writer: NoteWriter, sample_note: Entity):
"""Test basic frontmatter formatting."""
frontmatter = await note_writer.format_frontmatter(sample_note)
assert frontmatter["id"] == "notes/test_note"
assert frontmatter["type"] == "note"
assert frontmatter["created"] == "2025-01-01T00:00:00+00:00"
assert frontmatter["modified"] == "2025-01-02T00:00:00+00:00"
@pytest.mark.asyncio
async def test_format_frontmatter_with_metadata(note_writer: NoteWriter, sample_note: Entity):
"""Test frontmatter includes entity metadata."""
sample_note.entity_metadata = {"category": "research", "tags": ["python", "testing"]}
frontmatter = await note_writer.format_frontmatter(sample_note)
assert frontmatter["category"] == "research"
assert frontmatter["tags"] == ["python", "testing"]
assert frontmatter["id"] == "notes/test_note"
@pytest.mark.asyncio
async def test_format_content_basic(note_writer: NoteWriter, sample_note: Entity):
"""Test basic content formatting."""
content = "# Test Note\n\nThis is a test note."
result = await note_writer.format_content(sample_note, content)
assert result == content
@pytest.mark.asyncio
async def test_format_content_strips_whitespace(note_writer: NoteWriter, sample_note: Entity):
"""Test content formatting strips extra whitespace."""
content = "\n\n# Test Note\n\nThis is a test note.\n\n"
result = await note_writer.format_content(sample_note, content)
assert result == "# Test Note\n\nThis is a test note."
@pytest.mark.asyncio
async def test_format_content_preserves_markdown(note_writer: NoteWriter, sample_note: Entity):
"""Test content formatting preserves markdown formatting."""
content = """# Test Note
This note has:
- Bullet points
- *Italic text*
- **Bold text**
- `code blocks`
```python
def test():
pass
```"""
result = await note_writer.format_content(sample_note, content)
assert result == content