Skip to content

Commit

Permalink
test(refactor): Adapt to new schema
Browse files Browse the repository at this point in the history
test(dependency): Remove hypothesis as a dependency from the testing suite
  • Loading branch information
caniko authored and Can H. Tartanoglu committed Apr 12, 2024
1 parent d8fcd2b commit 2dd105d
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 505 deletions.
6 changes: 4 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test:
format:
poetry run black .
poetry run isort .
poetry run ruff check . --fix
poetry run ruff check --fix --exit-zero .
@echo "Formatting complete 🎉"

mypy:
Expand All @@ -26,4 +26,6 @@ pyright_test:
poetry run pyright tests/

typegen:
poetry run python typegen/generate_typing.py
poetry run python typegen/generate_typing.py

check: format pyright test
297 changes: 117 additions & 180 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions pydantic_numpy/helper/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,18 @@ def _deserialize_numpy_array_from_data_dict(data_dict: NumpyArrayTypeData) -> np

# IN_THE_FUTURE: Only works with 3.11 and above
# @validate_call
# def _dimension_type_from_depth(depth: PositiveInt) -> type[tuple[Any, ...]]:
# return tuple[*[Any] * depth] # type: ignore


_dimensions_to_shape_type: Final[dict[PositiveInt, type[tuple[Any, ...]]]] = {
1: tuple[Any],
2: tuple[Any, Any],
3: tuple[Any, Any, Any],
4: tuple[Any, Any, Any, Any],
5: tuple[Any, Any, Any, Any, Any],
6: tuple[Any, Any, Any, Any, Any, Any],
7: tuple[Any, Any, Any, Any, Any, Any, Any],
# def _dimension_type_from_depth(depth: PositiveInt) -> type[tuple[int, ...]]:
# return tuple[*[int] * depth] # type: ignore


_dimensions_to_shape_type: Final[dict[PositiveInt, type[tuple[int, ...]]]] = {
1: tuple[int], # type: ignore[dict-item]
2: tuple[int, int], # type: ignore[dict-item]
3: tuple[int, int, int], # type: ignore[dict-item]
4: tuple[int, int, int, int], # type: ignore[dict-item]
5: tuple[int, int, int, int, int], # type: ignore[dict-item]
6: tuple[int, int, int, int, int, int], # type: ignore[dict-item]
7: tuple[int, int, int, int, int, int, int], # type: ignore[dict-item]
}


Expand Down
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ semver = "^3.0.1"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
parameterized = "^0.9.0"
hypothesis = "^6.82.0"
orjson = "*"
setuptools = "^68.0.0"

[tool.poetry.group.format.dependencies]
black = "^23.7.0"
isort = "^5.12.0"
ruff = "^0.0.285"
ruff = "*"

[tool.poetry.group.typecheck.dependencies]
mypy = "*"
pyright = "^1.1.338"

[tool.pytest.ini_options]
filterwarnings = [
"ignore::hypothesis.errors.NonInteractiveExampleWarning",
"ignore:invalid value encountered in multiply:RuntimeWarning",
]

Expand All @@ -57,10 +54,11 @@ profile = "black"

[tool.ruff]
line-length = 120
ignore-init-module-imports = true
ignore = ["F403", "F405"]
lint.ignore-init-module-imports = true
lint.ignore = ["F403", "F405"]

[tool.pyright]
include = ["pydantic_numpy/**", "tests/**"]
reportUnsupportedDunderAll = false

[build-system]
Expand Down
31 changes: 3 additions & 28 deletions tests/helper/cache.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
from functools import cache
from typing import Optional
from functools import lru_cache

import numpy as np
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import floats
from pydantic import BaseModel

from pydantic_numpy.helper.typing import SupportedDTypes


@cache
def cached_calculation(array_type_hint) -> type[BaseModel]:
@lru_cache
def get_numpy_type_model(array_type_hint) -> type[BaseModel]:
class ModelForTesting(BaseModel):
array_field: array_type_hint

return ModelForTesting


@cache
def cached_hyp_array(numpy_dtype: SupportedDTypes, dimensions: Optional[int] = None, *, _axis_length: int = 1):
if np.issubdtype(numpy_dtype, np.floating):
if numpy_dtype == np.float16:
width = 16
elif numpy_dtype == np.float32:
width = 32
elif numpy_dtype in (np.longdouble, np.float64):
width = 64
else:
raise RuntimeError

element_strategy = floats(allow_infinity=False, allow_nan=False, width=width)
else:
element_strategy = None

return arrays(numpy_dtype, tuple(_axis_length for _ in range(dimensions or 1)), elements=element_strategy)
210 changes: 0 additions & 210 deletions tests/helper/groups.py

This file was deleted.

Loading

0 comments on commit 2dd105d

Please sign in to comment.