Skip to content

Commit

Permalink
- Fixed empty attrs_schema error
Browse files Browse the repository at this point in the history
- Generating uid moved to a func
  • Loading branch information
matveyvarg committed Oct 26, 2023
1 parent 4406041 commit 48a98f6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
16 changes: 13 additions & 3 deletions deker/tools/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import uuid

from functools import singledispatch
from typing import Any, Dict, List, Tuple, Union
from typing import Any, Dict, List, Tuple, Union, Literal

import numpy as np

Expand All @@ -26,6 +26,7 @@
from psutil import swap_memory, virtual_memory

from deker.errors import DekerMemoryError, DekerValidationError
from deker.types.private.enums import ArrayType


def calculate_total_cells_in_array(seq: Union[Tuple[int, ...], List[int]]) -> int:
Expand Down Expand Up @@ -87,6 +88,15 @@ def check_memory(shape: tuple, dtype: type, mem_limit_from_settings: int) -> Non
)


def generate_uid(array_type: ArrayType) -> str:
"""Generate uuid5 for given array_type.
:param array_type: Either array or varray
"""
namespace = uuid.NAMESPACE_X500 if array_type == "array" else uuid.NAMESPACE_OID
return str(uuid.uuid5(namespace, array_type + get_utc().isoformat()))


def get_id(array: Any) -> str:
"""Generate unique id by object type and datetime.
Expand All @@ -108,14 +118,14 @@ def array_id(arr: Array) -> str: # noqa[ARG001]
:param arr: Array type
"""
return str(uuid.uuid5(uuid.NAMESPACE_X500, "array" + get_utc().isoformat()))
return generate_uid(ArrayType.array)

@generate_id.register(VArray)
def varray_id(arr: VArray) -> str: # noqa[ARG001]
"""Generate id for VArray.
:param arr: VArray type
"""
return str(uuid.uuid5(uuid.NAMESPACE_OID, "varray" + get_utc().isoformat()))
return generate_uid(ArrayType.varray)

return generate_id(array)
11 changes: 8 additions & 3 deletions deker/types/private/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def get_name(object: "DTypeEnum") -> str:
return f"numpy.{object.name}"


class DimensionType(Enum):
class DimensionType(str, Enum):
"""Enum of dimensions' types."""

generic = "generic"
time = "time"


class LocksExtensions(Enum):
class LocksExtensions(str, Enum):
"""Extensions for lock files."""

array_lock = ".arrlock"
Expand All @@ -77,10 +77,15 @@ class LocksExtensions(Enum):
varray_lock = ".varraylock"


class LocksTypes(Enum):
class LocksTypes(str, Enum):
"""Locks enum."""

array_lock = "array creation lock"
array_read_lock = "array read lock"
collection_lock = "collection creation lock"
varray_lock = "varray write lock"


class ArrayType(str, Enum):
array = "array"
varray = "varray"
2 changes: 1 addition & 1 deletion deker/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def process_attributes(

array_type = "VArray" if isinstance(schema, VArraySchema) else "Array"

attrs_schema = schema.attributes if schema else None
attrs_schema = schema.attributes if schema else []

if primary_attributes is None:
primary_attributes = {}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cases/test_uri/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def test_uri_raises_invalid_uri(uri):
"http://host:8080/data/collections/",
"https://user:pass@host:8080/data/collections/",
"http://host:8080/data/collections/",
"https://user:pass@host:8080,host:8000/data/collections/",
"http://host:8080,host:3000/data/collections/",
"https://user:pass@host:8080/data/collections/",
],
)
Expand All @@ -152,6 +154,8 @@ def test_uri_path_concatenation(string):
"https://user:pass@host:8080/data/collections/",
"http://host:8080/data/collections/",
"https://user:pass@host:8080/data/collections/",
"https://user:pass@host:8080,host:8000/data/collections/",
"http://host:8080,host:3000/data/collections/",
],
)
def test_uri_path_concatenation_with_assignment_wrong_expectations(string):
Expand All @@ -171,6 +175,8 @@ def test_uri_path_concatenation_with_assignment_wrong_expectations(string):
"https://user:pass@host:8080/data/collections/",
"http://host:8080/data/collections/",
"https://user:pass@host:8080/data/collections/",
"https://user:pass@host:8080,host:8000/data/collections/",
"http://host:8080,host:3000/data/collections/",
],
)
def test_uri_path_correct_concatenation_with_assignment(string):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cases/test_validators/test_attributes_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,22 @@ def test_custom_attributes_schema_attrs_no_attrs_provided(
collection.delete()


class TestNoAttributes:
def test_no_attributes(self, client):
"""Test that it's possible to create array with empty primary and custom attributes schema."""
coll_params = ClientParams.ArraySchema.OK.no_vgrid_no_attrs()
try:
collection: Collection = client.create_collection(**coll_params)
except DekerCollectionAlreadyExistsError:
coll = client.get_collection(coll_params["name"])
coll.delete()
collection: Collection = client.create_collection(**coll_params)
try:
array = collection.create()
assert array
finally:
collection.delete()


if __name__ == "__main__":
pytest.main()

0 comments on commit 48a98f6

Please sign in to comment.