|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import sys |
| 16 | + |
15 | 17 | import pytest |
16 | 18 |
|
17 | 19 | from google.api import http_pb2 |
@@ -472,3 +474,45 @@ def test_field_mask_different_level_diffs(): |
472 | 474 | "alpha", |
473 | 475 | "red", |
474 | 476 | ] |
| 477 | + |
| 478 | + |
| 479 | +@pytest.mark.skipif( |
| 480 | + sys.version_info.major == 2, |
| 481 | + reason="Field names with trailing underscores can only be created" |
| 482 | + "through proto-plus, which is Python 3 only.", |
| 483 | +) |
| 484 | +def test_field_mask_ignore_trailing_underscore(): |
| 485 | + import proto |
| 486 | + |
| 487 | + class Foo(proto.Message): |
| 488 | + type_ = proto.Field(proto.STRING, number=1) |
| 489 | + input_config = proto.Field(proto.STRING, number=2) |
| 490 | + |
| 491 | + modified = Foo(type_="bar", input_config="baz") |
| 492 | + |
| 493 | + assert sorted(protobuf_helpers.field_mask(None, Foo.pb(modified)).paths) == [ |
| 494 | + "input_config", |
| 495 | + "type", |
| 496 | + ] |
| 497 | + |
| 498 | + |
| 499 | +@pytest.mark.skipif( |
| 500 | + sys.version_info.major == 2, |
| 501 | + reason="Field names with trailing underscores can only be created" |
| 502 | + "through proto-plus, which is Python 3 only.", |
| 503 | +) |
| 504 | +def test_field_mask_ignore_trailing_underscore_with_nesting(): |
| 505 | + import proto |
| 506 | + |
| 507 | + class Bar(proto.Message): |
| 508 | + class Baz(proto.Message): |
| 509 | + input_config = proto.Field(proto.STRING, number=1) |
| 510 | + |
| 511 | + type_ = proto.Field(Baz, number=1) |
| 512 | + |
| 513 | + modified = Bar() |
| 514 | + modified.type_.input_config = "foo" |
| 515 | + |
| 516 | + assert sorted(protobuf_helpers.field_mask(None, Bar.pb(modified)).paths) == [ |
| 517 | + "type.input_config", |
| 518 | + ] |
0 commit comments