mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 15:28:28 +01:00
It turns out that diskcache.Disk saves passed arguments to the database and uses that all the time. So this means that we are not forward compatible as it breaks moving from newer version of DVC to an older one. We don't promise this, but this breaks our benchmarks which are probably not isolated enough. Regarding the use of cache, it is a bit iffy to extend it this way. We only need this type for error messages. We could consider removing this, but since the error message is documented and it's not too hard to extend this :), I decided to preserve the message.
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
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_dir, disk_type):
|
|
directory = tmp_dir / "test"
|
|
cache = Cache(
|
|
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_dir, proto_a, proto_b):
|
|
with Cache(
|
|
directory=(tmp_dir / "test"),
|
|
disk_pickle_protocol=proto_a,
|
|
) as cache:
|
|
set_value(cache, "key", ("value1", "value2"))
|
|
with Cache(
|
|
directory=(tmp_dir / "test"),
|
|
disk_pickle_protocol=proto_b,
|
|
) as cache:
|
|
assert ("value1", "value2") == cache["key"]
|
|
set_value(cache, "key", ("value3", "value4"))
|
|
assert ("value3", "value4") == cache["key"]
|