diff --git a/tests/unit/objects/__init__.py b/tests/unit/objects/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/unit/objects/test_cache.py b/tests/unit/objects/test_cache.py deleted file mode 100644 index 93827a416..000000000 --- a/tests/unit/objects/test_cache.py +++ /dev/null @@ -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"] diff --git a/tests/unit/objects/test_hash.py b/tests/unit/objects/test_hash.py deleted file mode 100644 index 682f9c8dd..000000000 --- a/tests/unit/objects/test_hash.py +++ /dev/null @@ -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) diff --git a/tests/unit/objects/test_hash_stream.py b/tests/unit/objects/test_hash_stream.py deleted file mode 100644 index 29e10de89..000000000 --- a/tests/unit/objects/test_hash_stream.py +++ /dev/null @@ -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