Skip to content

Commit 1ce0bf8

Browse files
committed
test: Check expected interactions of PaddedInts and numpy arrays
1 parent 85eacf2 commit 1ce0bf8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/bids/layout/tests/test_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import os
44

5+
import numpy as np
56
import pytest
67
import bids
78
from bids.exceptions import ConfigError
89

910
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
1112

1213

1314
def test_bidsmetadata_class():
@@ -73,3 +74,20 @@ def test_add_config_paths():
7374
add_config_paths(dummy=bids_json)
7475
config = Config.load('dummy')
7576
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

Comments
 (0)