Skip to content

Commit

Permalink
envoy.base.utils(0.5.7): Switch protobuf `MessageFactory.GetPrototy…
Browse files Browse the repository at this point in the history
…pe` -> `GetMessageClass` (#2384)

Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax authored Oct 31, 2024
1 parent bfc507e commit d617aab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
2 changes: 1 addition & 1 deletion envoy.base.utils/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.7-dev
0.5.7
10 changes: 3 additions & 7 deletions envoy.base.utils/envoy/base/utils/abstract/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import json_format
from google.protobuf import (
message as _message,
message_factory as _message_factory)
message_factory,
message as _message)

import abstracts

Expand Down Expand Up @@ -64,10 +64,6 @@ def __init__(self, descriptor_path: str | pathlib.Path) -> None:
def descriptor_pool(self) -> _descriptor_pool.DescriptorPool:
return self.protobuf_set.descriptor_pool

@cached_property
def message_factory(self) -> _message_factory.MessageFactory:
return _message_factory.MessageFactory(pool=self.descriptor_pool)

@cached_property
def protobuf_set(self) -> interface.IProtobufSet:
return self.protobuf_set_class(self.descriptor_path)
Expand All @@ -91,7 +87,7 @@ def message(self, type_name: str) -> _message.Message:
def message_prototype(
self,
type_name: str) -> Callable[[], _message.Message]:
return self.message_factory.GetPrototype(self.find_message(type_name))
return message_factory.GetMessageClass(self.find_message(type_name))

def validate_fragment(
self,
Expand Down
26 changes: 3 additions & 23 deletions envoy.base.utils/tests/test_abstract_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,6 @@ def test_protobufvalidator_descriptor_pool(patches):
assert "descriptor_pool" not in proto_validator.__dict__


def test_protobufvalidator_message_factory(patches):
proto_validator = DummyProtobufValidator("DESCRIPTOR_PATH")
patched = patches(
"_message_factory",
("AProtobufValidator.descriptor_pool",
dict(new_callable=PropertyMock)),
prefix="envoy.base.utils.abstract.protobuf")

with patched as (m_factory, m_pool):
assert (
proto_validator.message_factory
== m_factory.MessageFactory.return_value)

assert (
m_factory.MessageFactory.call_args
== [(), dict(pool=m_pool.return_value)])
assert "message_factory" in proto_validator.__dict__


def test_protobufvalidator_protobuf_set(patches):
proto_validator = DummyProtobufValidator("DESCRIPTOR_PATH")
patched = patches(
Expand Down Expand Up @@ -226,19 +207,18 @@ def test_protobufvalidator_message(patches):
def test_protobufvalidator_message_prototype(patches):
proto_validator = DummyProtobufValidator("DESCRIPTOR_PATH")
patched = patches(
("AProtobufValidator.message_factory",
dict(new_callable=PropertyMock)),
"message_factory",
"AProtobufValidator.find_message",
prefix="envoy.base.utils.abstract.protobuf")
type_name = MagicMock()

with patched as (m_factory, m_find):
assert (
proto_validator.message_prototype(type_name)
== m_factory.return_value.GetPrototype.return_value)
== m_factory.GetMessageClass.return_value)

assert (
m_factory.return_value.GetPrototype.call_args
m_factory.GetMessageClass.call_args
== [(m_find.return_value, ), {}])
assert (
m_find.call_args
Expand Down

0 comments on commit d617aab

Please sign in to comment.