Writing tests for OpenBench components, workflows, and integrations
Source file → Test file
src/openbench/core/foo.py → tests/test_foo.py
src/openbench/data/sources/bar.py → tests/test_bar_source.py
src/openbench/intelligence/baz.py → tests/test_baz_agent.py
# All tests
python -m unittest discover tests -v
# Specific test file
python -m unittest tests.test_abstractions -v
# With coverage
pytest tests/ --cov=openbench --cov-report=term-missing
import unittest
from openbench.core import RawData
from my_module import MyDataSource
class TestMyDataSource(unittest.TestCase):
def setUp(self):
self.source = MyDataSource(config="test")
def test_source_type(self):
self.assertEqual(self.source.source_type, "my-source")
def test_extract(self):
result = self.source.extract()
self.assertIsInstance(result, RawData)
self.assertIsNotNone(result.content)
def test_chainable_invoke(self):
result = self.source.invoke({})
self.assertIsInstance(result, RawData)
import unittest
from openbench.core import Chain, Parallel, Lambda
class TestWorkflowComposition(unittest.TestCase):
def test_sequential_chain(self):
add_one = Lambda(lambda x: x + 1)
multiply_two = Lambda(lambda x: x * 2)
chain = add_one | multiply_two
result = chain.invoke(5)
self.assertEqual(result, 12) # (5 + 1) * 2
def test_parallel_execution(self):
add_one = Lambda(lambda x: x + 1)
multiply_two = Lambda(lambda x: x * 2)
parallel = add_one & multiply_two
result = parallel.invoke(5)
self.assertEqual(result, [6, 10])
from unittest.mock import Mock, patch
class TestWithMocks(unittest.TestCase):
def test_data_layer_with_mock_source(self):
mock_source = Mock()
mock_source.invoke.return_value = Mock(content="test data")
layer = DataLayer(sources=mock_source, stores=[])
result = layer.invoke({})
mock_source.invoke.assert_called_once()
@patch('my_module.external_api')
def test_agent_with_patched_api(self, mock_api):
mock_api.return_value = {"response": "test"}
agent = MyAgent(goal="test")
result = agent.execute(self.context)
self.assertEqual(result.status, "completed")
DO NOT:
assertTrue(validator.validate("hello")) when validate always returns True)Mock* classes for abstractions, @patch for external depsinvoke(), execute(), extract())invoke() and | operatorLLMProvider.generate() / generate_stream() and ToolExecutor → see intelligence-layer skilldata-layer skilladapters skilloutput-layer skillcreating-abstractions skilltest_extract_returns_raw_datasetUp()tearDown()