Test suite executed from CI pipeline (#433)

* Test strategy & test cases

* Unit tests

* Integration tests
This commit is contained in:
cybermaggedon 2025-07-14 14:57:44 +01:00 committed by GitHub
parent 9c7a070681
commit 2f7fddd206
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
101 changed files with 17811 additions and 1 deletions

View file

@ -0,0 +1,3 @@
"""
Common utilities for text completion tests
"""

View file

@ -0,0 +1,69 @@
"""
Base test patterns that can be reused across different text completion models
"""
from abc import ABC, abstractmethod
from unittest.mock import AsyncMock, MagicMock, patch
from unittest import IsolatedAsyncioTestCase
class BaseTextCompletionTestCase(IsolatedAsyncioTestCase, ABC):
"""
Base test class for text completion processors
Provides common test patterns that can be reused
"""
@abstractmethod
def get_processor_class(self):
"""Return the processor class to test"""
pass
@abstractmethod
def get_base_config(self):
"""Return base configuration for the processor"""
pass
@abstractmethod
def get_mock_patches(self):
"""Return list of patch decorators for mocking dependencies"""
pass
def create_base_config(self, **overrides):
"""Create base config with optional overrides"""
config = self.get_base_config()
config.update(overrides)
return config
def create_mock_llm_result(self, text="Test response", in_token=10, out_token=5):
"""Create a mock LLM result"""
from trustgraph.base import LlmResult
return LlmResult(text=text, in_token=in_token, out_token=out_token)
class CommonTestPatterns:
"""
Common test patterns that can be used across different models
"""
@staticmethod
def basic_initialization_test_pattern(test_instance):
"""
Test pattern for basic processor initialization
test_instance should be a BaseTextCompletionTestCase
"""
# This would contain the common pattern for initialization testing
pass
@staticmethod
def successful_generation_test_pattern(test_instance):
"""
Test pattern for successful content generation
"""
pass
@staticmethod
def error_handling_test_pattern(test_instance):
"""
Test pattern for error handling
"""
pass

View file

@ -0,0 +1,53 @@
"""
Common mocking utilities for text completion tests
"""
from unittest.mock import AsyncMock, MagicMock
class CommonMocks:
"""Common mock objects used across text completion tests"""
@staticmethod
def create_mock_async_processor_init():
"""Create mock for AsyncProcessor.__init__"""
mock = MagicMock()
mock.return_value = None
return mock
@staticmethod
def create_mock_llm_service_init():
"""Create mock for LlmService.__init__"""
mock = MagicMock()
mock.return_value = None
return mock
@staticmethod
def create_mock_response(text="Test response", prompt_tokens=10, completion_tokens=5):
"""Create a mock response object"""
response = MagicMock()
response.text = text
response.usage_metadata.prompt_token_count = prompt_tokens
response.usage_metadata.candidates_token_count = completion_tokens
return response
@staticmethod
def create_basic_config():
"""Create basic config with required fields"""
return {
'concurrency': 1,
'taskgroup': AsyncMock(),
'id': 'test-processor'
}
class MockPatches:
"""Common patch decorators for different services"""
@staticmethod
def get_base_patches():
"""Get patches that are common to all processors"""
return [
'trustgraph.base.async_processor.AsyncProcessor.__init__',
'trustgraph.base.llm_service.LlmService.__init__'
]