Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion tests/test_function_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from agents import RunContextWrapper
from agents.exceptions import UserError
from agents.function_schema import function_schema
from agents.function_schema import _detect_docstring_style, function_schema


def no_args_function():
Expand Down Expand Up @@ -885,3 +885,37 @@ def func_with_annotated_multiple_field_constraints(

with pytest.raises(ValidationError): # zero factor
fs.params_pydantic_model(**{"score": 50, "factor": 0.0})


@pytest.mark.parametrize(
("doc", "expected"),
[
# Sphinx (reStructuredText) field markers.
(":param x: the value\n:type x: int\n:return: result\n:rtype: int", "sphinx"),
# NumPy section headers with dashed underlines.
("Parameters\n----------\nx : int\n The value.\n\nReturns\n-------\nint\n", "numpy"),
# Google section headers.
("Does a thing.\n\nArgs:\n x: The value.\n\nReturns:\n The result.", "google"),
# No recognizable markers falls back to google.
("Just a plain description with no sections.", "google"),
# An empty docstring falls back to google.
("", "google"),
],
)
def test_detect_docstring_style(doc, expected):
assert _detect_docstring_style(doc) == expected


@pytest.mark.parametrize(
("doc", "expected"),
[
# Sphinx outranks numpy when scores tie.
(":param x: the value\nParameters\n----------\nx : int\n", "sphinx"),
# Sphinx outranks google when scores tie.
(":param x: the value\nArgs:\n x: the value", "sphinx"),
# NumPy outranks google when scores tie.
("Parameters\n----------\nx : int\n\nArgs:\n x: the value", "numpy"),
],
)
def test_detect_docstring_style_tie_break_priority(doc, expected):
assert _detect_docstring_style(doc) == expected