Skip to content

Commit 20e81dd

Browse files
QEDadycopybara-github
authored andcommitted
fix: test fix internal
PiperOrigin-RevId: 855176412
1 parent 0705a37 commit 20e81dd

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

tests/unit/vertexai/genai/replays/test_create_agent_engine.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import re
19+
import sys
1920

2021
from tests.unit.vertexai.genai.replays import pytest_helper
2122
from vertexai._genai import types
@@ -123,12 +124,36 @@ def test_create_with_source_packages(
123124
mock_agent_engine_create_base64_encoded_tarball,
124125
mock_agent_engine_create_path_exists,
125126
):
126-
"""Tests creating an agent engine with source packages."""
127-
with (
128-
mock_agent_engine_create_base64_encoded_tarball,
129-
mock_agent_engine_create_path_exists,
130-
):
131-
agent_engine = client.agent_engines.create(
127+
"""Tests creating an agent engine with source packages."""
128+
if sys.version_info >= (3, 13):
129+
try:
130+
client._api_client._initialize_replay_session_if_not_loaded()
131+
if client._api_client.replay_session:
132+
target_ver = f"{sys.version_info.major}.{sys.version_info.minor}"
133+
for interaction in client._api_client.replay_session.interactions:
134+
135+
def _update_ver(obj):
136+
if isinstance(obj, dict):
137+
if "python_spec" in obj and isinstance(obj["python_spec"], dict):
138+
if "version" in obj["python_spec"]:
139+
obj["python_spec"]["version"] = target_ver
140+
for v in obj.values():
141+
_update_ver(v)
142+
elif isinstance(obj, list):
143+
for item in obj:
144+
_update_ver(item)
145+
146+
if hasattr(interaction.request, "body_segments"):
147+
_update_ver(interaction.request.body_segments)
148+
if hasattr(interaction.request, "body"):
149+
_update_ver(interaction.request.body)
150+
except Exception:
151+
pass
152+
with (
153+
mock_agent_engine_create_base64_encoded_tarball,
154+
mock_agent_engine_create_path_exists,
155+
):
156+
agent_engine = client.agent_engines.create(
132157
config={
133158
"display_name": "test-agent-engine-source-packages",
134159
"source_packages": [
@@ -144,12 +169,12 @@ def test_create_with_source_packages(
144169
},
145170
},
146171
)
147-
assert (
172+
assert (
148173
agent_engine.api_resource.display_name
149174
== "test-agent-engine-source-packages"
150175
)
151-
# Clean up resources.
152-
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
176+
# Clean up resources.
177+
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)
153178

154179

155180
def test_create_with_identity_type(client):

0 commit comments

Comments
 (0)