Skip to content

Commit

Permalink
type hints
Browse files Browse the repository at this point in the history
d-v-b committed Aug 29, 2024
1 parent 60163cc commit ce2ad49
Showing 3 changed files with 28 additions and 96 deletions.
104 changes: 18 additions & 86 deletions tests/latest/test_multiscales.py
Original file line number Diff line number Diff line change
@@ -33,18 +33,8 @@ def multi_meta() -> MultiscaleMetadata:
Dataset(
path=f"path{idx}",
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
VectorTranslation(
translation=[
0,
]
* rank
),
VectorScale(scale=(1,) * rank),
VectorTranslation(translation=(0,) * rank),
),
)
for idx in range(num_datasets)
@@ -54,14 +44,7 @@ def multi_meta() -> MultiscaleMetadata:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
),
coordinateTransformations=(VectorScale(scale=(1,) * rank),),
)
return multi

@@ -83,8 +66,8 @@ def test_multiscale_unique_axis_names() -> None:
Dataset(
path="path",
coordinateTransformations=(
VectorScale(scale=[1, 1, 1]),
VectorTranslation(translation=[0, 0, 0]),
VectorScale(scale=(1, 1, 1)),
VectorTranslation(translation=(0, 0, 0)),
),
)
]
@@ -93,7 +76,7 @@ def test_multiscale_unique_axis_names() -> None:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(VectorScale(scale=[1, 1, 1]),),
coordinateTransformations=(VectorScale(scale=(1, 1, 1)),),
)

# make axis names collide
@@ -105,8 +88,8 @@ def test_multiscale_unique_axis_names() -> None:
Dataset(
path="path",
coordinateTransformations=(
VectorScale(scale=[1, 1, 1]),
VectorTranslation(translation=[0, 0, 0]),
VectorScale(scale=(1, 1, 1)),
VectorTranslation(translation=(0, 0, 0)),
),
)
]
@@ -116,7 +99,7 @@ def test_multiscale_unique_axis_names() -> None:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(VectorScale(scale=[1, 1, 1]),),
coordinateTransformations=(VectorScale(scale=(1, 1, 1)),),
)


@@ -142,18 +125,8 @@ def test_multiscale_space_axes_last(axis_types: list[str | None]) -> None:
Dataset(
path="path",
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
VectorTranslation(
translation=[
0,
]
* rank
),
VectorScale(scale=(1,) * rank),
VectorTranslation(translation=(0,) * rank),
),
)
]
@@ -163,14 +136,7 @@ def test_multiscale_space_axes_last(axis_types: list[str | None]) -> None:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
),
coordinateTransformations=(VectorScale(scale=(1,) * rank),),
)


@@ -182,18 +148,8 @@ def test_multiscale_axis_length(num_axes: int) -> None:
Dataset(
path="path",
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
VectorTranslation(
translation=[
0,
]
* rank
),
VectorScale(scale=(1,) * rank),
VectorTranslation(translation=(0,) * rank),
),
)
]
@@ -202,14 +158,7 @@ def test_multiscale_axis_length(num_axes: int) -> None:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
),
coordinateTransformations=(VectorScale(scale=(1,) * rank),),
)


@@ -369,18 +318,8 @@ def default_multiscale() -> MultiscaleMetadata:
Dataset(
path=f"path{idx}",
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
VectorTranslation(
translation=[
0,
]
* rank
),
VectorScale(scale=(1,) * rank),
VectorTranslation(translation=(0,) * rank),
),
)
for idx in range(num_datasets)
@@ -390,13 +329,6 @@ def default_multiscale() -> MultiscaleMetadata:
name="foo",
axes=axes,
datasets=datasets,
coordinateTransformations=(
VectorScale(
scale=[
1,
]
* rank
),
),
coordinateTransformations=(VectorScale(scale=(1,) * rank),),
)
return multi
8 changes: 4 additions & 4 deletions tests/v04/test_label.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import List, Literal
from typing import Literal
import pytest
from pydantic import ValidationError
from pydantic_ome_ngff.v04 import version as NGFF_VERSION
@@ -8,7 +8,7 @@


@pytest.mark.parametrize("version", (None, "0.4"))
def test_imagelabel(version: Literal["0.4"] | None):
def test_imagelabel(version: Literal["0.4"] | None) -> None:
color = Color(label_value=1, rgba=[0, 0, 0, 0])
model = ImageLabel(colors=[color], version=version)
dumped = model.model_dump()
@@ -19,7 +19,7 @@ def test_imagelabel(version: Literal["0.4"] | None):
assert dumped["version"] == NGFF_VERSION


def test_properties_colors_match():
def test_properties_colors_match() -> None:
color = Color(label_value=0, rgba=(0, 0, 0, 0))
prop = Property(label_value=1)

@@ -46,7 +46,7 @@ def test_imagelabel_version(version: str) -> None:
],
),
)
def test_imagelabel_colors(colors: List[Color] | None):
def test_imagelabel_colors(colors: list[Color] | None) -> None:
if colors is None:
with pytest.warns(UserWarning):
ImageLabel(colors=colors)
12 changes: 6 additions & 6 deletions tests/v04/test_utils.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
@pytest.mark.parametrize(
"ndim, scale", ((3, (1, 2, 3)), (3, None), (2, (1, 2)), (2, None))
)
def test_normalize_scale(ndim: int, scale: tuple[int, int, int] | None):
def test_normalize_scale(ndim: int, scale: tuple[int, int, int] | None) -> None:
normalized = normalize_scale(ndim=ndim, param=scale)
if scale is None:
assert normalized == (1,) * ndim
@@ -31,7 +31,7 @@ def test_normalize_scale(ndim: int, scale: tuple[int, int, int] | None):
@pytest.mark.parametrize(
"ndim, trans", ((3, (1, 2, 3)), (3, None), (2, (1, 2)), (2, None))
)
def test_normalize_translation(ndim: int, trans: tuple[int, int, int] | None):
def test_normalize_translation(ndim: int, trans: tuple[int, int, int] | None) -> None:
normalized = normalize_translation(ndim=ndim, param=trans)
if trans is None:
assert normalized == (0,) * ndim
@@ -48,7 +48,7 @@ def test_transform_coordinate_transformations(
old_trans: Literal["auto"] | None,
in_scale: Literal["auto"] | None,
in_trans: Literal["auto"] | None,
):
) -> None:
old_ctx: tuple[VectorScale] | tuple[VectorScale, VectorTranslation] = ()
old_scale = tuple(range(ndim))
old_ctx += (VectorScale(scale=old_scale),)
@@ -147,7 +147,7 @@ def test_transform_dataset(
)
def test_transform_multiscale_metadata(
ctx: None | tuple[VectorScale] | tuple[VectorScale, VectorTranslation],
):
) -> None:
scale = (2, 2)
trans = (0.5, 0.5)
datasets = (
@@ -172,7 +172,7 @@ def test_transform_multiscale_metadata(
@pytest.mark.parametrize("ctx", (None, "auto"))
def test_transpose_axes_multiscale(
order: tuple[int, ...] | tuple[str, ...], ctx: Literal["auto"] | None
):
) -> None:
axes = {k: Axis(type="space", name=k) for k in ("x", "y", "z")}
axes_tuple = tuple(axes.values())
dataset = Dataset(
@@ -224,7 +224,7 @@ def test_transpose_axes_multiscale(
(0, 2, 1),
),
)
def test_transpose_axes_dataset(order: tuple[int, int, int]):
def test_transpose_axes_dataset(order: tuple[int, int, int]) -> None:
dataset = Dataset(
path="foo",
coordinateTransformations=(

0 comments on commit ce2ad49

Please sign in to comment.