Skip to content

Commit

Permalink
Adding missing test coverage in tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kartographer committed Jan 31, 2025
1 parent 91a0dc8 commit 460e1e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pyuvdata/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ def _test_array_constant(array, *, tols=None):
from pyuvdata.parameter import UVParameter

if isinstance(array, UVParameter):
array_to_test = array.value
array_to_test = np.asarray(array.value)
if tols is None:
tols = array.tols
else:
array_to_test = array
array_to_test = np.asarray(array)
if tols is None:
tols = (0, 0)
assert isinstance(tols, tuple), "tols must be a length-2 tuple"
Expand Down
22 changes: 22 additions & 0 deletions tests/utils/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Licensed under the 2-clause BSD License
"""Tests for helper utility functions."""

import numpy as np
import pytest

from pyuvdata import utils
from pyuvdata.parameter import UVParameter
from pyuvdata.testing import check_warnings


Expand Down Expand Up @@ -89,3 +91,23 @@ def test_eval_inds(inds, nrecs, exp_output, nwarn):
):
output = utils.tools._eval_inds(inds=inds, nrecs=nrecs, strict=False)
assert all(exp_output == output)


@pytest.mark.parametrize("is_param", [True, False])
@pytest.mark.parametrize(
"inp_arr,tols,exp_outcome",
[
[np.array([0, 0, 0, 0]), (0, 0), True],
[[0, 0, 0, 0], None, True],
[[0, 0, 0, 1], (0, 0), False],
[[0, 0, 0, 1], None, False],
[[0, 0, 0, 1], (1, 0), True],
],
)
def test_array_constant(inp_arr, is_param, tols, exp_outcome):
if is_param:
kwargs = {"value": inp_arr}
if tols is not None:
kwargs["tols"] = tols
inp_arr = UVParameter("test", **kwargs)
assert exp_outcome == utils.tools._test_array_constant(inp_arr, tols=tols)

0 comments on commit 460e1e1

Please sign in to comment.