Skip to content

Commit 21f7600

Browse files
yyyu-googlecopybara-github
authored andcommitted
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 efbcb52 commit 21f7600

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
@@ -266,7 +266,28 @@ class InstrumentEnum(Enum):
266266
config=types.GenerateContentConfig(audio_timestamp=True),
267267
),
268268
exception_if_mldev='not supported',
269-
)
269+
),
270+
pytest_helper.TestTableItem(
271+
name='test_response_schema_with_default',
272+
parameters=types._GenerateContentParameters(
273+
model='gemini-1.5-flash',
274+
contents=t.t_contents(None, 'What is your name?'),
275+
config={
276+
'response_mime_type': 'application/json',
277+
'response_schema': {
278+
'type': 'OBJECT',
279+
'properties': {
280+
'name': {
281+
'type': 'STRING',
282+
'default': 'default_name',
283+
},
284+
},
285+
},
286+
},
287+
),
288+
exception_if_mldev='not supported',
289+
ignore_keys=['parsed'],
290+
),
270291
]
271292

272293
pytestmark = pytest_helper.setup(

google/genai/types.py

+7
Original file line numberDiff line numberDiff line change
@@ -7985,6 +7985,10 @@ class TestTableItem(_common.BaseModel):
79857985
default=None,
79867986
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.""",
79877987
)
7988+
ignore_keys: Optional[list[str]] = Field(
7989+
default=None,
7990+
description="""Keys to ignore when comparing the request and response. This is useful for tests that are not deterministic.""",
7991+
)
79887992

79897993

79907994
class TestTableItemDict(TypedDict, total=False):
@@ -8010,6 +8014,9 @@ class TestTableItemDict(TypedDict, total=False):
80108014
skip_in_api_mode: Optional[str]
80118015
"""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."""
80128016

8017+
ignore_keys: Optional[list[str]]
8018+
"""Keys to ignore when comparing the request and response. This is useful for tests that are not deterministic."""
8019+
80138020

80148021
TestTableItemOrDict = Union[TestTableItem, TestTableItemDict]
80158022

0 commit comments

Comments
 (0)