Skip to content

Commit

Permalink
cycle import
Browse files Browse the repository at this point in the history
  • Loading branch information
imatiushin committed Oct 17, 2023
1 parent 75c91f7 commit 1384414
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 73 deletions.
5 changes: 2 additions & 3 deletions deker/ABC/base_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
from deker.schemas import ArraySchema, VArraySchema
from deker.subset import Subset, VSubset
from deker.tools.array import check_memory, get_id
from deker.validators import is_valid_uuid, validate_custom_attributes
from deker.tools.schema import create_dimensions
from deker.types.private.classes import ArrayMeta, Serializer
from deker.types.private.typings import FancySlice, Numeric, Slice
from deker.validators import process_attributes
from deker.validators import process_attributes, is_valid_uuid, validate_custom_attributes


if TYPE_CHECKING:
Expand Down Expand Up @@ -386,7 +385,7 @@ def update_custom_attributes(self, attributes: dict) -> None:
self.dimensions,
self.primary_attributes,
self.custom_attributes,
attributes
attributes,
)
self._adapter.update_meta_custom_attributes(self, attributes)
self.custom_attributes = attributes
Expand Down
2 changes: 1 addition & 1 deletion deker/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def create(
self,
primary_attributes: Optional[dict] = None,
custom_attributes: Optional[dict] = None,
id_: Optional[str] = None
id_: Optional[str] = None,
) -> Union[Array, VArray]:
"""Create ``Array`` or ``VArray`` according to collection main schema.
Expand Down
8 changes: 4 additions & 4 deletions deker/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _create( # type: ignore
schema: "BaseArraysSchema",
primary_attributes: Optional[dict] = None,
custom_attributes: Optional[dict] = None,
id_: Optional[str]=None
id_: Optional[str] = None,
) -> Union[Array, VArray]:
"""Create Array or VArray.
Expand Down Expand Up @@ -141,7 +141,7 @@ def create(
self,
primary_attributes: Optional[dict] = None,
custom_attributes: Optional[dict] = None,
id_: Optional[str] = None
id_: Optional[str] = None,
) -> Union[Array, VArray]:
"""Create array or varray.
Expand Down Expand Up @@ -184,7 +184,7 @@ def create(
self,
primary_attributes: Optional[dict] = None,
custom_attributes: Optional[dict] = None,
id_: Optional[str] = None
id_: Optional[str] = None,
) -> VArray:
"""Create varray in collection.
Expand Down Expand Up @@ -232,7 +232,7 @@ def create(
self,
primary_attributes: Optional[dict] = None,
custom_attributes: Optional[dict] = None,
id_: Optional[str] = None
id_: Optional[str] = None,
) -> Array:
"""Create array in collection.
Expand Down
12 changes: 6 additions & 6 deletions deker/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from deker_tools.time import get_utc

from deker import Dimension, TimeDimension
from deker.dimensions import Dimension, TimeDimension
from deker.errors import DekerValidationError


Expand Down Expand Up @@ -138,8 +138,8 @@ def process_attributes(
def validate_custom_attributes(
schema: Union["ArraySchema", "VArraySchema"],
dimensions: Tuple[Union[Dimension, TimeDimension], ...],
primary_attributes: Optional[dict],
custom_attributes: Optional[dict],
primary_attributes: dict,
custom_attributes: dict,
attributes: Optional[dict],
) -> dict:
"""Validate custom attributes over schema.
Expand All @@ -154,9 +154,9 @@ def validate_custom_attributes(
raise DekerValidationError("No attributes passed for update")
for s in schema.dimensions:
if (
isinstance(s, TimeDimensionSchema)
and isinstance(s.start_value, str)
and s.start_value.startswith("$")
isinstance(s, TimeDimensionSchema)
and isinstance(s.start_value, str)
and s.start_value.startswith("$")
):
if s.start_value[1:] in primary_attributes:
continue
Expand Down
120 changes: 61 additions & 59 deletions tests/test_cases/test_managers/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@


class TestDataManagerMethods:
@pytest.mark.parametrize("array_params", [
{},
{"id_": str(uuid.uuid4())}
])
@pytest.mark.parametrize("array_params", [{}, {"id_": str(uuid.uuid4())}])
def test_manager_create_array(self, collection_manager, array_params):
"""Tests if manager can create array.
Expand All @@ -35,12 +32,15 @@ def test_manager_create_array(self, collection_manager, array_params):
if array_params.get("id_"):
assert array.id == array_params["id_"]

@pytest.mark.parametrize("id_", [
(str(uuid.uuid4()))[:-10],
"123",
"{20f5484b-88ae-49b0-8af0-3a389b4917dd}",
"20f5484b88ae49b08af03a389b4917dd"
])
@pytest.mark.parametrize(
"id_",
[
(str(uuid.uuid4()))[:-10],
"123",
"{20f5484b-88ae-49b0-8af0-3a389b4917dd}",
"20f5484b88ae49b08af03a389b4917dd",
],
)
def test_manager_create_array_fail_bad_id(self, collection_manager, id_):
"""Tests if manager returns error on incorrect id param.
Expand Down Expand Up @@ -123,9 +123,9 @@ def test_get_array_by_primary_attribute(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_array_by_primary_attribute_datetime(
self,
client: Client,
property_name: str,
self,
client: Client,
property_name: str,
):
"""Tests possibility of getting an array by datetme primary attributes.
Expand Down Expand Up @@ -166,9 +166,9 @@ def test_get_array_by_primary_attribute_datetime(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_varray_by_primary_attribute_datetime(
self,
client: Client,
property_name: str,
self,
client: Client,
property_name: str,
):
"""Tests possibility of getting an array by datetme primary attributes.
Expand Down Expand Up @@ -212,10 +212,10 @@ def test_get_varray_by_primary_attribute_datetime(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_array_by_primary_attribute_no_such_attribute(
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
property_name: str,
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
property_name: str,
):
"""Tests None is returned if there is no array with such primary attributes.
Expand All @@ -232,10 +232,10 @@ def test_get_array_by_primary_attribute_no_such_attribute(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_array_by_primary_attribute_empty_collection(
self,
array_with_attributes: Array,
collection_manager_with_attributes,
property_name: str,
self,
array_with_attributes: Array,
collection_manager_with_attributes,
property_name: str,
):
"""Tests None is returned if collection is empty.
Expand All @@ -250,9 +250,9 @@ def test_get_array_by_primary_attribute_empty_collection(
assert array is None

def test_get_array_by_primary_attribute_fails_too_many_attrs(
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
):
"""Tests if filtering fails of there is too many attributes
Expand All @@ -272,9 +272,9 @@ def test_get_array_by_primary_attribute_fails_too_many_attrs(
assert "Some arguments don't exist in schema" == str(error.value)

def test_get_array_by_primary_attribute_absence(
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
self,
inserted_array_with_attributes: Array,
collection_manager_with_attributes,
):
with pytest.raises(NotImplementedError):
collection_manager_with_attributes.filter({"extra": 12}).first()
Expand All @@ -284,10 +284,7 @@ def test_get_array_by_primary_attribute_absence(


class TestDataManagerMethodsVArray:
@pytest.mark.parametrize("varray_params", [
{},
{"id_": str(uuid.uuid4())}
])
@pytest.mark.parametrize("varray_params", [{}, {"id_": str(uuid.uuid4())}])
def test_manager_create_varray(self, va_collection_manager, varray_params):
"""Tests if manager can create VArray.
Expand All @@ -298,12 +295,15 @@ def test_manager_create_varray(self, va_collection_manager, varray_params):
if varray_params.get("id_"):
assert varray.id == varray_params["id_"]

@pytest.mark.parametrize("id_", [
str(uuid.uuid4())[:-1],
"123",
"{20f5484b-88ae-49b0-8af0-3a389b4917dd}",
"20f5484b88ae49b08af03a389b4917dd"
])
@pytest.mark.parametrize(
"id_",
[
str(uuid.uuid4())[:-1],
"123",
"{20f5484b-88ae-49b0-8af0-3a389b4917dd}",
"20f5484b88ae49b08af03a389b4917dd",
],
)
def test_manager_create_varray_fail_bad_id(self, va_collection_manager, id_):
"""Tests if manager returns error on incorrect id param.
Expand All @@ -313,7 +313,9 @@ def test_manager_create_varray_fail_bad_id(self, va_collection_manager, id_):
with pytest.raises(DekerValidationError):
va_collection_manager.create(id_=id_)

def test_manager_create_varray_fail_exists(self, inserted_varray: VArray, va_collection_manager):
def test_manager_create_varray_fail_exists(
self, inserted_varray: VArray, va_collection_manager
):
"""Tests if manager returns error on trying to create varray with uuid of existing varray.
:param inserted_varray: fixture
Expand Down Expand Up @@ -358,10 +360,10 @@ def test_get_varray_by_id_empty_collection(self, varray: VArray, va_collection_m

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_varray_by_primary_attribute(
self,
inserted_varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
self,
inserted_varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
):
"""Tests possibility of getting an array by primary attributes.
Expand All @@ -382,10 +384,10 @@ def test_get_varray_by_primary_attribute(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_varray_by_primary_attribute_no_such_attribute(
self,
inserted_varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
self,
inserted_varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
):
"""Tests None is returned if there is no array with such primary attributes.
Expand All @@ -402,10 +404,10 @@ def test_get_varray_by_primary_attribute_no_such_attribute(

@pytest.mark.parametrize("property_name", ["first", "last"])
def test_get_varray_by_primary_attribute_empty_collection(
self,
varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
self,
varray_with_attributes: VArray,
va_collection_manager_with_attributes,
property_name: str,
):
"""Tests None is returned if collection is empty.
Expand All @@ -422,9 +424,9 @@ def test_get_varray_by_primary_attribute_empty_collection(
assert array is None

def test_get_array_by_primary_attribute_fails_too_many_attrs(
self,
inserted_array_with_attributes: Array,
va_collection_manager_with_attributes,
self,
inserted_array_with_attributes: Array,
va_collection_manager_with_attributes,
):
"""Tests if filtering fails if there is too many attributes
Expand All @@ -444,9 +446,9 @@ def test_get_array_by_primary_attribute_fails_too_many_attrs(
assert "Some arguments don't exist in schema" == str(error.value)

def test_get_varray_by_primary_attribute_absence(
self,
inserted_varray_with_attributes: Array,
va_collection_manager_with_attributes,
self,
inserted_varray_with_attributes: Array,
va_collection_manager_with_attributes,
):
with pytest.raises(NotImplementedError) as error:
va_collection_manager_with_attributes.filter({"extra": 12}).first()
Expand Down

0 comments on commit 1384414

Please sign in to comment.