MCPcopy Index your code
hub / github.com/google/adk-python / MockPlugin

Class MockPlugin

tests/unittests/test_runners.py:135–189  ·  view source on GitHub ↗

Mock plugin for unit testing.

Source from the content-addressed store, hash-verified

133
134
135class MockPlugin(BasePlugin):
136 """Mock plugin for unit testing."""
137
138 ON_USER_CALLBACK_MSG = (
139 "Modified user message ON_USER_CALLBACK_MSG from MockPlugin"
140 )
141 ON_EVENT_CALLBACK_MSG = "Modified event ON_EVENT_CALLBACK_MSG from MockPlugin"
142 ON_EVENT_CALLBACK_METADATA = {"plugin_key": "plugin_value"}
143
144 def __init__(self):
145 super().__init__(name="mock_plugin")
146 self.enable_user_message_callback = False
147 self.enable_event_callback = False
148 self.user_content_seen_in_before_run_callback = None
149
150 async def on_user_message_callback(
151 self,
152 *,
153 invocation_context: InvocationContext,
154 user_message: types.Content,
155 ) -> Optional[types.Content]:
156 if not self.enable_user_message_callback:
157 return None
158 return types.Content(
159 role="model",
160 parts=[types.Part(text=self.ON_USER_CALLBACK_MSG)],
161 )
162
163 async def before_run_callback(
164 self,
165 *,
166 invocation_context: InvocationContext,
167 ) -> None:
168 self.user_content_seen_in_before_run_callback = (
169 invocation_context.user_content
170 )
171
172 async def on_event_callback(
173 self, *, invocation_context: InvocationContext, event: Event
174 ) -> Optional[Event]:
175 if not self.enable_event_callback:
176 return None
177 return Event(
178 invocation_id="",
179 author="",
180 content=types.Content(
181 parts=[
182 types.Part(
183 text=self.ON_EVENT_CALLBACK_MSG,
184 )
185 ],
186 role=event.content.role,
187 ),
188 custom_metadata=self.ON_EVENT_CALLBACK_METADATA,
189 )
190
191
192class TestRunnerFindAgentToRun:

Calls

no outgoing calls