Skip to content

Commit 5f6c5ee

Browse files
committed
wip
1 parent 69b6a0a commit 5f6c5ee

6 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/gapic-generator/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
{% if api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|list %}
88
import re
9-
_UUID4_RE = re.compile(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}")
9+
_UUID4_RE = re.compile(r"{{ uuid4_re }}")
1010
{% endif %}
1111
from unittest import mock
1212
from unittest.mock import AsyncMock

packages/gapic-generator/gapic/generator/generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def __init__(self, opts: Options) -> None:
7575
self._env.tests["str_field_pb"] = utils.is_str_field_pb
7676
self._env.tests["msg_field_pb"] = utils.is_msg_field_pb
7777

78+
# Add global variables.
79+
self._env.globals["uuid4_re"] = utils.UUID4_RE
80+
7881
self._sample_configs = opts.sample_configs
7982

8083
def get_response(self, api_schema: api.API, opts: Options) -> CodeGeneratorResponse:

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
{% if api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|list %}
1111
import re
12-
_UUID4_RE = re.compile(r"{{ test_macros.get_uuid4_re() }}")
12+
_UUID4_RE = re.compile(r"{{ uuid4_re }}")
1313
{% endif %}
1414
from unittest import mock
1515
from unittest.mock import AsyncMock

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ def test_initialize_client_w_{{transport_name}}():
22132213
{% endmacro %}{# empty_call_test #}
22142214

22152215
{% macro get_uuid4_re() -%}
2216-
[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}
2216+
{{ uuid4_re }}
22172217
{%- endmacro %}{# uuid_re #}
22182218

22192219
{% macro routing_parameter_test(service, api, transport, is_async) %}

packages/gapic-generator/gapic/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from gapic.utils.code import nth
2323
from gapic.utils.code import partition
2424
from gapic.utils.code import make_private
25+
from gapic.utils.constants import UUID4_RE
2526
from gapic.utils.doc import doc
2627
from gapic.utils.filename import to_valid_filename
2728
from gapic.utils.filename import to_valid_module_name
@@ -52,5 +53,6 @@
5253
"to_camel_case",
5354
"to_valid_filename",
5455
"to_valid_module_name",
56+
"UUID4_RE",
5557
"wrap",
5658
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2026 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+
# https://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+
# The regex for a UUID4 as specified in AIP-4235.
16+
UUID4_RE = r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}"

0 commit comments

Comments
 (0)