Skip to content

Commit 191eb5c

Browse files
committed
TEST: Test invalid values for ArrayProxy keep_file_open flag. Add indexed_gzip
to CI build matrix
1 parent 82e7c84 commit 191eb5c

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cache:
1515
env:
1616
global:
1717
- DEPENDS="six numpy scipy matplotlib h5py pillow"
18+
- OPTIONAL_DEPENDS=""
1819
- PYDICOM=1
1920
- INSTALL_TYPE="setup"
2021
- EXTRA_WHEELS="https://5cf40426d9f06eb7461d-6fe47d9331aba7cd62fc36c7196769e4.ssl.cf2.rackcdn.com"
@@ -84,6 +85,13 @@ matrix:
8485
- python: 3.5
8586
env:
8687
- DOC_DOC_TEST=1
88+
# Run tests with indexed_gzip present
89+
- python: 2.7
90+
env:
91+
- OPTIONAL_DEPENDS="indexed_gzip"
92+
- python: 3.5
93+
env:
94+
- OPTIONAL_DEPENDS="indexed_gzip"
8795
before_install:
8896
- source tools/travis_tools.sh
8997
- python -m pip install --upgrade pip
@@ -93,7 +101,7 @@ before_install:
93101
- python --version # just to check
94102
- pip install -U pip wheel # needed at one point
95103
- retry pip install nose flake8 mock # always
96-
- pip install $EXTRA_PIP_FLAGS $DEPENDS
104+
- pip install $EXTRA_PIP_FLAGS $DEPENDS $OPTIONAL_DEPENDS
97105
# pydicom <= 0.9.8 doesn't install on python 3
98106
- if [ "${TRAVIS_PYTHON_VERSION:0:1}" == "2" ]; then
99107
if [ "$PYDICOM" == "1" ]; then

nibabel/tests/test_arrayproxy.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def __init__(self, *args, **kwargs):
345345
CountingImageOpener.numOpeners += 1
346346

347347

348-
def test_keep_file_open_true_false():
348+
def test_keep_file_open_true_false_invalid():
349349
# Test the behaviour of the keep_file_open __init__ flag, when it is set to
350350
# True or False.
351351
CountingImageOpener.numOpeners = 0
@@ -360,7 +360,8 @@ def test_keep_file_open_true_false():
360360
# handle, and that ArrayProxy(keep_file_open=False) creates a file
361361
# handle on every data access.
362362
with mock.patch('nibabel.arrayproxy.ImageOpener', CountingImageOpener):
363-
proxy_no_kfp = ArrayProxy(fname, ((10, 10, 10), dtype))
363+
proxy_no_kfp = ArrayProxy(fname, ((10, 10, 10), dtype),
364+
keep_file_open=False)
364365
assert not proxy_no_kfp._keep_file_open
365366
for i in range(voxels.shape[0]):
366367
x , y, z = [int(c) for c in voxels[i, :]]
@@ -388,13 +389,24 @@ def test_keep_file_open_true_false():
388389
assert not fobj.closed
389390
proxy_kfp = ArrayProxy(fobj, ((10, 10, 10), dtype),
390391
keep_file_open=True)
391-
assert not proxy_kfp._keep_file_open
392+
assert proxy_kfp._keep_file_open
392393
for i in range(voxels.shape[0]):
393394
assert proxy_kfp[x, y, z] == x * 100 + y * 10 + z
394395
assert not fobj.closed
395396
del proxy_kfp
396397
proxy_kfp = None
397398
assert not fobj.closed
399+
# Test invalid values of keep_file_open
400+
with assert_raises(ValueError):
401+
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=0)
402+
with assert_raises(ValueError):
403+
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=1)
404+
with assert_raises(ValueError):
405+
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=55)
406+
with assert_raises(ValueError):
407+
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='autob')
408+
with assert_raises(ValueError):
409+
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open='cauto')
398410

399411

400412
def test_keep_file_open_default():

0 commit comments

Comments
 (0)