Achieve 100% test coverage with comprehensive improvements
Enhanced test suite from 97% to 100% coverage with 173 passing tests. ## New Features ### 1. Error Handling Tests (3 tests) - test_add_message_handles_read_error_gracefully - test_add_message_handles_write_error_gracefully - test_clear_user_history_handles_permission_error - test_logger_reuses_existing_handlers Coverage: memory.py 91% → 100%, utils.py 98% → 100% ### 2. Integration Tests (9 tests) - test_integration.py - test_mention_to_response_workflow: Full message flow - test_conversation_context_preserved: Multi-turn conversations - test_config_to_components_integration: Component initialization - test_error_recovery_workflow: Graceful error handling - test_mention_detection_integration_with_nicknames - test_memory_limit_enforcement_in_workflow - test_ambiguous_greeting_workflow - test_logger_integration_with_memory - test_logger_integration_with_ai_provider - test_config_validation_workflow ### 3. Parameterized Tests (45 tests) - 18 mention detection test cases - 17 greeting detection test cases - 8 content extraction test cases - Covers edge cases, unicode, nicknames, false positives ### 4. GitHub Actions CI Workflow - Multi-Python version testing (3.9, 3.10, 3.11, 3.12) - Automated coverage reporting - Code quality checks (Black, isort, flake8) - Codecov integration - Coverage badge generation ## Test Statistics - Tests: 116 → 173 (+49% increase) - Coverage: 97% → 100% (+3pp) - Execution time: ~1.1 seconds - All components: 100% coverage ## Files Modified - tests/test_utils.py: Added parameterized tests and error handling - tests/test_memory.py: Added error handling tests - tests/test_integration.py: NEW - Full integration test suite - tests/README.md: Updated documentation - .github/workflows/test.yml: NEW - CI/CD automation
This commit is contained in:
parent
f6813b5fa5
commit
90a70a85eb
5 changed files with 553 additions and 18 deletions
|
|
@ -327,3 +327,39 @@ class TestConversationMemory:
|
|||
# Only message within retention should be kept
|
||||
assert len(retrieved) == 1
|
||||
assert retrieved[0]["content"] == "Just under boundary"
|
||||
|
||||
def test_add_message_handles_read_error_gracefully(self, temp_dir, mocker):
|
||||
"""Test that add_message handles file read errors gracefully"""
|
||||
memory = ConversationMemory(data_dir=str(temp_dir))
|
||||
|
||||
# Create a file first
|
||||
memory.add_message("testuser", "user", "First message")
|
||||
|
||||
# Mock json.load to raise an exception
|
||||
mocker.patch("json.load", side_effect=PermissionError("Permission denied"))
|
||||
|
||||
# Should not crash, should handle the error gracefully
|
||||
memory.add_message("testuser", "user", "Second message")
|
||||
|
||||
def test_add_message_handles_write_error_gracefully(self, temp_dir, mocker):
|
||||
"""Test that add_message handles file write errors gracefully"""
|
||||
memory = ConversationMemory(data_dir=str(temp_dir))
|
||||
|
||||
# Mock json.dump to raise an exception
|
||||
mocker.patch("json.dump", side_effect=IOError("Disk full"))
|
||||
|
||||
# Should not crash even when write fails
|
||||
memory.add_message("testuser", "user", "Test message")
|
||||
|
||||
def test_clear_user_history_handles_permission_error(self, temp_dir, mocker):
|
||||
"""Test that clear_user_history handles permission errors gracefully"""
|
||||
memory = ConversationMemory(data_dir=str(temp_dir))
|
||||
|
||||
# Create a user file
|
||||
memory.add_message("testuser", "user", "Test message")
|
||||
|
||||
# Mock unlink to raise permission error
|
||||
mocker.patch("pathlib.Path.unlink", side_effect=PermissionError("Permission denied"))
|
||||
|
||||
# Should not crash
|
||||
memory.clear_user_history("testuser")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue