Skip to content

Commit

Permalink
TST: add tests for bug 462
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Nov 1, 2023
1 parent bba2d87 commit 8754a5c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions unyt/tests/test_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
UnytError,
)
from unyt.testing import assert_array_equal_units
from unyt.unit_object import Unit
from unyt.unit_registry import UnitRegistry

NUMPY_VERSION = Version(version("numpy"))

Expand Down Expand Up @@ -265,6 +267,23 @@ def test_wrapping_completeness():
assert function in all_funcs


@pytest.mark.parametrize(
"arrays",
[
[np.array([1]), [2] * Unit()],
[np.array([1]), [2] * Unit(registry=UnitRegistry())],
# [[1], [2] * Unit()],
],
)
def test_unit_validation(arrays):
# see https://github.com/yt-project/unyt/issues/462
# numpy.concatenate isn't essential to this test
# what we're really testing is the unit consistency validation
# underneath, but we do so using public API
res = np.concatenate(arrays)
assert res.units.is_dimensionless


def test_array_repr():
arr = [1, 2, 3] * cm
assert re.fullmatch(r"unyt_array\(\[1, 2, 3\], (units=)?'cm'\)", np.array_repr(arr))
Expand Down

0 comments on commit 8754a5c

Please sign in to comment.