From f3be2fbfeaf73e570a9aaea6f43932804541946a Mon Sep 17 00:00:00 2001 From: Stanislav Hejny Date: Thu, 24 Jul 2025 08:16:41 +0100 Subject: [PATCH] test: update tests to use invoke_command directly --- tests/adapter/test_rpc.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tests/adapter/test_rpc.py b/tests/adapter/test_rpc.py index 6c43d9d..51f2ed6 100644 --- a/tests/adapter/test_rpc.py +++ b/tests/adapter/test_rpc.py @@ -1,8 +1,8 @@ import importlib -import asyncio import sys import unittest -from amqp.service.amq_message_handler import DataMessageHandler +from amqp.service.amq_message_handler import invoke_command + class TestRPCInvocation(unittest.IsolatedAsyncioTestCase): """Test cases for the RPC invocation functionality in DataMessageHandler.""" @@ -53,8 +53,7 @@ class MyService: async def test_invoke_global_sync_function(self): """Test invoking a global synchronous function.""" - result = await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + result = await invoke_command( class_name="__global__", function_name="greet_sync", kwargs={"name": "Alice"} @@ -63,8 +62,7 @@ class MyService: async def test_invoke_global_async_function(self): """Test invoking a global asynchronous function.""" - result = await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + result = await invoke_command( class_name="__global__", function_name="greet_async", kwargs={"name": "Bob"} @@ -73,8 +71,7 @@ class MyService: async def test_invoke_class_sync_method(self): """Test invoking a class synchronous method.""" - result = await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + result = await invoke_command( class_name="MyService", function_name="process_data_sync", kwargs={"data": "report", "count": 3} @@ -86,8 +83,7 @@ class MyService: async def test_invoke_class_async_method(self): """Test invoking a class asynchronous method.""" - result = await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + result = await invoke_command( class_name="MyService", function_name="process_data_async", kwargs={"data": "metrics", "delay": 0.01} @@ -100,8 +96,7 @@ class MyService: async def test_package_not_found(self): """Test error handling when package is not found.""" with self.assertRaises(ModuleNotFoundError): - await DataMessageHandler.invoke_command( - package_name="non_existent_package", + await invoke_command( class_name="__global__", function_name="some_func", kwargs={} @@ -110,8 +105,7 @@ class MyService: async def test_class_not_found(self): """Test error handling when class is not found.""" with self.assertRaises(AttributeError): - await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + await invoke_command( class_name="NonExistentClass", function_name="some_method", kwargs={} @@ -120,8 +114,7 @@ class MyService: async def test_method_not_found(self): """Test error handling when method is not found.""" with self.assertRaises(AttributeError): - await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + await invoke_command( class_name="MyService", function_name="non_existent_method", kwargs={} @@ -129,8 +122,7 @@ class MyService: async def test_private_method_access(self): """Test that private methods can be accessed (Python doesn't enforce privacy).""" - result = await DataMessageHandler.invoke_command( - package_name="my_package.my_module", + result = await invoke_command( class_name="MyService", function_name="_private_method", kwargs={}