Skip to content

Commit 6cc6a48

Browse files
sararobcopybara-github
authored andcommitted
chore: Add tests for private AE sandboxes methods
PiperOrigin-RevId: 885014935
1 parent 50d804f commit 6cc6a48

6 files changed

Lines changed: 247 additions & 0 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_private_create(client):
22+
spec = {
23+
"code_execution_environment": {
24+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
25+
}
26+
}
27+
agent_engine_sandbox_operation = client.agent_engines.sandboxes._create(
28+
name=(
29+
"projects/964831358985/locations/us-central1/reasoningEngines/2886612747586371584"
30+
),
31+
spec=spec,
32+
)
33+
assert isinstance(agent_engine_sandbox_operation, types.AgentEngineSandboxOperation)
34+
35+
36+
pytestmark = pytest_helper.setup(
37+
file=__file__,
38+
globals_for_file=globals(),
39+
test_method="agent_engines.sandboxes._create",
40+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_private_delete(client):
22+
agent_engine_sandbox_delete_operation = client.agent_engines.sandboxes._delete(
23+
name=(
24+
"reasoningEngines/2886612747586371584/sandboxEnvironments/6068475153556176896"
25+
),
26+
)
27+
assert isinstance(
28+
agent_engine_sandbox_delete_operation, types.DeleteAgentEngineSandboxOperation
29+
)
30+
31+
32+
pytestmark = pytest_helper.setup(
33+
file=__file__,
34+
globals_for_file=globals(),
35+
test_method="agent_engines.sandboxes._delete",
36+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
import json
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_private_execute_code(client):
24+
25+
code = """
26+
with open("test.txt", "r") as input:
27+
with open("output.txt", "w") as output_txt:
28+
for line in input:
29+
output_txt.write(line)
30+
"""
31+
# Transform the input data into chunks as expected by _execute_code
32+
input_chunks = [
33+
types.Chunk(
34+
mime_type="application/json",
35+
data=json.dumps({"code": code}).encode("utf-8"),
36+
),
37+
types.Chunk(
38+
mime_type="text/plain",
39+
data=b"Hello, world!",
40+
metadata={"attributes": {"file_name": b"test.txt"}},
41+
),
42+
]
43+
44+
execute_code_response = client.agent_engines.sandboxes._execute_code(
45+
name=(
46+
"reasoningEngines/2886612747586371584/sandboxEnvironments/6068475153556176896"
47+
),
48+
inputs=input_chunks,
49+
)
50+
assert isinstance(
51+
execute_code_response,
52+
types.ExecuteSandboxEnvironmentResponse,
53+
)
54+
assert isinstance(execute_code_response.outputs, list)
55+
assert isinstance(execute_code_response.outputs[0], types.Chunk)
56+
57+
58+
pytestmark = pytest_helper.setup(
59+
file=__file__,
60+
globals_for_file=globals(),
61+
test_method="agent_engines.sandboxes._execute_code",
62+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_private_get(client):
22+
23+
sandbox_name = "projects/964831358985/locations/us-central1/reasoningEngines/2886612747586371584/sandboxEnvironments/3186171392039059456"
24+
25+
agent_engine_sandbox = client.agent_engines.sandboxes._get(name=sandbox_name)
26+
assert isinstance(agent_engine_sandbox, types.SandboxEnvironment)
27+
assert (
28+
agent_engine_sandbox.name == sandbox_name
29+
)
30+
31+
32+
pytestmark = pytest_helper.setup(
33+
file=__file__,
34+
globals_for_file=globals(),
35+
test_method="agent_engines.sandboxes._get",
36+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_private_get_operation(client):
22+
23+
operation_name = "projects/964831358985/locations/us-central1/operations/4799455193970245632"
24+
25+
agent_engine_sandbox = client.agent_engines.sandboxes._get_sandbox_operation(operation_name=operation_name)
26+
assert isinstance(agent_engine_sandbox, types.AgentEngineSandboxOperation)
27+
assert (
28+
agent_engine_sandbox.name == operation_name
29+
)
30+
31+
32+
pytestmark = pytest_helper.setup(
33+
file=__file__,
34+
globals_for_file=globals(),
35+
test_method="agent_engines.sandboxes._get_sandbox_operation",
36+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_private_list(client):
22+
agent_engine_sandbox_list_operation = client.agent_engines.sandboxes._list(
23+
name=(
24+
"reasoningEngines/2886612747586371584"
25+
),
26+
)
27+
assert isinstance(agent_engine_sandbox_list_operation.sandbox_environments[0], types.SandboxEnvironment)
28+
assert isinstance(
29+
agent_engine_sandbox_list_operation, types.ListAgentEngineSandboxesResponse
30+
)
31+
32+
33+
pytestmark = pytest_helper.setup(
34+
file=__file__,
35+
globals_for_file=globals(),
36+
test_method="agent_engines.sandboxes._list",
37+
)

0 commit comments

Comments
 (0)