SimpleCas basic implementation.
This commit is contained in:
76
tests/test_simple_cas.py
Normal file
76
tests/test_simple_cas.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# bsv - Backup, Synchronization, Versioning
|
||||
# Copyright (C) 2023 Simon Boyé
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from __future__ import annotations
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
|
||||
from tempfile import TemporaryDirectory
|
||||
import pytest
|
||||
|
||||
from bsv.simple_cas.cas import SimpleCas
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_dir():
|
||||
with TemporaryDirectory(prefix="simple_cas_") as tmp_dir:
|
||||
yield Path(tmp_dir)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cas(tmp_dir):
|
||||
cas = SimpleCas(
|
||||
tmp_dir,
|
||||
sha256, # type: ignore
|
||||
)
|
||||
with cas:
|
||||
yield cas
|
||||
|
||||
|
||||
def test_simple_cas(tmp_dir: Path):
|
||||
cas = SimpleCas(
|
||||
tmp_dir,
|
||||
sha256, # type: ignore
|
||||
)
|
||||
with cas:
|
||||
assert len(cas) == 0
|
||||
|
||||
data = b"Hello World!"
|
||||
digest = cas.write(b"blob", data)
|
||||
|
||||
assert len(cas) == 1
|
||||
assert digest in cas
|
||||
|
||||
obj = cas.read(digest)
|
||||
assert obj is not None
|
||||
assert obj.object_type == b"blob"
|
||||
assert obj.data == data
|
||||
|
||||
cas = SimpleCas(
|
||||
tmp_dir,
|
||||
sha256, # type: ignore
|
||||
)
|
||||
with cas:
|
||||
assert len(cas) == 1
|
||||
assert digest in cas
|
||||
|
||||
obj = cas.read(digest)
|
||||
assert obj is not None
|
||||
assert obj.object_type == b"blob"
|
||||
assert obj.data == data
|
||||
|
||||
digest2 = cas.write(b"blob", data)
|
||||
assert digest2 == digest
|
||||
assert len(cas) == 1
|
||||
Reference in New Issue
Block a user