Skip to content

Commit

Permalink
tests & locks fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matveyvarg committed Apr 15, 2024
1 parent 8aec238 commit ffc4dea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions deker/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 37 additions & 1 deletion tests/test_cases/test_arrays/test_varray_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit ffc4dea

Please sign in to comment.