diff --git a/tests/func/objects/__init__.py b/tests/func/data/__init__.py similarity index 100% rename from tests/func/objects/__init__.py rename to tests/func/data/__init__.py diff --git a/tests/func/objects/db/__init__.py b/tests/func/data/db/__init__.py similarity index 100% rename from tests/func/objects/db/__init__.py rename to tests/func/data/db/__init__.py diff --git a/tests/func/objects/db/test_index.py b/tests/func/data/db/test_index.py similarity index 100% rename from tests/func/objects/db/test_index.py rename to tests/func/data/db/test_index.py diff --git a/tests/func/objects/test_hash.py b/tests/func/objects/test_hash.py deleted file mode 100644 index 10eae3ff4..000000000 --- a/tests/func/objects/test_hash.py +++ /dev/null @@ -1,16 +0,0 @@ -from dvc.fs import LocalFileSystem -from dvc.objects.hash import file_md5 - - -def test_file_md5(tmp_dir): - tmp_dir.gen("foo", "foo content") - - fs = LocalFileSystem() - assert file_md5("foo", fs) == file_md5("foo", fs) - - -def test_file_md5_crlf(tmp_dir): - fs = LocalFileSystem() - tmp_dir.gen("cr", b"a\nb\nc") - tmp_dir.gen("crlf", b"a\r\nb\r\nc") - assert file_md5("cr", fs) == file_md5("crlf", fs) diff --git a/tests/unit/objects/db/__init__.py b/tests/unit/data/__init__.py similarity index 100% rename from tests/unit/objects/db/__init__.py rename to tests/unit/data/__init__.py diff --git a/tests/unit/data/db/__init__.py b/tests/unit/data/db/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/objects/db/test_local.py b/tests/unit/data/db/test_local.py similarity index 100% rename from tests/unit/objects/db/test_local.py rename to tests/unit/data/db/test_local.py diff --git a/tests/unit/objects/test_tree.py b/tests/unit/data/test_tree.py similarity index 100% rename from tests/unit/objects/test_tree.py rename to tests/unit/data/test_tree.py diff --git a/tests/unit/objects/test_cache.py b/tests/unit/objects/test_cache.py index 5bcb0bd7c..2a43711c7 100644 --- a/tests/unit/objects/test_cache.py +++ b/tests/unit/objects/test_cache.py @@ -12,10 +12,10 @@ def set_value(cache: Cache, key: str, value: Any) -> Any: @pytest.mark.parametrize("disk_type", [None, "test"]) -def test_pickle_protocol_error(tmp_dir, disk_type): - directory = tmp_dir / "test" +def test_pickle_protocol_error(tmp_path, disk_type): + directory = tmp_path / "test" cache = Cache( - directory, + str(directory), disk_pickle_protocol=pickle.HIGHEST_PROTOCOL + 1, type=disk_type, ) @@ -33,14 +33,14 @@ def test_pickle_protocol_error(tmp_dir, disk_type): (pickle.HIGHEST_PROTOCOL, pickle.HIGHEST_PROTOCOL - 1), ], ) -def test_pickle_backwards_compat(tmp_dir, proto_a, proto_b): +def test_pickle_backwards_compat(tmp_path, proto_a, proto_b): with Cache( - directory=(tmp_dir / "test"), + directory=str(tmp_path / "test"), disk_pickle_protocol=proto_a, ) as cache: set_value(cache, "key", ("value1", "value2")) with Cache( - directory=(tmp_dir / "test"), + directory=str(tmp_path / "test"), disk_pickle_protocol=proto_b, ) as cache: assert ("value1", "value2") == cache["key"] diff --git a/tests/unit/objects/test_hash.py b/tests/unit/objects/test_hash.py new file mode 100644 index 000000000..cc3bf9c26 --- /dev/null +++ b/tests/unit/objects/test_hash.py @@ -0,0 +1,19 @@ +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 index 217906dfb..0b80a23ea 100644 --- a/tests/unit/objects/test_hash_stream.py +++ b/tests/unit/objects/test_hash_stream.py @@ -5,10 +5,10 @@ from dvc.objects.hash import HashStreamFile, file_md5 from dvc.objects.istextfile import DEFAULT_CHUNK_SIZE, istextfile -def test_hashed_stream_reader(tmp_dir): - tmp_dir.gen({"foo": "foo"}) +def test_hashed_stream_reader(tmp_path): + foo = tmp_path / "foo" + foo.write_bytes(b"foo") - foo = tmp_dir / "foo" with open(foo, "rb") as fobj: stream_reader = HashStreamFile(fobj) @@ -21,15 +21,14 @@ def test_hashed_stream_reader(tmp_dir): assert stream_reader.read(1) == b"o" assert stream_reader.tell() == 3 - hex_digest = file_md5(foo, LocalFileSystem()) + 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_dir): - tmp_dir.gen({"foo": b"foo \x00" * 16}) - - foo = tmp_dir / "foo" +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: @@ -45,7 +44,7 @@ def test_hashed_stream_reader_as_chunks(tmp_dir): assert stream_reader.tell() == actual_size == total_read - hex_digest = file_md5(foo, LocalFileSystem()) + hex_digest = file_md5(str(foo), LocalFileSystem()) assert not stream_reader.is_text assert hex_digest == stream_reader.hash_value @@ -54,20 +53,20 @@ def test_hashed_stream_reader_as_chunks(tmp_dir): "contents", [b"x" * DEFAULT_CHUNK_SIZE + b"\x00", b"clean", b"not clean \x00"], ) -def test_hashed_stream_reader_compatibility(tmp_dir, contents): +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 - tmp_dir.gen("data", contents) - data = tmp_dir / "data" + 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(data, local_fs) + hex_digest = file_md5(str(data), local_fs) - assert stream_reader.is_text is istextfile(data, local_fs) + assert stream_reader.is_text is istextfile(str(data), local_fs) assert stream_reader.hash_value == hex_digest