-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c06d84
commit 3a441c4
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Any, Type | ||
|
||
import numpy as np | ||
|
||
from parcels import Grid, TimeConverter | ||
from parcels.grid import RectilinearGrid | ||
|
||
|
||
def validate_simple_repr(class_: Type, kwargs: dict[str, Any]): | ||
"""Test that the repr of an object contains all the arguments. This only works for simple objects.""" | ||
obj = class_(**kwargs) | ||
obj_repr = repr(obj) | ||
|
||
for param in kwargs.keys(): | ||
assert param in obj_repr | ||
# skip `assert repr(value) in obj_repr` as this is not always true if init does processing on the value | ||
assert class_.__name__ in obj_repr | ||
|
||
|
||
# def test_variable_repr(): | ||
# """Test arguments are in the repr of a Variable object""" | ||
# kwargs = dict(name='test', dtype='float32', initial=0, to_write=True) | ||
# validate_repr(Variable, kwargs) | ||
|
||
|
||
def test_grid_repr(): | ||
"""Test arguments are in the repr of a Grid object""" | ||
kwargs = dict( | ||
lon=np.array([1, 2, 3]), lat=np.array([4, 5, 6]), time=None, time_origin=TimeConverter(), mesh="spherical" | ||
) | ||
validate_simple_repr(Grid, kwargs) | ||
|
||
|
||
def test_rectilineargrid_repr(): | ||
""" | ||
Test arguments are in the repr of a RectilinearGrid object. | ||
Mainly to test inherited repr is correct. | ||
""" | ||
kwargs = dict( | ||
lon=np.array([1, 2, 3]), lat=np.array([4, 5, 6]), time=None, time_origin=TimeConverter(), mesh="spherical" | ||
) | ||
validate_simple_repr(RectilinearGrid, kwargs) |