test: update tests to use invoke_command directly

This commit is contained in:
Stanislav Hejny
2025-07-24 08:16:41 +01:00
committed by Stanislav Hejny (aider)
parent ad49cb2836
commit f3be2fbfea
+10 -18
View File
@@ -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={}