diff --git a/deker/locks.py b/deker/locks.py index ef00b70..da34768 100644 --- a/deker/locks.py +++ b/deker/locks.py @@ -132,6 +132,8 @@ def wait_for_unlock(check_func: Callable, check_func_args: tuple, timeout, inter class ReadArrayLock(LockWithArrayMixin[ArrayFromArgs], BaseLock): """Read lock for Array.""" + ALLOWED_TYPES = ["LocalArrayAdapter"] + def get_path(self) -> Path: """Get path to read-lock file. @@ -197,6 +199,8 @@ def release(self, e: Optional[Exception] = None) -> None: # noqa[ARG002] class WriteArrayLock(LockWithArrayMixin["Array"], BaseLock): """Write lock for arrays.""" + ALLOWED_TYPES = ["LocalArrayAdapter"] + def get_path(self) -> Path: """Get path to the file for locking.""" path = self.dir_path / (self.array_id + self.instance.file_ext) diff --git a/tests/test_cases/test_arrays/test_varray_methods.py b/tests/test_cases/test_arrays/test_varray_methods.py index 69871c4..7fc6807 100644 --- a/tests/test_cases/test_arrays/test_varray_methods.py +++ b/tests/test_cases/test_arrays/test_varray_methods.py @@ -3,16 +3,18 @@ from datetime import datetime, timedelta, timezone from pathlib import Path +from random import shuffle from typing import Any import numpy as np import pytest -from deker_local_adapters import HDF5StorageAdapter +from deker_local_adapters import HDF5StorageAdapter, LocalArrayAdapter, LocalVArrayAdapter from deker_local_adapters.factory import AdaptersFactory from deker_tools.path import is_empty from numpy import ndarray +from deker.types import ArrayMeta from tests.parameters.array_params import attributes_validation_params from tests.parameters.index_exp_params import invalid_index_params, valid_index_exp_params from tests.parameters.uri import embedded_uri @@ -783,6 +785,40 @@ def test_step_validaor(self, varray: VArray, index_exp): with pytest.raises(IndexError): varray[index_exp] + def test_create_from_meta_ordered( + self, + varray_collection_with_attributes: Collection, + local_array_adapter: LocalArrayAdapter, + local_varray_adapter: LocalVArrayAdapter, + varray_with_attributes: VArray, + ): + meta: ArrayMeta = varray_with_attributes.as_dict + + primary_attribute_keys = list(meta["primary_attributes"].keys()) + shuffle(primary_attribute_keys) + + custom_attribute_keys = list(meta["custom_attributes"].keys()) + shuffle(custom_attribute_keys) + + primary_attributes, custom_attributes = {}, {} + for key in primary_attribute_keys: + primary_attributes[key] = meta["primary_attributes"][key] + + for key in custom_attribute_keys: + custom_attributes[key] = meta["custom_attributes"][key] + + meta["primary_attributes"] = primary_attributes + meta["custom_attributes"] = custom_attributes + + array = VArray._create_from_meta( + varray_collection_with_attributes, + meta=meta, + array_adapter=local_array_adapter, + varray_adapter=local_varray_adapter, + ) + assert array.primary_attributes == varray_with_attributes.primary_attributes + assert array.custom_attributes == varray_with_attributes.custom_attributes + if __name__ == "__main__": pytest.main()