-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathtest_run_config.py
More file actions
107 lines (83 loc) · 3.4 KB
/
Copy pathtest_run_config.py
File metadata and controls
107 lines (83 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from unittest.mock import ANY
from unittest.mock import patch
from google.adk.agents.run_config import RunConfig
from google.genai import types
import pytest
def test_validate_max_llm_calls_valid():
value = RunConfig.validate_max_llm_calls(100)
assert value == 100
def test_validate_max_llm_calls_negative():
with patch("google.adk.agents.run_config.logger.warning") as mock_warning:
value = RunConfig.validate_max_llm_calls(-1)
mock_warning.assert_called_once_with(ANY)
assert value == -1
def test_validate_max_llm_calls_warns_on_zero():
with patch("google.adk.agents.run_config.logger.warning") as mock_warning:
value = RunConfig.validate_max_llm_calls(0)
mock_warning.assert_called_once_with(ANY)
assert value == 0
def test_validate_max_llm_calls_too_large():
with pytest.raises(
ValueError, match=f"max_llm_calls should be less than {sys.maxsize}."
):
RunConfig.validate_max_llm_calls(sys.maxsize)
def test_audio_transcription_configs_are_not_shared_between_instances():
config1 = RunConfig()
config2 = RunConfig()
# Validate output_audio_transcription
assert config1.output_audio_transcription is not None
assert config2.output_audio_transcription is not None
assert (
config1.output_audio_transcription
is not config2.output_audio_transcription
)
# Validate input_audio_transcription
assert config1.input_audio_transcription is not None
assert config2.input_audio_transcription is not None
assert (
config1.input_audio_transcription is not config2.input_audio_transcription
)
def test_avatar_config_initialization():
custom_avatar = types.CustomizedAvatar(
image_mime_type="image/jpeg", image_data=b"image_bytes"
)
avatar_config = types.AvatarConfig(
audio_bitrate_bps=128000,
video_bitrate_bps=1000000,
customized_avatar=custom_avatar,
)
run_config = RunConfig(avatar_config=avatar_config)
assert run_config.avatar_config == avatar_config
assert run_config.avatar_config.customized_avatar == custom_avatar
assert (
run_config.avatar_config.customized_avatar.image_mime_type == "image/jpeg"
)
assert run_config.avatar_config.customized_avatar.image_data == b"image_bytes"
def test_avatar_config_with_name():
avatar_config = types.AvatarConfig(
audio_bitrate_bps=128000,
video_bitrate_bps=1000000,
avatar_name="test_avatar",
)
run_config = RunConfig(avatar_config=avatar_config)
assert run_config.avatar_config == avatar_config
assert run_config.avatar_config.avatar_name == "test_avatar"
assert run_config.avatar_config.customized_avatar is None
def test_model_input_context_accepts_transient_contents():
context_content = types.UserContent("Relevant context for this turn")
run_config = RunConfig(model_input_context=[context_content])
assert run_config.model_input_context == [context_content]