|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from strands.hooks import AgentInitializedEvent, BeforeInvocationEvent, BeforeToolCallEvent, HookRegistry, Plugin |
| 5 | +from strands.hooks import AgentInitializedEvent, BeforeInvocationEvent, BeforeToolCallEvent, HookRegistry |
6 | 6 | from strands.interrupt import Interrupt, _InterruptState |
7 | 7 |
|
8 | 8 |
|
@@ -168,115 +168,3 @@ def __call__(self, event: "NonExistentType") -> None: # noqa: F821 |
168 | 168 |
|
169 | 169 | with pytest.raises(ValueError, match="failed to get type hints for callback"): |
170 | 170 | registry.add_callback(None, callback) |
171 | | - |
172 | | - |
173 | | -# Plugin Protocol Tests |
174 | | - |
175 | | - |
176 | | -def test_plugin_protocol_is_runtime_checkable(): |
177 | | - """Test that Plugin Protocol is runtime checkable with isinstance.""" |
178 | | - |
179 | | - class MyPlugin: |
180 | | - name = "my-plugin" |
181 | | - |
182 | | - def init_plugin(self, agent): |
183 | | - pass |
184 | | - |
185 | | - plugin = MyPlugin() |
186 | | - assert isinstance(plugin, Plugin) |
187 | | - |
188 | | - |
189 | | -def test_plugin_protocol_sync_implementation(): |
190 | | - """Test Plugin Protocol works with synchronous init_plugin.""" |
191 | | - |
192 | | - class SyncPlugin: |
193 | | - name = "sync-plugin" |
194 | | - |
195 | | - def init_plugin(self, agent): |
196 | | - agent.custom_attribute = "initialized by plugin" |
197 | | - |
198 | | - plugin = SyncPlugin() |
199 | | - mock_agent = unittest.mock.Mock() |
200 | | - |
201 | | - # Verify the plugin matches the protocol |
202 | | - assert isinstance(plugin, Plugin) |
203 | | - assert plugin.name == "sync-plugin" |
204 | | - |
205 | | - # Execute init_plugin synchronously |
206 | | - plugin.init_plugin(mock_agent) |
207 | | - assert mock_agent.custom_attribute == "initialized by plugin" |
208 | | - |
209 | | - |
210 | | -@pytest.mark.asyncio |
211 | | -async def test_plugin_protocol_async_implementation(): |
212 | | - """Test Plugin Protocol works with asynchronous init_plugin.""" |
213 | | - |
214 | | - class AsyncPlugin: |
215 | | - name = "async-plugin" |
216 | | - |
217 | | - async def init_plugin(self, agent): |
218 | | - agent.custom_attribute = "initialized by async plugin" |
219 | | - |
220 | | - plugin = AsyncPlugin() |
221 | | - mock_agent = unittest.mock.Mock() |
222 | | - |
223 | | - # Verify the plugin matches the protocol |
224 | | - assert isinstance(plugin, Plugin) |
225 | | - assert plugin.name == "async-plugin" |
226 | | - |
227 | | - # Execute init_plugin asynchronously |
228 | | - await plugin.init_plugin(mock_agent) |
229 | | - assert mock_agent.custom_attribute == "initialized by async plugin" |
230 | | - |
231 | | - |
232 | | -def test_plugin_protocol_requires_name(): |
233 | | - """Test that Plugin Protocol requires a name property.""" |
234 | | - |
235 | | - class PluginWithoutName: |
236 | | - def init_plugin(self, agent): |
237 | | - pass |
238 | | - |
239 | | - plugin = PluginWithoutName() |
240 | | - # A class without 'name' should not pass isinstance check |
241 | | - assert not isinstance(plugin, Plugin) |
242 | | - |
243 | | - |
244 | | -def test_plugin_protocol_requires_init_plugin_method(): |
245 | | - """Test that Plugin Protocol requires an init_plugin method.""" |
246 | | - |
247 | | - class PluginWithoutInitPlugin: |
248 | | - name = "incomplete-plugin" |
249 | | - |
250 | | - plugin = PluginWithoutInitPlugin() |
251 | | - # A class without 'init_plugin' should not pass isinstance check |
252 | | - assert not isinstance(plugin, Plugin) |
253 | | - |
254 | | - |
255 | | -def test_plugin_protocol_with_class_attribute_name(): |
256 | | - """Test Plugin Protocol works when name is a class attribute.""" |
257 | | - |
258 | | - class PluginWithClassAttribute: |
259 | | - name: str = "class-attr-plugin" |
260 | | - |
261 | | - def init_plugin(self, agent): |
262 | | - pass |
263 | | - |
264 | | - plugin = PluginWithClassAttribute() |
265 | | - assert isinstance(plugin, Plugin) |
266 | | - assert plugin.name == "class-attr-plugin" |
267 | | - |
268 | | - |
269 | | -def test_plugin_protocol_with_property_name(): |
270 | | - """Test Plugin Protocol works when name is a property.""" |
271 | | - |
272 | | - class PluginWithProperty: |
273 | | - @property |
274 | | - def name(self): |
275 | | - return "property-plugin" |
276 | | - |
277 | | - def init_plugin(self, agent): |
278 | | - pass |
279 | | - |
280 | | - plugin = PluginWithProperty() |
281 | | - assert isinstance(plugin, Plugin) |
282 | | - assert plugin.name == "property-plugin" |
0 commit comments