Fixing tests

This commit is contained in:
Cyber MacGeddon 2025-09-26 00:59:11 +01:00
parent cfc92918ff
commit 128d7b5ec0
2 changed files with 32 additions and 54 deletions

View file

@ -11,21 +11,24 @@ from trustgraph.base.flow_processor import FlowProcessor
from trustgraph.base import ParameterSpec, ConsumerSpec, ProducerSpec from trustgraph.base import ParameterSpec, ConsumerSpec, ProducerSpec
class MockAsyncProcessor:
def __init__(self, **params):
self.config_handlers = []
self.id = params.get('id', 'test-service')
self.specifications = []
class TestFlowParameterSpecs(IsolatedAsyncioTestCase): class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
"""Test flow processor parameter specification functionality""" """Test flow processor parameter specification functionality"""
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
def test_parameter_spec_registration(self): def test_parameter_spec_registration(self):
"""Test that parameter specs can be registered with flow processors""" """Test that parameter specs can be registered with flow processors"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)
@ -49,16 +52,14 @@ class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
assert "model" in param_names assert "model" in param_names
assert "temperature" in param_names assert "temperature" in param_names
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
def test_mixed_specification_types(self): def test_mixed_specification_types(self):
"""Test registration of mixed specification types (parameters, consumers, producers)""" """Test registration of mixed specification types (parameters, consumers, producers)"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)
@ -85,16 +86,14 @@ class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
assert len(consumer_specs) == 1 assert len(consumer_specs) == 1
assert len(producer_specs) == 1 assert len(producer_specs) == 1
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
def test_parameter_spec_metadata(self): def test_parameter_spec_metadata(self):
"""Test parameter specification metadata handling""" """Test parameter specification metadata handling"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)
@ -119,16 +118,14 @@ class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
assert model_spec_registered.name == "model" assert model_spec_registered.name == "model"
assert temperature_spec_registered.name == "temperature" assert temperature_spec_registered.name == "temperature"
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
def test_duplicate_parameter_spec_handling(self): def test_duplicate_parameter_spec_handling(self):
"""Test handling of duplicate parameter spec registration""" """Test handling of duplicate parameter spec registration"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)
@ -148,17 +145,15 @@ class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
# Either should have 2 duplicates or the system should handle deduplication # Either should have 2 duplicates or the system should handle deduplication
assert len(param_specs) >= 1 # At least one should be registered assert len(param_specs) >= 1 # At least one should be registered
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
@patch('trustgraph.base.flow_processor.Flow') @patch('trustgraph.base.flow_processor.Flow')
async def test_parameter_specs_available_to_flows(self, mock_flow_class): async def test_parameter_specs_available_to_flows(self, mock_flow_class):
"""Test that parameter specs are available when flows are created""" """Test that parameter specs are available when flows are created"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)
@ -190,16 +185,14 @@ class TestFlowParameterSpecs(IsolatedAsyncioTestCase):
class TestParameterSpecValidation(IsolatedAsyncioTestCase): class TestParameterSpecValidation(IsolatedAsyncioTestCase):
"""Test parameter specification validation functionality""" """Test parameter specification validation functionality"""
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
def test_parameter_spec_name_validation(self): def test_parameter_spec_name_validation(self):
"""Test parameter spec name validation""" """Test parameter spec name validation"""
# Arrange # Arrange
def mock_init(self, **kwargs):
self.config_handlers = []
self.id = kwargs.get('id', 'test-service')
config = { config = {
'id': 'test-flow-processor', 'id': 'test-flow-processor',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
processor = FlowProcessor(**config) processor = FlowProcessor(**config)

View file

@ -91,19 +91,14 @@ class TestLlmServiceParameters(IsolatedAsyncioTestCase):
assert temperature_spec is not None assert temperature_spec is not None
assert temperature_spec.name == "temperature" assert temperature_spec.name == "temperature"
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
async def test_on_request_extracts_parameters_from_flow(self): async def test_on_request_extracts_parameters_from_flow(self):
"""Test that on_request method extracts model and temperature from flow""" """Test that on_request method extracts model and temperature from flow"""
# Arrange # Arrange
# Create service instance and manually initialize required attributes
service = LlmService.__new__(LlmService)
service.config_handlers = [] # Required by FlowProcessor
service.flows = {} # Required by FlowProcessor
service.specifications = [] # Required by FlowProcessor
config = { config = {
'id': 'test-llm-service', 'id': 'test-llm-service',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
service = LlmService(**config) service = LlmService(**config)
@ -158,19 +153,14 @@ class TestLlmServiceParameters(IsolatedAsyncioTestCase):
mock_flow.assert_any_call("model") mock_flow.assert_any_call("model")
mock_flow.assert_any_call("temperature") mock_flow.assert_any_call("temperature")
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
async def test_on_request_handles_missing_parameters_gracefully(self): async def test_on_request_handles_missing_parameters_gracefully(self):
"""Test that on_request handles missing parameters gracefully""" """Test that on_request handles missing parameters gracefully"""
# Arrange # Arrange
# Create service instance and manually initialize required attributes
service = LlmService.__new__(LlmService)
service.config_handlers = [] # Required by FlowProcessor
service.flows = {} # Required by FlowProcessor
service.specifications = [] # Required by FlowProcessor
config = { config = {
'id': 'test-llm-service', 'id': 'test-llm-service',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
service = LlmService(**config) service = LlmService(**config)
@ -217,19 +207,14 @@ class TestLlmServiceParameters(IsolatedAsyncioTestCase):
assert call_args[0][2] is None # model (will use processor default) assert call_args[0][2] is None # model (will use processor default)
assert call_args[0][3] is None # temperature (will use processor default) assert call_args[0][3] is None # temperature (will use processor default)
@patch('trustgraph.base.async_processor.AsyncProcessor', MockAsyncProcessor)
async def test_on_request_error_handling_preserves_behavior(self): async def test_on_request_error_handling_preserves_behavior(self):
"""Test that parameter extraction doesn't break existing error handling""" """Test that parameter extraction doesn't break existing error handling"""
# Arrange # Arrange
# Create service instance and manually initialize required attributes
service = LlmService.__new__(LlmService)
service.config_handlers = [] # Required by FlowProcessor
service.flows = {} # Required by FlowProcessor
service.specifications = [] # Required by FlowProcessor
config = { config = {
'id': 'test-llm-service', 'id': 'test-llm-service',
'concurrency': 1 'concurrency': 1,
'taskgroup': AsyncMock()
} }
service = LlmService(**config) service = LlmService(**config)