13
13
# limitations under the License.
14
14
15
15
16
- from toolbox_core .tool import create_docstring
16
+ from unittest .mock import AsyncMock , Mock
17
+
18
+ import pytest
19
+
20
+ from toolbox_core .tool import create_docstring , resolve_value
17
21
18
22
19
23
def test_create_docstring_no_params ():
@@ -27,3 +31,64 @@ def test_create_docstring_no_params():
27
31
28
32
assert result_docstring == description
29
33
assert "\n \n Args:" not in result_docstring
34
+
35
+
36
+ @pytest .mark .asyncio
37
+ @pytest .mark .parametrize (
38
+ "non_callable_source" ,
39
+ [
40
+ "a simple string" ,
41
+ 12345 ,
42
+ True ,
43
+ False ,
44
+ None ,
45
+ [1 , "two" , 3.0 ],
46
+ {"key" : "value" , "number" : 100 },
47
+ object (),
48
+ ],
49
+ ids = [
50
+ "string" ,
51
+ "integer" ,
52
+ "bool_true" ,
53
+ "bool_false" ,
54
+ "none" ,
55
+ "list" ,
56
+ "dict" ,
57
+ "object" ,
58
+ ],
59
+ )
60
+ async def test_resolve_value_non_callable (non_callable_source ):
61
+ """
62
+ Tests resolve_value when the source is not callable.
63
+ """
64
+ resolved = await resolve_value (non_callable_source )
65
+
66
+ assert resolved is non_callable_source
67
+
68
+
69
+ @pytest .mark .asyncio
70
+ async def test_resolve_value_sync_callable ():
71
+ """
72
+ Tests resolve_value with a synchronous callable.
73
+ """
74
+ expected_value = "sync result"
75
+ sync_callable = Mock (return_value = expected_value )
76
+
77
+ resolved = await resolve_value (sync_callable )
78
+
79
+ sync_callable .assert_called_once ()
80
+ assert resolved == expected_value
81
+
82
+
83
+ @pytest .mark .asyncio
84
+ async def test_resolve_value_async_callable ():
85
+ """
86
+ Tests resolve_value with an asynchronous callable (coroutine function).
87
+ """
88
+ expected_value = "async result"
89
+ async_callable = AsyncMock (return_value = expected_value )
90
+
91
+ resolved = await resolve_value (async_callable )
92
+
93
+ async_callable .assert_awaited_once ()
94
+ assert resolved == expected_value
0 commit comments