|
| 1 | +import asyncio |
| 2 | + |
1 | 3 | import pytest |
2 | | -from examples import ExampleClassA, ExampleClassC |
| 4 | +from examples import ExampleAsyncClass, ExampleClassA, ExampleClassC |
3 | 5 |
|
4 | 6 | from objinspect import Class |
5 | 7 |
|
@@ -78,3 +80,27 @@ def test_instance_classmethod_filter_only_excludes_classmethods(): |
78 | 80 | method_names = [method.name for method in cls.methods] |
79 | 81 | assert "public_method" in method_names |
80 | 82 | assert "class_method" not in method_names |
| 83 | + |
| 84 | + |
| 85 | +def test_classmethod_can_be_called_without_initialization(): |
| 86 | + cls = Class(ExampleClassC, classmethod=True) |
| 87 | + assert cls.call_method("class_method") is None |
| 88 | + |
| 89 | + |
| 90 | +def test_async_method_call_requires_initialization(): |
| 91 | + cls = Class(ExampleAsyncClass, classmethod=True) |
| 92 | + with pytest.raises(ValueError, match="is not initialized"): |
| 93 | + asyncio.run(cls.call_method_async("async_instance_method", 3)) |
| 94 | + |
| 95 | + |
| 96 | +def test_async_static_and_class_methods_call_without_initialization(): |
| 97 | + cls = Class(ExampleAsyncClass, classmethod=True) |
| 98 | + assert asyncio.run(cls.call_method_async("async_static_method", 4)) == 5 |
| 99 | + assert asyncio.run(cls.call_method_async("async_class_method", "ok")) == "ExampleAsyncClass:ok" |
| 100 | + |
| 101 | + |
| 102 | +def test_async_call_on_initialized_instance(): |
| 103 | + cls = Class(ExampleAsyncClass) |
| 104 | + cls.init("pref") |
| 105 | + assert asyncio.run(cls.call_method_async("async_instance_method", 7)) == "pref:7" |
| 106 | + assert asyncio.run(cls.call_method_async("sync_method", 7)) == 14 |
0 commit comments