From e246fabb70653ecaf2ddd0f2dd0c731f71feebb2 Mon Sep 17 00:00:00 2001 From: Rafael M Mudafort Date: Thu, 30 Nov 2023 22:07:17 -0600 Subject: [PATCH] Test grid to and from dict functionality - disabled This requires setting the comparison method in the TurbineGrid and Grid classes. While this can be done with field(eq=cmp_using(eq=np.array_equal)) this adds a lot of additional code to the attribute declarations and makes them difficult to read. Holding off for now but I wanted to leave the test in place for future reference. --- floris/type_dec.py | 19 ++++++++++++++++++- tests/turbine_grid_unit_test.py | 8 +++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/floris/type_dec.py b/floris/type_dec.py index 830f6c6ab..23df94412 100644 --- a/floris/type_dec.py +++ b/floris/type_dec.py @@ -28,7 +28,12 @@ import attrs import numpy as np import numpy.typing as npt -from attrs import Attribute, define +from attrs import ( + Attribute, + # cmp_using, + define, + # field, +) ### Define general data types used throughout @@ -51,6 +56,18 @@ def floris_array_converter(data: Iterable) -> np.ndarray: raise TypeError(e.args[0] + f". Data given: {data}") return a +# def array_field(**kwargs) -> Callable: +# """ +# A wrapper for the :py:func:`attr.field` function that converts the input to a Numpy array, +# adds a comparison function specific to Numpy arrays, and passes through all additional +# keyword arguments. +# """ +# return field( +# converter=floris_array_converter, +# eq=cmp_using(eq=np.array_equal), +# **kwargs +# ) + def _attr_serializer(inst: type, field: Attribute, value: Any): if isinstance(value, np.ndarray): return value.tolist() diff --git a/tests/turbine_grid_unit_test.py b/tests/turbine_grid_unit_test.py index b7ed288bc..1d1230325 100644 --- a/tests/turbine_grid_unit_test.py +++ b/tests/turbine_grid_unit_test.py @@ -14,9 +14,8 @@ import numpy as np -import pytest -from floris.utilities import Vec3 +from floris.simulation import TurbineGrid from tests.conftest import ( N_TURBINES, N_WIND_DIRECTIONS, @@ -25,7 +24,10 @@ ) -# TODO: test the dimension expansion +# def test_from_dict_as_dict(turbine_grid_fixture): +# grid_dict = turbine_grid_fixture.as_dict() +# new_grid = TurbineGrid.from_dict(grid_dict) +# assert new_grid == turbine_grid_fixture def test_set_grid(turbine_grid_fixture):