Skip to content
2 changes: 1 addition & 1 deletion python_tests/test_issues_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ def secret(self) -> int:
def test_shopping_cart_secret_issue(db0_fixture):
cart_1 = ShoppingCart(as_temp=True)
assert cart_1.secret is not None
cart_2 = ShoppingCart(as_temp=False)
cart_2 = ShoppingCart(as_temp=False)
assert cart_2.secret is None

23 changes: 23 additions & 0 deletions python_tests/test_memo_immutable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from random import random
import pytest
import dbzero as db0
from dataclasses import dataclass
from .conftest import DB0_DIR
import random


@db0.memo(immutable=True, no_default_tags=True)
@dataclass
class MemoImmutableClass1:
data: str
value: int = 0

def test_create_memo_immutable(db0_fixture):
_ = MemoImmutableClass1(data="immutable data", value=42)


def test_tag_and_find_immutable_instance(db0_fixture):
obj_1 = MemoImmutableClass1(data="immutable data", value=42)
db0.tags(obj_1).add("tag1", "tag2")
assert list(db0.find("tag1")) == [obj_1]

51 changes: 51 additions & 0 deletions python_tests/test_memo_no_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,54 @@ def test_find_no_cache_objects(db0_fixture):
final_cache_size = db0.get_cache_stats()["size"]
# make sure cache utilization is low
assert abs(final_cache_size - initial_cache_size) < (300 << 10)


def test_fetching_no_cache_objects(db0_fixture):
px_name = db0.get_current_prefix().name
buf = db0.list()
uuid_list = []
for _ in range(100):
obj = MemoNoCacheClass()
buf.append(obj)
uuid_list.append(db0.uuid(obj))

db0.close()
db0.init(DB0_DIR)
db0.open(px_name, "r")

# now fetch objects by uuid
initial_cache_size = db0.get_cache_stats()["size"]
total_len = 0
for id in uuid_list:
# NOTE: must fetch with type, otherwise no_cache flag may not be honored
obj = db0.fetch(MemoNoCacheClass, id)
# this forces data retrieval
total_len += len(obj.data)

final_cache_size = db0.get_cache_stats()["size"]
# make sure cache utilization is low
assert abs(final_cache_size - initial_cache_size) < (300 << 10)


def test_find_no_cache_objects(db0_fixture):
px_name = db0.get_current_prefix().name
buf = db0.list()
for _ in range(100):
obj = MemoNoCacheClass()
buf.append(obj)

db0.close()
db0.init(DB0_DIR)
db0.open(px_name, "r")

# now retrieve objects using db0.find
initial_cache_size = db0.get_cache_stats()["size"]
total_len = 0
for obj in db0.find(MemoNoCacheClass):
# this forces data retrieval (but not caching)
total_len += len(obj.data)

assert total_len > 0
final_cache_size = db0.get_cache_stats()["size"]
# make sure cache utilization is low
assert abs(final_cache_size - initial_cache_size) < (350 << 10)
3 changes: 2 additions & 1 deletion src/dbzero/bindings/TypeId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ namespace db0::bindings
MEMO_EXPIRED_REF = 117,
// Python type decorated as memo
MEMO_TYPE = 118,
MEMO_IMMUTABLE_OBJECT = 119,
// COUNT determines size of the type operator arrays
COUNT = 119,
COUNT = 120,
// unrecognized type
UNKNOWN = std::numeric_limits<std::uint16_t>::max()
};
Expand Down
Loading