Skip to content

Commit

Permalink
fix: resolve issue where marshal fails with cross api dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Mar 15, 2023
1 parent 9270fe5 commit e123ad8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ class Foo(proto.Message):
del sys.modules[__name__].__protobuf__


def test_module_package_cross_api():
sys.modules[__name__].__protobuf__ = proto.module(package="spam.eggs.v1")
try:

class Baz(proto.Message):
foo = proto.RepeatedField(proto.INT64, number=1)


marshal = proto.Marshal(name="spam.eggs.v1")

assert Baz.meta.package == "spam.eggs.v1"
assert Baz.pb() in marshal._rules

sys.modules[__name__].__protobuf__ = proto.module(package="ham.pancakes.v1")

class AnotherMessage(proto.Message):
qux = proto.Field(proto.MESSAGE, number=1, message=Baz)

marshal = proto.Marshal(name="ham.pancakes.v1")

assert AnotherMessage.meta.package == "ham.pancakes.v1"
assert AnotherMessage.pb() in marshal._rules
# Confirm that Baz.pb() is no longer present in marshal._rules
assert Baz.pb() not in marshal._rules

# Test using multiple packages together
msg = AnotherMessage(qux=Baz())
assert type(msg) == AnotherMessage
finally:
del sys.modules[__name__].__protobuf__


def test_module_package_explicit_marshal():
sys.modules[__name__].__protobuf__ = proto.module(
package="spam.eggs.v1",
Expand Down

0 comments on commit e123ad8

Please sign in to comment.