mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
tests: remove objects related tests
This commit is contained in:
committed by
skshetry
parent
5e561c1dfd
commit
7bc98e3fb3
@@ -1,48 +0,0 @@
|
||||
import pickle
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc_objects.cache import Cache, DiskError
|
||||
|
||||
|
||||
def set_value(cache: Cache, key: str, value: Any) -> Any:
|
||||
cache[key] = value
|
||||
return cache[key]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("disk_type", [None, "test"])
|
||||
def test_pickle_protocol_error(tmp_path, disk_type):
|
||||
directory = tmp_path / "test"
|
||||
cache = Cache(
|
||||
str(directory),
|
||||
disk_pickle_protocol=pickle.HIGHEST_PROTOCOL + 1,
|
||||
type=disk_type,
|
||||
)
|
||||
with pytest.raises(DiskError) as exc, cache as cache:
|
||||
set_value(cache, "key", ("value1", "value2"))
|
||||
assert exc.value.directory == str(directory)
|
||||
assert exc.value.type == "test"
|
||||
assert f"Could not open disk 'test' in {directory}" == str(exc.value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"proto_a, proto_b",
|
||||
[
|
||||
(pickle.HIGHEST_PROTOCOL - 1, pickle.HIGHEST_PROTOCOL),
|
||||
(pickle.HIGHEST_PROTOCOL, pickle.HIGHEST_PROTOCOL - 1),
|
||||
],
|
||||
)
|
||||
def test_pickle_backwards_compat(tmp_path, proto_a, proto_b):
|
||||
with Cache(
|
||||
directory=str(tmp_path / "test"),
|
||||
disk_pickle_protocol=proto_a,
|
||||
) as cache:
|
||||
set_value(cache, "key", ("value1", "value2"))
|
||||
with Cache(
|
||||
directory=str(tmp_path / "test"),
|
||||
disk_pickle_protocol=proto_b,
|
||||
) as cache:
|
||||
assert ("value1", "value2") == cache["key"]
|
||||
set_value(cache, "key", ("value3", "value4"))
|
||||
assert ("value3", "value4") == cache["key"]
|
||||
@@ -1,19 +0,0 @@
|
||||
from dvc_objects.fs import LocalFileSystem
|
||||
from dvc_objects.hash import file_md5
|
||||
|
||||
|
||||
def test_file_md5(tmp_path):
|
||||
foo = tmp_path / "foo"
|
||||
foo.write_text("foo content")
|
||||
|
||||
fs = LocalFileSystem()
|
||||
assert file_md5(str(foo), fs) == file_md5(str(foo), fs)
|
||||
|
||||
|
||||
def test_file_md5_crlf(tmp_path):
|
||||
fs = LocalFileSystem()
|
||||
cr = tmp_path / "cr"
|
||||
crlf = tmp_path / "crlf"
|
||||
cr.write_bytes(b"a\nb\nc")
|
||||
crlf.write_bytes(b"a\r\nb\r\nc")
|
||||
assert file_md5(str(cr), fs) == file_md5(str(crlf), fs)
|
||||
@@ -1,72 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from dvc_objects.fs import LocalFileSystem
|
||||
from dvc_objects.hash import HashStreamFile, file_md5
|
||||
from dvc_objects.istextfile import DEFAULT_CHUNK_SIZE, istextfile
|
||||
|
||||
|
||||
def test_hashed_stream_reader(tmp_path):
|
||||
foo = tmp_path / "foo"
|
||||
foo.write_bytes(b"foo")
|
||||
|
||||
with open(foo, "rb") as fobj:
|
||||
stream_reader = HashStreamFile(fobj)
|
||||
|
||||
assert stream_reader.readable()
|
||||
assert not stream_reader.seekable()
|
||||
|
||||
assert stream_reader.read(2) == b"fo"
|
||||
assert stream_reader.tell() == 2
|
||||
|
||||
assert stream_reader.read(1) == b"o"
|
||||
assert stream_reader.tell() == 3
|
||||
|
||||
hex_digest = file_md5(str(foo), LocalFileSystem())
|
||||
assert stream_reader.is_text
|
||||
assert hex_digest == stream_reader.hash_value
|
||||
|
||||
|
||||
def test_hashed_stream_reader_as_chunks(tmp_path):
|
||||
foo = tmp_path / "foo"
|
||||
foo.write_bytes(b"foo \x00" * 16)
|
||||
|
||||
actual_size = len(foo.read_bytes())
|
||||
with open(foo, "rb") as fobj:
|
||||
stream_reader = HashStreamFile(fobj)
|
||||
|
||||
total_read = 0
|
||||
while True:
|
||||
chunk = stream_reader.read(16)
|
||||
total_read += len(chunk)
|
||||
assert stream_reader.tell() == total_read
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
assert stream_reader.tell() == actual_size == total_read
|
||||
|
||||
hex_digest = file_md5(str(foo), LocalFileSystem())
|
||||
assert not stream_reader.is_text
|
||||
assert hex_digest == stream_reader.hash_value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"contents",
|
||||
[b"x" * DEFAULT_CHUNK_SIZE + b"\x00", b"clean", b"not clean \x00"],
|
||||
)
|
||||
def test_hashed_stream_reader_compatibility(tmp_path, contents):
|
||||
# Always read more than the DEFAULT_CHUNK_SIZE (512 bytes).
|
||||
# This imitates the read actions performed by upload_fobj.
|
||||
chunk_size = DEFAULT_CHUNK_SIZE * 2
|
||||
|
||||
data = tmp_path / "data"
|
||||
data.write_bytes(contents)
|
||||
|
||||
with open(data, "rb") as fobj:
|
||||
stream_reader = HashStreamFile(fobj)
|
||||
stream_reader.read(chunk_size)
|
||||
|
||||
local_fs = LocalFileSystem()
|
||||
hex_digest = file_md5(str(data), local_fs)
|
||||
|
||||
assert stream_reader.is_text is istextfile(str(data), local_fs)
|
||||
assert stream_reader.hash_value == hex_digest
|
||||
Reference in New Issue
Block a user