Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

test: target e2e tests to python 3.11 for max coverage #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions 10 bigframes/functions/_function_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
)

from bigframes import clients
from bigframes import version as bigframes_version
import bigframes.core.compile.ibis_types
import bigframes.exceptions as bfe
import bigframes.series as bf_series
Expand Down Expand Up @@ -458,16 +457,13 @@ def remote_function(
msg = bfe.format_message(
"You have not explicitly set a user-managed `cloud_function_service_account`. "
"Using the default Compute Engine service account. "
"To use Bigframes 2.0, please explicitly set `cloud_function_service_account` "
"In BigFrames 2.0 onwards, you would have to explicitly set `cloud_function_service_account` "
'either to a user-managed service account (preferred) or to `"default"` '
"to use the Compute Engine service account (discouraged). "
"to use the default Compute Engine service account (discouraged). "
"See, https://cloud.google.com/functions/docs/securing/function-identity."
)

if (
bigframes_version.__version__.startswith("1.")
and cloud_function_service_account is None
):
if cloud_function_service_account is None:
warnings.warn(msg, stacklevel=2, category=FutureWarning)

if cloud_function_service_account == "default":
Expand Down
8 changes: 7 additions & 1 deletion 8 noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@

DEFAULT_PYTHON_VERSION = "3.10"

# Cloud Run Functions supports Python versions up to 3.12
# https://cloud.google.com/run/docs/runtimes/python
# Managed Python UDF is supported only in Python 3.11
# Let's set the E2E tests version to 3.11 to cover most code paths.
E2E_TEST_PYTHON_VERSION = "3.11"

UNIT_TEST_PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
UNIT_TEST_STANDARD_DEPENDENCIES = [
"mock",
Expand Down Expand Up @@ -418,7 +424,7 @@ def doctest(session: nox.sessions.Session):
)


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS[-1])
@nox.session(python=E2E_TEST_PYTHON_VERSION)
def e2e(session: nox.sessions.Session):
"""Run the large tests in system test suite."""
run_system(
Expand Down
12 changes: 0 additions & 12 deletions 12 tests/system/large/functions/test_managed_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
bpd.options.experiments.udf = True


@pytest.mark.skipif(
get_python_version() not in bff_session._MANAGED_FUNC_PYTHON_VERSIONS,
reason=f"Supported version: {bff_session._MANAGED_FUNC_PYTHON_VERSIONS}",
)
def test_managed_function_multiply_with_ibis(
session,
scalars_table_id,
Expand Down Expand Up @@ -80,10 +76,6 @@ def multiply(x, y):
cleanup_function_assets(multiply, bigquery_client)


@pytest.mark.skipif(
jialuoo marked this conversation as resolved.
Show resolved Hide resolved
get_python_version() not in bff_session._MANAGED_FUNC_PYTHON_VERSIONS,
reason=f"Supported version: {bff_session._MANAGED_FUNC_PYTHON_VERSIONS}",
)
def test_managed_function_stringify_with_ibis(
session,
scalars_table_id,
Expand Down Expand Up @@ -132,10 +124,6 @@ def stringify(x):
)


@pytest.mark.skipif(
get_python_version() not in bff_session._MANAGED_FUNC_PYTHON_VERSIONS,
reason=f"Supported version: {bff_session._MANAGED_FUNC_PYTHON_VERSIONS}",
)
def test_managed_function_binop(session, scalars_dfs, dataset_id):
try:

Expand Down
86 changes: 58 additions & 28 deletions 86 tests/system/large/functions/test_remote_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import inspect
import math # must keep this at top level to test udf referring global import
import os.path
import re
import shutil
import sys
import tempfile
import textwrap
import typing
import warnings

import google.api_core.exceptions
Expand Down Expand Up @@ -50,12 +51,6 @@
_team_euler = "Team Euler"


pytestmark = pytest.mark.skipif(
sys.version_info >= (3, 13),
reason="Runtime 'python313' is not supported yet. Skip for now.",
)


def make_uniq_udf(udf):
"""Transform a udf to another with same behavior but a unique name.
Use this to test remote functions with reuse=True, in which case parallel
Expand Down Expand Up @@ -1323,14 +1318,38 @@ def square_num(x):
)


def test_remote_function_warns_default_cloud_function_service_account():
project = "bigframes-dev-perf"
rf_session = bigframes.Session(context=bigframes.BigQueryOptions(project=project))

with pytest.warns(FutureWarning, match="You have not explicitly set a"):
rf_session.remote_function(
cloud_function_service_account=None, # Explicitly omit service account.
)
@pytest.mark.parametrize(
("remote_function_args"),
[
pytest.param(
{},
id="no-set",
),
pytest.param(
{"cloud_function_service_account": None},
id="set-none",
),
],
)
def test_remote_function_warns_default_cloud_function_service_account(
session, remote_function_args
):
with pytest.warns(FutureWarning) as record:
session.remote_function(**remote_function_args)

len(
[
warn
for warn in record
if re.search(
(
"You have not explicitly set a user-managed.*Using the default Compute Engine.*service account"
),
typing.cast(FutureWarning, warn.message).args[0],
re.DOTALL,
)
]
) == 1


@pytest.mark.flaky(retries=2, delay=120)
Expand Down Expand Up @@ -2319,36 +2338,40 @@ def generate_stats(row: pandas.Series) -> list[int]:


@pytest.mark.parametrize(
("ingress_settings_args", "effective_ingress_settings", "expected_warning"),
(
"ingress_settings_args",
"effective_ingress_settings",
"expect_default_ingress_setting_warning",
),
[
pytest.param(
{},
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
FutureWarning,
True,
id="no-set",
),
pytest.param(
{"cloud_function_ingress_settings": None},
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
FutureWarning,
True,
id="set-none",
),
pytest.param(
{"cloud_function_ingress_settings": "all"},
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
None,
False,
id="set-all",
),
pytest.param(
{"cloud_function_ingress_settings": "internal-only"},
functions_v2.ServiceConfig.IngressSettings.ALLOW_INTERNAL_ONLY,
None,
False,
id="set-internal-only",
),
pytest.param(
{"cloud_function_ingress_settings": "internal-and-gclb"},
functions_v2.ServiceConfig.IngressSettings.ALLOW_INTERNAL_AND_GCLB,
None,
False,
id="set-internal-and-gclb",
),
],
Expand All @@ -2359,11 +2382,11 @@ def test_remote_function_ingress_settings(
scalars_dfs,
ingress_settings_args,
effective_ingress_settings,
expected_warning,
expect_default_ingress_setting_warning,
):
try:
# Verify the function raises the expected security warning message.
with warnings.catch_warnings(record=True) as w:
with warnings.catch_warnings(record=True) as record:

def square(x: int) -> int:
return x * x
Expand All @@ -2372,11 +2395,18 @@ def square(x: int) -> int:
reuse=False, **ingress_settings_args
)(square)

if expected_warning is not None:
assert issubclass(w[0].category, FutureWarning)
assert "Consider using 'internal-only' for enhanced security." in str(
w[0].message
)
default_ingress_setting_warnings = [
warn
for warn in record
if isinstance(warn.message, FutureWarning)
and "`cloud_function_ingress_settings` are set to 'all' by default"
in warn.message.args[0]
and "will change to 'internal-only' for enhanced security in future"
in warn.message.args[0]
]
assert len(default_ingress_setting_warnings) == (
1 if expect_default_ingress_setting_warning else 0
)

# Assert that the GCF is created with the intended maximum timeout
gcf = session.cloudfunctionsclient.get_function(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.