forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_doc_parsing.py
115 lines (86 loc) · 2.66 KB
/
test_doc_parsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from agents.function_schema import generate_func_documentation
def func_foo_google(a: int, b: float) -> str:
"""
This is func_foo.
Args:
a: The first argument.
b: The second argument.
Returns:
A result
"""
return "ok"
def func_foo_numpy(a: int, b: float) -> str:
"""
This is func_foo.
Parameters
----------
a: int
The first argument.
b: float
The second argument.
Returns
-------
str
A result
"""
return "ok"
def func_foo_sphinx(a: int, b: float) -> str:
"""
This is func_foo.
:param a: The first argument.
:param b: The second argument.
:return: A result
"""
return "ok"
class Bar:
def func_bar(self, a: int, b: float) -> str:
"""
This is func_bar.
Args:
a: The first argument.
b: The second argument.
Returns:
A result
"""
return "ok"
@classmethod
def func_baz(cls, a: int, b: float) -> str:
"""
This is func_baz.
Args:
a: The first argument.
b: The second argument.
Returns:
A result
"""
return "ok"
def test_functions_are_ok():
func_foo_google(1, 2.0)
func_foo_numpy(1, 2.0)
func_foo_sphinx(1, 2.0)
Bar().func_bar(1, 2.0)
Bar.func_baz(1, 2.0)
def test_auto_detection() -> None:
doc = generate_func_documentation(func_foo_google)
assert doc.name == "func_foo_google"
assert doc.description == "This is func_foo."
assert doc.param_descriptions == {"a": "The first argument.", "b": "The second argument."}
doc = generate_func_documentation(func_foo_numpy)
assert doc.name == "func_foo_numpy"
assert doc.description == "This is func_foo."
assert doc.param_descriptions == {"a": "The first argument.", "b": "The second argument."}
doc = generate_func_documentation(func_foo_sphinx)
assert doc.name == "func_foo_sphinx"
assert doc.description == "This is func_foo."
assert doc.param_descriptions == {"a": "The first argument.", "b": "The second argument."}
def test_instance_method() -> None:
bar = Bar()
doc = generate_func_documentation(bar.func_bar)
assert doc.name == "func_bar"
assert doc.description == "This is func_bar."
assert doc.param_descriptions == {"a": "The first argument.", "b": "The second argument."}
def test_classmethod() -> None:
doc = generate_func_documentation(Bar.func_baz)
assert doc.name == "func_baz"
assert doc.description == "This is func_baz."
assert doc.param_descriptions == {"a": "The first argument.", "b": "The second argument."}