Fix Message equality comparison (#513)
This commit is contained in:
parent
6faac1d1ca
commit
4cdf1bb9e0
@ -651,7 +651,7 @@ class Message(ABC):
|
||||
|
||||
def __eq__(self, other) -> bool:
|
||||
if type(self) is not type(other):
|
||||
return False
|
||||
return NotImplemented
|
||||
|
||||
for field_name in self._betterproto.meta_by_field_name:
|
||||
self_val = self.__raw_get(field_name)
|
||||
|
@ -18,6 +18,7 @@ from typing import (
|
||||
List,
|
||||
Optional,
|
||||
)
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
|
||||
@ -727,3 +728,15 @@ def test_is_set():
|
||||
assert not Spam().is_set("bar")
|
||||
assert Spam(foo=True).is_set("foo")
|
||||
assert Spam(foo=True, bar=0).is_set("bar")
|
||||
|
||||
|
||||
def test_equality_comparison():
|
||||
from tests.output_betterproto.bool import Test as TestMessage
|
||||
|
||||
msg = TestMessage(value=True)
|
||||
|
||||
assert msg == msg
|
||||
assert msg == ANY
|
||||
assert msg == TestMessage(value=True)
|
||||
assert msg != 1
|
||||
assert msg != TestMessage(value=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user