diff --git a/google/genai/tests/afc/test_generate_content_stream_afc.py b/google/genai/tests/afc/test_generate_content_stream_afc.py index 5cdb9b33f..b9ec0e282 100644 --- a/google/genai/tests/afc/test_generate_content_stream_afc.py +++ b/google/genai/tests/afc/test_generate_content_stream_afc.py @@ -21,6 +21,14 @@ from ... import types +pytestmark = [ + pytest.mark.skipif( + "config.getoption('--private')", + reason="AFC logic in private SDK is re-written", + ), +] + + TEST_NO_AFC_PART = types.Part( text=( 'Okay, here is the weather in San Francisco' diff --git a/google/genai/tests/afc/test_should_disable_afc.py b/google/genai/tests/afc/test_should_disable_afc.py index 188bf2b57..bfc002972 100644 --- a/google/genai/tests/afc/test_should_disable_afc.py +++ b/google/genai/tests/afc/test_should_disable_afc.py @@ -17,9 +17,17 @@ """Tests for should_disable_afc.""" import pytest +from .. import pytest_helper from ... import types from ..._extra_utils import should_disable_afc +pytestmark = [ + pytest.mark.skipif( + "config.getoption('--private')", + reason="AFC re-written for private SDK", + ), +] + def test_config_is_none(): assert should_disable_afc(None) is False diff --git a/google/genai/tests/chats/test_get_history.py b/google/genai/tests/chats/test_get_history.py index e29862a77..8bdb88c8f 100644 --- a/google/genai/tests/chats/test_get_history.py +++ b/google/genai/tests/chats/test_get_history.py @@ -562,6 +562,10 @@ def test_chat_stream_with_empty_content( assert not chat.get_history(curated=True) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC logic in private is re-written', +) def test_chat_with_afc_history(mock_generate_content_afc_history): models_module = models.Models(mock_api_client) chats_module = chats.Chats(modules=models_module) diff --git a/google/genai/tests/chats/test_send_message.py b/google/genai/tests/chats/test_send_message.py index cee6bfe3c..0ec0f90b3 100644 --- a/google/genai/tests/chats/test_send_message.py +++ b/google/genai/tests/chats/test_send_message.py @@ -40,10 +40,16 @@ raise e -pytestmark = pytest_helper.setup( - file=__file__, - globals_for_file=globals(), -) +pytestmark = [ + pytest_helper.setup( + file=__file__, + globals_for_file=globals(), + ), + pytest.mark.skipif( + "config.getoption('--private')", + reason="AFC re-written for private SDK", + ), +] pytest_plugins = ('pytest_asyncio',) diff --git a/google/genai/tests/chats/test_validate_response.py b/google/genai/tests/chats/test_validate_response.py index 40c63094b..0ae49c406 100644 --- a/google/genai/tests/chats/test_validate_response.py +++ b/google/genai/tests/chats/test_validate_response.py @@ -14,8 +14,10 @@ # +from ... import chats from ... import types -from ...chats import _validate_response + +_validate_response = chats._validate_response def test_validate_response_default_response(): diff --git a/google/genai/tests/models/test_function_call_streaming.py b/google/genai/tests/models/test_function_call_streaming.py index 7ac83bc24..fbc3ec914 100644 --- a/google/genai/tests/models/test_function_call_streaming.py +++ b/google/genai/tests/models/test_function_call_streaming.py @@ -148,6 +148,11 @@ test_method='models.generate_content_stream', ) + +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='in private it was not able to find the replay file', +) def test_streaming_with_python_native_no_afc_config(client): """Tests streaming function calls with native python AFC without disabling AFC.""" if not client.vertexai: @@ -173,6 +178,10 @@ def test_streaming_with_python_native_no_afc_config(client): assert 'not compatible with automatic function calling (AFC)' in str(e.value) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='in private it was not able to find the replay file', +) def test_streaming_with_python_afc_disabled_false(client): """Tests streaming function calls with native python AFC without disabling AFC.""" if not client.vertexai: diff --git a/google/genai/tests/models/test_generate_content.py b/google/genai/tests/models/test_generate_content.py index 8b20d8c66..fcf8aed5b 100644 --- a/google/genai/tests/models/test_generate_content.py +++ b/google/genai/tests/models/test_generate_content.py @@ -2159,6 +2159,10 @@ class Foo(BaseModel): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_function(client): def get_weather(city: str) -> str: """Returns the weather in a city.""" diff --git a/google/genai/tests/models/test_generate_content_mcp.py b/google/genai/tests/models/test_generate_content_mcp.py index 233186e88..7e3f0a219 100644 --- a/google/genai/tests/models/test_generate_content_mcp.py +++ b/google/genai/tests/models/test_generate_content_mcp.py @@ -105,6 +105,10 @@ async def test_mcp_tools_with_custom_headers_async(client): } +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_mcp_tools_subsequent_calls_async(client): class MockMcpClientSession(McpClientSession): diff --git a/google/genai/tests/models/test_generate_content_tools.py b/google/genai/tests/models/test_generate_content_tools.py index 72eda55db..4be655258 100644 --- a/google/genai/tests/models/test_generate_content_tools.py +++ b/google/genai/tests/models/test_generate_content_tools.py @@ -838,6 +838,10 @@ def test_function_calling_without_implementation(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_2_function(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -852,6 +856,10 @@ def test_2_function(client): assert 'sunny' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) @pytest.mark.asyncio async def test_2_function_async(client): response = await client.aio.models.generate_content( @@ -866,7 +874,10 @@ async def test_2_function_async(client): assert 'Boston' in response.text assert 'sunny' in response.text - +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_customized_math_rule(client): def customized_divide_integers(numerator: int, denominator: int) -> int: """Divide two integers with customized math rule.""" @@ -882,6 +893,10 @@ def customized_divide_integers(numerator: int, denominator: int) -> int: assert '501' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -895,6 +910,10 @@ def test_automatic_function_calling(client): assert '500' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_with_async_function(client): response = await client.aio.models.generate_content( @@ -1006,6 +1025,10 @@ async def test_automatic_function_calling_stream_async(client): assert chunk.text is not None or chunk.candidates[0].finish_reason +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_disable_afc(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1020,6 +1043,10 @@ def test_callable_tools_user_disable_afc(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_disable_afc_with_max_remote_calls(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1034,7 +1061,10 @@ def test_callable_tools_user_disable_afc_with_max_remote_calls(client): }, ) - +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_disable_afc_with_max_remote_calls_negative( client, ): @@ -1052,6 +1082,10 @@ def test_callable_tools_user_disable_afc_with_max_remote_calls_negative( ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_disable_afc_with_max_remote_calls_zero(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1066,7 +1100,10 @@ def test_callable_tools_user_disable_afc_with_max_remote_calls_zero(client): }, ) - +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_enable_afc(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1081,6 +1118,10 @@ def test_callable_tools_user_enable_afc(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_enable_afc_with_max_remote_calls(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1096,6 +1137,10 @@ def test_callable_tools_user_enable_afc_with_max_remote_calls(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_enable_afc_with_max_remote_calls_negative( client, ): @@ -1113,6 +1158,10 @@ def test_callable_tools_user_enable_afc_with_max_remote_calls_negative( ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_callable_tools_user_enable_afc_with_max_remote_calls_zero(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1128,6 +1177,10 @@ def test_callable_tools_user_enable_afc_with_max_remote_calls_zero(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_exception(client): client.models.generate_content( model='gemini-2.5-flash', @@ -1138,7 +1191,10 @@ def test_automatic_function_calling_with_exception(client): }, ) - +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_float_without_decimal(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1152,6 +1208,10 @@ def test_automatic_function_calling_float_without_decimal(client): assert '500.0' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_pydantic_model(client): class CityObject(pydantic.BaseModel): city_name: str @@ -1175,7 +1235,10 @@ def get_weather_pydantic_model( assert 'cold' in response.text and 'Boston' in response.text - +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_pydantic_model_in_list_type(client): class CityObject(pydantic.BaseModel): city_name: str @@ -1211,6 +1274,10 @@ def get_weather_from_list_of_cities( # TODO(b/397404656): modify this test to pass in api mode +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_pydantic_model_in_union_type(client): class AnimalObject(pydantic.BaseModel): name: str @@ -1258,6 +1325,10 @@ def get_information( assert 'cat' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_union_operator(client): class AnimalObject(pydantic.BaseModel): name: str @@ -1289,6 +1360,10 @@ def get_information( assert response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_tuple_param(client): def output_latlng( latlng: tuple[float, float], @@ -1312,6 +1387,10 @@ def output_latlng( sys.version_info < (3, 10), reason='| is only supported in Python 3.10 and above.', ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_union_operator_return_type(client): def get_cheese_age(cheese: int) -> int | float: """ @@ -1341,6 +1420,10 @@ def get_cheese_age(cheese: int) -> int | float: assert '3' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_parameterized_generic_union_type( client, ): @@ -1388,6 +1471,10 @@ def test_empty_tools(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_with_1_empty_tool(client): # Bad request for empty tool. with pytest_helper.exception_if_vertex(client, errors.ClientError): @@ -1451,6 +1538,10 @@ async def test_vai_search_stream_async(client): assert 'retrieval' in str(e) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_automatic_function_calling_with_coroutine_function(client): async def divide_integers(a: int, b: int) -> int: return a // b @@ -1466,6 +1557,10 @@ async def divide_integers(a: int, b: int) -> int: ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_with_coroutine_function_async( client, @@ -1485,6 +1580,10 @@ async def divide_integers(a: int, b: int) -> int: assert '500' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_async(client): def divide_integers(a: int, b: int) -> int: @@ -1502,6 +1601,10 @@ def divide_integers(a: int, b: int) -> int: assert '500' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_async_with_exception(client): def mystery_function(a: int, b: int) -> int: @@ -1525,6 +1628,10 @@ def mystery_function(a: int, b: int) -> int: ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_async_float_without_decimal(client): response = await client.aio.models.generate_content( @@ -1539,6 +1646,10 @@ async def test_automatic_function_calling_async_float_without_decimal(client): assert '500.0' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_async_with_pydantic_model(client): class CityObject(pydantic.BaseModel): @@ -1566,6 +1677,10 @@ def get_weather_pydantic_model( assert 'cold' in response.text and 'Boston' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_automatic_function_calling_async_with_async_function(client): async def get_current_weather_async(city: str) -> str: @@ -1611,6 +1726,10 @@ async def get_current_weather_async(city: str) -> str: assert chunk.parts[0].function_call.args['city'] == 'San Francisco' +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_2_function_with_history(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1665,6 +1784,10 @@ def test_2_function_with_history(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC by default is disabled in private models.py', +) @pytest.mark.asyncio async def test_2_function_with_history_async(client): response = await client.aio.models.generate_content( @@ -1730,6 +1853,10 @@ def is_a_rabbit(self, number: int) -> str: return self.NAME + 'says isEven: ' + str(number % 2 == 0) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_class_method_tools(client): # This test is to make sure that instance method tools can be used in # the generate_content request. @@ -1748,6 +1875,10 @@ def test_class_method_tools(client): assert 'FunctionHolder' in response.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_disable_afc_in_any_mode(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1764,6 +1895,10 @@ def test_disable_afc_in_any_mode(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_afc_once_in_any_mode(client): response = client.models.generate_content( model='gemini-2.5-flash', @@ -1799,6 +1934,10 @@ def test_code_execution_tool(client): ) +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_afc_logs_to_logger_instance(client, caplog): caplog.set_level(logging.DEBUG, logger='google_genai.models') client.models.generate_content( @@ -1822,6 +1961,10 @@ def test_afc_logs_to_logger_instance(client, caplog): assert 'Reached max remote calls' in caplog.text +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_suppress_logs_with_sdk_logger(client, caplog): caplog.set_level(logging.DEBUG, logger='google_genai.models') sdk_logger = logging.getLogger('google_genai.models') @@ -1867,6 +2010,10 @@ def test_tools_chat_curation(client, caplog): assert len(history) == 4 +@pytest.mark.skipif( + 'config.getoption("--private")', + reason='AFC removed from private models.py', +) def test_function_declaration_with_callable(client): response = client.models.generate_content( model='gemini-2.5-pro', @@ -1883,6 +2030,7 @@ def test_function_declaration_with_callable(client): ) assert response.function_calls is not None + def test_function_declaration_with_callable_stream_now(client): for chunk in client.models.generate_content_stream( model='gemini-2.5-pro', @@ -1896,6 +2044,7 @@ def test_function_declaration_with_callable_stream_now(client): ): pass + @pytest.mark.asyncio async def test_function_declaration_with_callable_async(client): response = await client.aio.models.generate_content( @@ -1928,6 +2077,7 @@ async def test_function_declaration_with_callable_async_stream(client): ): pass + def test_server_side_mcp_only(client): """Test server side mcp, happy path.""" with pytest_helper.exception_if_vertex(client, ValueError): @@ -1948,6 +2098,7 @@ def test_server_side_mcp_only(client): ) assert response.text + @pytest.mark.asyncio async def test_server_side_mcp_only_async(client): """Test server side mcp, happy path.""" @@ -1972,6 +2123,7 @@ async def test_server_side_mcp_only_async(client): ) assert response.text + def test_server_side_mcp_only_stream(client): """Test server side mcp, happy path.""" with pytest_helper.exception_if_vertex(client, ValueError): diff --git a/google/genai/tests/private/test_send_message.py b/google/genai/tests/private/test_send_message.py new file mode 100644 index 000000000..695d5ac57 --- /dev/null +++ b/google/genai/tests/private/test_send_message.py @@ -0,0 +1,30 @@ +# # Copyright 2025 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. +# # + +# """Replay tests for private chats.send_message().""" + +# import pytest +# from .. import pytest_helper + +# pytestmark = [ +# pytest_helper.setup( +# file=__file__, +# globals_for_file=globals(), +# ), +# pytest.mark.skipif( +# "not config.getoption('--private')", +# reason="This test file is only intended for the private SDK", +# ), +# ]