Skip to content

Commit a7105a6

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: schema transformer logic fix.
tests: include several specific response schema tests to verify that tSchema logic is handled properly across all languages. and enable replay test framework support ignoreKeys in response comparison PiperOrigin-RevId: 738616785
1 parent 2d12f54 commit a7105a6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

google/genai/tests/models/test_generate_content.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,28 @@ class InstrumentEnum(Enum):
276276
config=types.GenerateContentConfig(audio_timestamp=True),
277277
),
278278
exception_if_mldev='not supported',
279-
)
279+
),
280+
pytest_helper.TestTableItem(
281+
name='test_response_schema_with_default',
282+
parameters=types._GenerateContentParameters(
283+
model='gemini-1.5-flash',
284+
contents=t.t_contents(None, 'What is your name?'),
285+
config={
286+
'response_mime_type': 'application/json',
287+
'response_schema': {
288+
'type': 'OBJECT',
289+
'properties': {
290+
'name': {
291+
'type': 'STRING',
292+
'default': 'default_name',
293+
},
294+
},
295+
},
296+
},
297+
),
298+
exception_if_mldev='not supported',
299+
ignore_keys=['parsed'],
300+
),
280301
]
281302

282303
pytestmark = pytest_helper.setup(

google/genai/types.py

+7
Original file line numberDiff line numberDiff line change
@@ -8061,6 +8061,10 @@ class TestTableItem(_common.BaseModel):
80618061
default=None,
80628062
description="""When set to a reason string, this test will be skipped in the API mode. Use this flag for tests that can not be reproduced with the real API. E.g. a test that deletes a resource.""",
80638063
)
8064+
ignore_keys: Optional[list[str]] = Field(
8065+
default=None,
8066+
description="""Keys to ignore when comparing the request and response. This is useful for tests that are not deterministic.""",
8067+
)
80648068

80658069

80668070
class TestTableItemDict(TypedDict, total=False):
@@ -8086,6 +8090,9 @@ class TestTableItemDict(TypedDict, total=False):
80868090
skip_in_api_mode: Optional[str]
80878091
"""When set to a reason string, this test will be skipped in the API mode. Use this flag for tests that can not be reproduced with the real API. E.g. a test that deletes a resource."""
80888092

8093+
ignore_keys: Optional[list[str]]
8094+
"""Keys to ignore when comparing the request and response. This is useful for tests that are not deterministic."""
8095+
80898096

80908097
TestTableItemOrDict = Union[TestTableItem, TestTableItemDict]
80918098

0 commit comments

Comments
 (0)