Skip to content

Commit

Permalink
Merge branch 'master' into dev/deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
miraleung authored May 13, 2021
2 parents b644403 + d789c84 commit ad62b27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gapic/schema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ def __str__(self) -> str:
if self.module:
module_name = self.module

# If collisions are registered and conflict with our module,
# use the module alias instead.
if self.module_alias:
module_name = self.module_alias

# This module is from a different proto package
# Most commonly happens for a common proto
# https://pypi.org/project/googleapis-common-protos/
if not self.proto_package.startswith(self.api_naming.proto_package):
module_name = f'{self.module}_pb2'

# If collisions are registered and conflict with our module,
# use the module alias instead.
if self.module_alias:
module_name = self.module_alias

# Return the dot-separated Python identifier.
return '.'.join((module_name,) + self.parent + (self.name,))

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/schema/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def test_address_str_different_proto_package():
assert str(addr) == 'options_pb2.GetPolicyOptions'


def test_address_str_different_proto_package_with_collision():
addr = metadata.Address(
package=('google', 'rpc'),
module='status',
name='Status',
api_naming=naming.NewNaming(proto_package='foo.bar.baz.v1')
).with_context(collisions=frozenset({'status'}))
# the module alias should be ignored for _pb2 types
assert str(addr) == 'status_pb2.Status'


def test_address_proto():
addr = metadata.Address(package=('foo', 'bar'), module='baz', name='Bacon')
assert addr.proto == 'foo.bar.Bacon'
Expand Down

0 comments on commit ad62b27

Please sign in to comment.