Skip to content

Commit b277748

Browse files
partheanidhiii-27
authored andcommitted
chore: replace re.match with re.fullmatch (#17024)
This PR depends on #16944. Please review #16944 first. The PR addresses the feedback in #16944 (comment) , specifically 1.
1 parent 40e51da commit b277748

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def test_{{ method_name }}_empty_call():
692692
{% if method_settings is not none %}
693693
{% for auto_populated_field in method_settings.auto_populated_fields %}
694694
# Ensure that the uuid4 field is set according to AIP 4235
695-
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
695+
assert re.fullmatch(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
696696
# clear UUID field so that the check below succeeds
697697
args[0].{{ auto_populated_field }} = None
698698
{% endfor %}
@@ -730,7 +730,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
730730
{% if method_settings is not none %}
731731
{% for auto_populated_field in method_settings.auto_populated_fields %}
732732
# Ensure that the uuid4 field is set according to AIP 4235
733-
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
733+
assert re.fullmatch(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
734734
# clear UUID field so that the check below succeeds
735735
args[0].{{ auto_populated_field }} = None
736736
{% endfor %}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
151151
{% if method_settings is not none %}
152152
{% for auto_populated_field in method_settings.auto_populated_fields %}
153153
# Ensure that the uuid4 field is set according to AIP 4235
154-
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
154+
assert re.fullmatch(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
155155
# clear UUID field so that the check below succeeds
156156
args[0].{{ auto_populated_field }} = None
157157
{% endfor %}
@@ -1224,7 +1224,7 @@ def test_{{ method_name }}_rest_required_fields(request_type={{ method.input.ide
12241224
# Ensure that the uuid4 field is set according to AIP 4235
12251225
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
12261226
if key == "{{ auto_populated_field|camel_case }}":
1227-
assert re.match(r"{{ get_uuid4_re() }}", value)
1227+
assert re.fullmatch(r"{{ get_uuid4_re() }}", value)
12281228
break
12291229

12301230
# Include {{ auto_populated_field|camel_case }} within expected_params with value mock.ANY
@@ -1576,7 +1576,7 @@ def test_{{ method_name }}_rest_no_http_options():
15761576
{% if method_settings is not none %}
15771577
{% for auto_populated_field in method_settings.auto_populated_fields %}
15781578
# Ensure that the uuid4 field is set according to AIP 4235
1579-
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
1579+
assert re.fullmatch(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
15801580
# clear UUID field so that the check below succeeds
15811581
args[0].{{ auto_populated_field }} = None
15821582
{% endfor %}{# for auto_populated_field in method_settings.auto_populated_fields #}

packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ def test_create_job_non_empty_request_with_auto_populated_field():
18631863
call.assert_called()
18641864
_, args, _ = call.mock_calls[0]
18651865
# Ensure that the uuid4 field is set according to AIP 4235
1866-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
1866+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
18671867
# clear UUID field so that the check below succeeds
18681868
args[0].request_id = None
18691869
assert args[0] == storage_batch_operations.CreateJobRequest(
@@ -2215,7 +2215,7 @@ def test_delete_job_non_empty_request_with_auto_populated_field():
22152215
call.assert_called()
22162216
_, args, _ = call.mock_calls[0]
22172217
# Ensure that the uuid4 field is set according to AIP 4235
2218-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
2218+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
22192219
# clear UUID field so that the check below succeeds
22202220
args[0].request_id = None
22212221
assert args[0] == storage_batch_operations.DeleteJobRequest(
@@ -2533,7 +2533,7 @@ def test_cancel_job_non_empty_request_with_auto_populated_field():
25332533
call.assert_called()
25342534
_, args, _ = call.mock_calls[0]
25352535
# Ensure that the uuid4 field is set according to AIP 4235
2536-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
2536+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
25372537
# clear UUID field so that the check below succeeds
25382538
args[0].request_id = None
25392539
assert args[0] == storage_batch_operations.CancelJobRequest(
@@ -4135,7 +4135,7 @@ def test_create_job_rest_required_fields(request_type=storage_batch_operations.C
41354135
# Ensure that the uuid4 field is set according to AIP 4235
41364136
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
41374137
if key == "requestId":
4138-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
4138+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
41394139
break
41404140

41414141
# Include requestId within expected_params with value mock.ANY
@@ -4313,7 +4313,7 @@ def test_delete_job_rest_required_fields(request_type=storage_batch_operations.D
43134313
# Ensure that the uuid4 field is set according to AIP 4235
43144314
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
43154315
if key == "requestId":
4316-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
4316+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
43174317
break
43184318

43194319
# Include requestId within expected_params with value mock.ANY
@@ -4489,7 +4489,7 @@ def test_cancel_job_rest_required_fields(request_type=storage_batch_operations.C
44894489
# Ensure that the uuid4 field is set according to AIP 4235
44904490
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
44914491
if key == "requestId":
4492-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
4492+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
44934493
break
44944494

44954495
# Include requestId within expected_params with value mock.ANY
@@ -5125,7 +5125,7 @@ def test_create_job_empty_call_grpc():
51255125
call.assert_called()
51265126
_, args, _ = call.mock_calls[0]
51275127
# Ensure that the uuid4 field is set according to AIP 4235
5128-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5128+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
51295129
# clear UUID field so that the check below succeeds
51305130
args[0].request_id = None
51315131
request_msg = storage_batch_operations.CreateJobRequest()
@@ -5152,7 +5152,7 @@ def test_delete_job_empty_call_grpc():
51525152
call.assert_called()
51535153
_, args, _ = call.mock_calls[0]
51545154
# Ensure that the uuid4 field is set according to AIP 4235
5155-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5155+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
51565156
# clear UUID field so that the check below succeeds
51575157
args[0].request_id = None
51585158
request_msg = storage_batch_operations.DeleteJobRequest()
@@ -5179,7 +5179,7 @@ def test_cancel_job_empty_call_grpc():
51795179
call.assert_called()
51805180
_, args, _ = call.mock_calls[0]
51815181
# Ensure that the uuid4 field is set according to AIP 4235
5182-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5182+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
51835183
# clear UUID field so that the check below succeeds
51845184
args[0].request_id = None
51855185
request_msg = storage_batch_operations.CancelJobRequest()
@@ -5330,7 +5330,7 @@ async def test_create_job_empty_call_grpc_asyncio():
53305330
call.assert_called()
53315331
_, args, _ = call.mock_calls[0]
53325332
# Ensure that the uuid4 field is set according to AIP 4235
5333-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5333+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
53345334
# clear UUID field so that the check below succeeds
53355335
args[0].request_id = None
53365336
request_msg = storage_batch_operations.CreateJobRequest()
@@ -5359,7 +5359,7 @@ async def test_delete_job_empty_call_grpc_asyncio():
53595359
call.assert_called()
53605360
_, args, _ = call.mock_calls[0]
53615361
# Ensure that the uuid4 field is set according to AIP 4235
5362-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5362+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
53635363
# clear UUID field so that the check below succeeds
53645364
args[0].request_id = None
53655365
request_msg = storage_batch_operations.DeleteJobRequest()
@@ -5389,7 +5389,7 @@ async def test_cancel_job_empty_call_grpc_asyncio():
53895389
call.assert_called()
53905390
_, args, _ = call.mock_calls[0]
53915391
# Ensure that the uuid4 field is set according to AIP 4235
5392-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5392+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
53935393
# clear UUID field so that the check below succeeds
53945394
args[0].request_id = None
53955395
request_msg = storage_batch_operations.CancelJobRequest()
@@ -6647,7 +6647,7 @@ def test_create_job_empty_call_rest():
66476647
call.assert_called()
66486648
_, args, _ = call.mock_calls[0]
66496649
# Ensure that the uuid4 field is set according to AIP 4235
6650-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6650+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
66516651
# clear UUID field so that the check below succeeds
66526652
args[0].request_id = None
66536653
request_msg = storage_batch_operations.CreateJobRequest()
@@ -6673,7 +6673,7 @@ def test_delete_job_empty_call_rest():
66736673
call.assert_called()
66746674
_, args, _ = call.mock_calls[0]
66756675
# Ensure that the uuid4 field is set according to AIP 4235
6676-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6676+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
66776677
# clear UUID field so that the check below succeeds
66786678
args[0].request_id = None
66796679
request_msg = storage_batch_operations.DeleteJobRequest()
@@ -6699,7 +6699,7 @@ def test_cancel_job_empty_call_rest():
66996699
call.assert_called()
67006700
_, args, _ = call.mock_calls[0]
67016701
# Ensure that the uuid4 field is set according to AIP 4235
6702-
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6702+
assert re.fullmatch(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
67036703
# clear UUID field so that the check below succeeds
67046704
args[0].request_id = None
67056705
request_msg = storage_batch_operations.CancelJobRequest()

0 commit comments

Comments
 (0)