Skip to content

Commit e36398a

Browse files
committed
RDBC-471 Changed the concept of _RefEq and wrote test
1 parent f360afb commit e36398a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

pyravendb/store/document_session.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ def __init__(self, ref):
2727
return
2828
self.ref = ref
2929

30+
# As we split the hashable and unhashable items into separate collections, we only compare _RefEq to other _RefEq
3031
def __eq__(self, other):
31-
return (
32-
True
33-
if id(self.ref) == id(other)
34-
else (False if id(self.ref) == id(other) else id(self.ref) == id(other.ref))
35-
)
32+
if isinstance(other, _RefEq):
33+
return id(self.ref) == id(other.ref)
34+
raise TypeError("Expected _RefEq type object")
3635

3736
def __hash__(self):
3837
return id(self.ref)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from pyravendb.tests.test_base import TestBase
2+
from pyravendb.store.document_session import _RefEq
3+
from dataclasses import dataclass
4+
5+
6+
@dataclass()
7+
class TestData:
8+
entry: str
9+
10+
11+
class TestDocumentsByEntity(TestBase):
12+
def setUp(self):
13+
super(TestDocumentsByEntity, self).setUp()
14+
15+
def test_ref_eq(self):
16+
data = TestData(entry="classified")
17+
18+
wrapped_data_1 = _RefEq(data)
19+
wrapped_data_2 = _RefEq(wrapped_data_1)
20+
21+
self.assertTrue(wrapped_data_2 == wrapped_data_1)
22+
with self.assertRaises(TypeError):
23+
wrapped_data_1 == data

0 commit comments

Comments
 (0)