From bdd687fa693a580738813074194d01fb2c9e105d Mon Sep 17 00:00:00 2001 From: thejesshwar Date: Wed, 7 Jan 2026 22:56:04 +0530 Subject: [PATCH 1/5] test: add verification for documentation suite template --- tests/test_suite_template.py | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_suite_template.py diff --git a/tests/test_suite_template.py b/tests/test_suite_template.py new file mode 100644 index 0000000..87917f9 --- /dev/null +++ b/tests/test_suite_template.py @@ -0,0 +1,74 @@ +import pytest +from dataclasses import dataclass +from typing import Generator, Any +from agentunit import Scenario +from agentunit.adapters.base import AdapterOutcome, BaseAdapter +# Note: Adjust these imports based on what is actually in suite_template.py +# You might need to check src/agentunit/core/context.py or similar for exact types if these fail. + +# --- 1. MOCK THE CLASSES FROM THE TEMPLATE --- +# (We copy the essence of FAQAdapter/DatasetSource here since we can't import from docs/) + +@dataclass +class FAQItem: + question: str + answer: str + +class MockDataset: + """Simulates the dataset source from the template.""" + def __iter__(self) -> Generator[FAQItem, None, None]: + yield FAQItem("What is AgentUnit?", "A framework.") + yield FAQItem("Is it open source?", "Yes.") + +class MockAgent: + """A fake agent that always answers correctly.""" + def connect(self) -> None: + pass + + def answer(self, question: str) -> str: + # Simple logic to simulate an agent + if "AgentUnit" in question: + return "A framework." + return "Yes." + +class FAQAdapter(BaseAdapter): + """ + This mimics the adapter in docs/templates/suite_template.py + """ + def __init__(self): + self.agent = MockAgent() + + # RENAME: setup -> prepare + def prepare(self) -> None: + self.agent.connect() + + # RENAME: run -> execute + def execute(self, input_data: FAQItem) -> AdapterOutcome: + # The core logic we want to test + response = self.agent.answer(input_data.question) + + # Simple exact match check + success = (response == input_data.answer) + + return AdapterOutcome(success=success,output=response) + +# --- 2. THE TEST CASE --- + +def test_suite_template_flow(): + """ + Verifies that the FAQAdapter logic from the documentation template + works correctly with a mock agent. + """ + # 1. Setup the scenario with our adapter and dataset + dataset = MockDataset() + adapter = FAQAdapter() + + # 2. Call the correct lifecycle methods + adapter.prepare() # Was adapter.setup() + + for item in dataset: + outcome = adapter.execute(item) # Was adapter.run(item) + + # 3. Assertions + assert outcome.success is True + assert outcome.output == item.answer \ No newline at end of file From 9149a67d9b6f1518a7a3e05e13423248b41f5b7c Mon Sep 17 00:00:00 2001 From: thejesshwar Date: Wed, 7 Jan 2026 22:57:26 +0530 Subject: [PATCH 2/5] test: add verification for documentation suite template --- tests/test_suite_template.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/test_suite_template.py b/tests/test_suite_template.py index 87917f9..4d4287e 100644 --- a/tests/test_suite_template.py +++ b/tests/test_suite_template.py @@ -3,11 +3,6 @@ from typing import Generator, Any from agentunit import Scenario from agentunit.adapters.base import AdapterOutcome, BaseAdapter -# Note: Adjust these imports based on what is actually in suite_template.py -# You might need to check src/agentunit/core/context.py or similar for exact types if these fail. - -# --- 1. MOCK THE CLASSES FROM THE TEMPLATE --- -# (We copy the essence of FAQAdapter/DatasetSource here since we can't import from docs/) @dataclass class FAQItem: @@ -37,12 +32,8 @@ class FAQAdapter(BaseAdapter): """ def __init__(self): self.agent = MockAgent() - - # RENAME: setup -> prepare def prepare(self) -> None: self.agent.connect() - - # RENAME: run -> execute def execute(self, input_data: FAQItem) -> AdapterOutcome: # The core logic we want to test response = self.agent.answer(input_data.question) @@ -52,8 +43,6 @@ def execute(self, input_data: FAQItem) -> AdapterOutcome: return AdapterOutcome(success=success,output=response) -# --- 2. THE TEST CASE --- - def test_suite_template_flow(): """ Verifies that the FAQAdapter logic from the documentation template @@ -62,12 +51,10 @@ def test_suite_template_flow(): # 1. Setup the scenario with our adapter and dataset dataset = MockDataset() adapter = FAQAdapter() - - # 2. Call the correct lifecycle methods - adapter.prepare() # Was adapter.setup() + adapter.prepare() for item in dataset: - outcome = adapter.execute(item) # Was adapter.run(item) + outcome = adapter.execute(item) # 3. Assertions assert outcome.success is True From bff4ba760c6a35004945d6f61ea7ebb5edd6d40a Mon Sep 17 00:00:00 2001 From: thejesshwar Date: Wed, 7 Jan 2026 23:06:50 +0530 Subject: [PATCH 3/5] fix: resolve linting errors --- tests/test_suite_template.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_suite_template.py b/tests/test_suite_template.py index 4d4287e..62d54b1 100644 --- a/tests/test_suite_template.py +++ b/tests/test_suite_template.py @@ -1,9 +1,9 @@ -import pytest +from collections.abc import Generator from dataclasses import dataclass -from typing import Generator, Any -from agentunit import Scenario + from agentunit.adapters.base import AdapterOutcome, BaseAdapter + @dataclass class FAQItem: question: str @@ -11,7 +11,7 @@ class FAQItem: class MockDataset: """Simulates the dataset source from the template.""" - def __iter__(self) -> Generator[FAQItem, None, None]: + def __iter__(self) -> Generator[FAQItem]: yield FAQItem("What is AgentUnit?", "A framework.") yield FAQItem("Is it open source?", "Yes.") @@ -37,10 +37,10 @@ def prepare(self) -> None: def execute(self, input_data: FAQItem) -> AdapterOutcome: # The core logic we want to test response = self.agent.answer(input_data.question) - + # Simple exact match check success = (response == input_data.answer) - + return AdapterOutcome(success=success,output=response) def test_suite_template_flow(): @@ -51,11 +51,11 @@ def test_suite_template_flow(): # 1. Setup the scenario with our adapter and dataset dataset = MockDataset() adapter = FAQAdapter() - adapter.prepare() - + adapter.prepare() + for item in dataset: - outcome = adapter.execute(item) - + outcome = adapter.execute(item) + # 3. Assertions assert outcome.success is True - assert outcome.output == item.answer \ No newline at end of file + assert outcome.output == item.answer From ef7d57fa6f6a4bd782be99a04f12d13d867f4a4d Mon Sep 17 00:00:00 2001 From: thejesshwar Date: Wed, 7 Jan 2026 23:21:48 +0530 Subject: [PATCH 4/5] style: apply ruff formatting --- tests/test_suite_template.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_suite_template.py b/tests/test_suite_template.py index 62d54b1..6e13283 100644 --- a/tests/test_suite_template.py +++ b/tests/test_suite_template.py @@ -9,14 +9,18 @@ class FAQItem: question: str answer: str + class MockDataset: """Simulates the dataset source from the template.""" + def __iter__(self) -> Generator[FAQItem]: yield FAQItem("What is AgentUnit?", "A framework.") yield FAQItem("Is it open source?", "Yes.") + class MockAgent: """A fake agent that always answers correctly.""" + def connect(self) -> None: pass @@ -26,22 +30,27 @@ def answer(self, question: str) -> str: return "A framework." return "Yes." + class FAQAdapter(BaseAdapter): """ This mimics the adapter in docs/templates/suite_template.py """ + def __init__(self): self.agent = MockAgent() + def prepare(self) -> None: self.agent.connect() + def execute(self, input_data: FAQItem) -> AdapterOutcome: # The core logic we want to test response = self.agent.answer(input_data.question) # Simple exact match check - success = (response == input_data.answer) + success = response == input_data.answer + + return AdapterOutcome(success=success, output=response) - return AdapterOutcome(success=success,output=response) def test_suite_template_flow(): """ From fc59b953288483a3a5f6b3126ebb12433352d74e Mon Sep 17 00:00:00 2001 From: thejesshwar Date: Wed, 7 Jan 2026 23:36:28 +0530 Subject: [PATCH 5/5] fix: update adapter signature to match BaseAdapter --- tests/test_suite_template.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_suite_template.py b/tests/test_suite_template.py index 6e13283..3d17e76 100644 --- a/tests/test_suite_template.py +++ b/tests/test_suite_template.py @@ -2,6 +2,7 @@ from dataclasses import dataclass from agentunit.adapters.base import AdapterOutcome, BaseAdapter +from agentunit.core.trace import TraceLog @dataclass @@ -42,14 +43,17 @@ def __init__(self): def prepare(self) -> None: self.agent.connect() - def execute(self, input_data: FAQItem) -> AdapterOutcome: + def execute(self, case: FAQItem, trace: TraceLog | None = None) -> AdapterOutcome: # The core logic we want to test - response = self.agent.answer(input_data.question) + response = self.agent.answer(case.question) # Simple exact match check - success = response == input_data.answer + success = response == case.answer - return AdapterOutcome(success=success, output=response) + return AdapterOutcome( + success=success, + output=response, + ) def test_suite_template_flow():