Files
OBLITERATUS/tests/test_export_optional_recording.py

35 lines
1.3 KiB
Python

"""Export continuation remains valid when durable receipts are read-only."""
from unittest.mock import Mock
import pytest
from obliteratus.models import checkpoint_export as export
from tests import test_checkpoint_export_continuation as cases
model_plan = cases.model_plan
pytestmark = pytest.mark.cpu
@pytest.mark.parametrize("restored", [False, True])
def test_continuation_without_record_callback_keeps_exact_checkpoint(
tmp_path, monkeypatch, model_plan, restored,
):
model, plan = model_plan
store = cases.Store()
reference = tmp_path / "reference"
cases.write(model, plan, reference, continuation=store.continuation())
if not restored:
store.receipts.clear()
materialize = Mock(wraps=export._materialize_tensor)
monkeypatch.setattr(export, "_materialize_tensor", materialize)
destination = tmp_path / "result"
cases.write(model, plan, destination, continuation=store.continuation(record_shard=None))
assert cases.snapshot(destination) == cases.snapshot(reference)
if restored:
materialize.assert_not_called()
assert store.restored == [shard.filename for shard in plan.shards]
else:
assert {call.args[1] for call in materialize.call_args_list} == set(plan.tensors)
assert not store.restored