Skip to content

Commit

Permalink
test(messages)✅: Add tests for DeveloperMessage creation and dev() fu…
Browse files Browse the repository at this point in the history
…nction

- Added a new test case to validate the dev() function with various input types.
- Test cases include single string, multiple strings, file path, existing DeveloperMessage, and mixed inputs.
- Handled edge cases such as non-existent files and other message types.
  • Loading branch information
ericmjl committed Dec 20, 2024
1 parent 6cf6f39 commit 18b36ce
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/bot/test_structuredbot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Tests for StructuredBot."""

import pytest
from typing import Optional

from llamabot.components.messages import SystemMessage
from llamabot.bot.structuredbot import StructuredBot
from llamabot.prompt_manager import prompt
from pydantic import BaseModel, Field
from llamabot.components.messages import SystemMessage
from typing import Optional


@prompt
Expand Down
50 changes: 50 additions & 0 deletions tests/components/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
AIMessage,
ToolMessage,
process_messages,
dev,
DeveloperMessage,
)


Expand Down Expand Up @@ -70,3 +72,51 @@ def test_process_messages_with_nested_types():
assert result[2].content == "nested message 1"
assert isinstance(result[3], HumanMessage)
assert result[3].content == "nested message 2"


def test_dev_message_creation(tmp_path):
"""Test that the dev() function creates DeveloperMessages correctly.
Tests various input types including strings, paths, and existing messages.
"""
from pytest import raises

# Create a temporary file for testing
test_file = tmp_path / "dev_notes.txt"
test_file.write_text("Add error handling")

# Test single string input
msg1 = dev("Write tests")
assert isinstance(msg1, DeveloperMessage)
assert msg1.content == "Write tests"

# Test multiple string inputs
msg2 = dev("Write tests", "with good coverage")
assert isinstance(msg2, DeveloperMessage)
assert msg2.content == "Write tests with good coverage"

# Test file path input
msg3 = dev(test_file)
assert isinstance(msg3, DeveloperMessage)
assert msg3.content == "Add error handling"

# Test existing DeveloperMessage input
existing_msg = DeveloperMessage(content="Refactor code")
msg4 = dev(existing_msg, "to be more modular")
assert isinstance(msg4, DeveloperMessage)
assert msg4.content == "Refactor code to be more modular"

# Test mixed input types
msg5 = dev("Add docstrings", test_file, DeveloperMessage(content="Follow PEP8"))
assert isinstance(msg5, DeveloperMessage)
assert msg5.content == "Add docstrings Add error handling Follow PEP8"

# Test with non-existent file
with raises(FileNotFoundError):
dev(tmp_path / "nonexistent.txt")

# Test with other message types
human_msg = HumanMessage(content="Test message")
msg6 = dev(human_msg)
assert isinstance(msg6, DeveloperMessage)
assert msg6.content == "Test message"

0 comments on commit 18b36ce

Please sign in to comment.