From 2fe0df19261bf5e6e7589a7cd77de03dd1c5c5fc Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 16 Oct 2023 11:34:57 -0400 Subject: [PATCH] fix: Fix coverage gap in tests (#1802) --- .../%name_%version/%sub/test_%service.py.j2 | 10 ++-- .../gapic/%name_%version/%sub/test_macros.j2 | 9 ++-- .../unit/gapic/asset_v1/test_asset_service.py | 18 ++++--- .../unit/gapic/eventarc_v1/test_eventarc.py | 54 ++++++++++++------- .../unit/gapic/redis_v1/test_cloud_redis.py | 18 ++++--- 5 files changed, 72 insertions(+), 37 deletions(-) diff --git a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index ed5bc534cd..fdcf2b3351 100644 --- a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -1032,7 +1032,8 @@ def test_{{ method.name|snake_case }}_rest(request_type): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -1044,8 +1045,8 @@ def test_{{ method.name|snake_case }}_rest(request_type): subfields_not_in_runtime = [] - # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["{{ field.name }}"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["{{ field.name }}"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -1064,7 +1065,8 @@ def test_{{ method.name|snake_case }}_rest(request_type): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 index a996b757b9..6c00659c5a 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 @@ -905,7 +905,8 @@ def test_{{ method_name }}_rest(request_type): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -918,7 +919,8 @@ def test_{{ method_name }}_rest(request_type): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["{{ field.name }}"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["{{ field.name }}"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -937,7 +939,8 @@ def test_{{ method_name }}_rest(request_type): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index a38f051dad..da7e9293ed 100755 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -10011,7 +10011,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -10024,7 +10025,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["saved_query"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["saved_query"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -10043,7 +10045,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -10864,7 +10867,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -10877,7 +10881,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["saved_query"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["saved_query"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -10896,7 +10901,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") diff --git a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index cb5be11f6b..da0e006f4f 100755 --- a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -6243,7 +6243,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -6256,7 +6257,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["trigger"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["trigger"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -6275,7 +6277,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -6559,7 +6562,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -6572,7 +6576,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["trigger"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["trigger"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -6591,7 +6596,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -7641,7 +7647,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -7654,7 +7661,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["channel"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["channel"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -7673,7 +7681,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -7957,7 +7966,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -7970,7 +7980,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["channel"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["channel"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -7989,7 +8000,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -9561,7 +9573,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -9574,7 +9587,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["channel_connection"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["channel_connection"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -9593,7 +9607,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -10329,7 +10344,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -10342,7 +10358,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["google_channel_config"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["google_channel_config"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -10361,7 +10378,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index 918dcf3ffa..7950841287 100755 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -4320,7 +4320,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -4333,7 +4334,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["instance"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["instance"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -4352,7 +4354,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -4625,7 +4628,8 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() - else: + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -4638,7 +4642,8 @@ def get_message_fields(field): subfields_not_in_runtime = [] # For each item in the sample request, create a list of sub fields which are not present at runtime - for field, value in request_init["instance"].items(): + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["instance"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -4657,7 +4662,8 @@ def get_message_fields(field): ) # Remove fields from the sample request which are not present in the runtime version of the dependency - for subfield_to_delete in subfields_not_in_runtime: + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield")