From d617aab35e83cc0e5209312a1f5dc4564c671104 Mon Sep 17 00:00:00 2001 From: phlax Date: Thu, 31 Oct 2024 10:25:51 +0000 Subject: [PATCH] `envoy.base.utils`(0.5.7): Switch protobuf `MessageFactory.GetPrototype` -> `GetMessageClass` (#2384) Signed-off-by: Ryan Northey --- envoy.base.utils/VERSION | 2 +- .../envoy/base/utils/abstract/protobuf.py | 10 +++---- .../tests/test_abstract_protobuf.py | 26 +++---------------- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/envoy.base.utils/VERSION b/envoy.base.utils/VERSION index 0e8d5ffd8..d3532a107 100644 --- a/envoy.base.utils/VERSION +++ b/envoy.base.utils/VERSION @@ -1 +1 @@ -0.5.7-dev +0.5.7 diff --git a/envoy.base.utils/envoy/base/utils/abstract/protobuf.py b/envoy.base.utils/envoy/base/utils/abstract/protobuf.py index 999398dd4..820bb3aa4 100644 --- a/envoy.base.utils/envoy/base/utils/abstract/protobuf.py +++ b/envoy.base.utils/envoy/base/utils/abstract/protobuf.py @@ -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 @@ -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) @@ -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, diff --git a/envoy.base.utils/tests/test_abstract_protobuf.py b/envoy.base.utils/tests/test_abstract_protobuf.py index 1b2211a20..a95baa9c5 100644 --- a/envoy.base.utils/tests/test_abstract_protobuf.py +++ b/envoy.base.utils/tests/test_abstract_protobuf.py @@ -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( @@ -226,8 +207,7 @@ 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() @@ -235,10 +215,10 @@ def test_protobufvalidator_message_prototype(patches): 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