|
2 | 2 |
|
3 | 3 | import os |
4 | 4 |
|
| 5 | +import numpy as np |
5 | 6 | import pytest |
6 | 7 | import bids |
7 | 8 | from bids.exceptions import ConfigError |
8 | 9 |
|
9 | 10 | from ..models import Entity, Config |
10 | | -from ..utils import BIDSMetadata, parse_file_entities, add_config_paths |
| 11 | +from ..utils import BIDSMetadata, PaddedInt, parse_file_entities, add_config_paths |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def test_bidsmetadata_class(): |
@@ -73,3 +74,20 @@ def test_add_config_paths(): |
73 | 74 | add_config_paths(dummy=bids_json) |
74 | 75 | config = Config.load('dummy') |
75 | 76 | assert 'subject' in config.entities |
| 77 | + |
| 78 | + |
| 79 | +def test_PaddedInt_array_comparisons(): |
| 80 | + # Array comparisons should work, not raise exceptions |
| 81 | + arr = np.array([5, 5, 5]) |
| 82 | + assert np.all(arr == PaddedInt(5)) |
| 83 | + assert np.all(arr == PaddedInt("05")) |
| 84 | + assert np.all(PaddedInt(5) == arr) |
| 85 | + assert np.all(PaddedInt("05") == arr) |
| 86 | + |
| 87 | + # If the value gets put into an array, it should be considered an int |
| 88 | + # We lose the padding, but it's unlikely we would try to recover it |
| 89 | + # from an array. |
| 90 | + assert np.array([PaddedInt(5)]).dtype == np.int64 |
| 91 | + |
| 92 | + # Verify that we do get some False results |
| 93 | + assert np.array_equal(np.array([4, 5, 6]) == PaddedInt(5), [False, True, False]) |
0 commit comments