|
1 | 1 | """Tests for pymare.utils.""" |
2 | 2 | import os.path as op |
3 | 3 |
|
| 4 | +import numpy as np |
| 5 | +import pytest |
| 6 | + |
4 | 7 | from pymare import utils |
5 | 8 |
|
6 | 9 |
|
7 | 10 | def test_get_resource_path(): |
8 | 11 | """Test nimare.utils.get_resource_path.""" |
9 | 12 | print(utils.get_resource_path()) |
10 | 13 | assert op.isdir(utils.get_resource_path()) |
| 14 | + |
| 15 | + |
| 16 | +def test_check_inputs_shape(): |
| 17 | + """Test nimare.utils._check_inputs_shape.""" |
| 18 | + n_rows = 5 |
| 19 | + n_columns = 4 |
| 20 | + n_pred = 3 |
| 21 | + y = np.random.randint(1, 100, size=(n_rows, n_columns)) |
| 22 | + v = np.random.randint(1, 100, size=(n_rows + 1, n_columns)) |
| 23 | + n = np.random.randint(1, 100, size=(n_rows, n_columns)) |
| 24 | + X = np.random.randint(1, 100, size=(n_rows, n_pred)) |
| 25 | + X_names = [f"X{x}" for x in range(n_pred)] |
| 26 | + |
| 27 | + utils._check_inputs_shape(y, X, "y", "X", row=True) |
| 28 | + utils._check_inputs_shape(y, n, "y", "n", row=True, column=True) |
| 29 | + utils._check_inputs_shape(X, np.array(X_names)[None, :], "X", "X_names", column=True) |
| 30 | + |
| 31 | + # Raise error if the number of rows and columns of v don't match y |
| 32 | + with pytest.raises(ValueError): |
| 33 | + utils._check_inputs_shape(y, v, "y", "v", row=True, column=True) |
| 34 | + |
| 35 | + # Raise error if neither row or column is True |
| 36 | + with pytest.raises(ValueError): |
| 37 | + utils._check_inputs_shape(y, n, "y", "n") |
| 38 | + |
| 39 | + # Dataset may be initialized with n or v as None |
| 40 | + utils._check_inputs_shape(y, None, "y", "n", row=True, column=True) |
0 commit comments