Skip to content

doctest AFNIHeader.get_data_scaling fails if ran "alone" #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yarikoptic opened this issue Jul 30, 2019 · 5 comments · Fixed by #785
Closed

doctest AFNIHeader.get_data_scaling fails if ran "alone" #784

yarikoptic opened this issue Jul 30, 2019 · 5 comments · Fixed by #785

Comments

@yarikoptic
Copy link
Member

originally reported in #782 but has nothing to do with the endianess, so filing separately

when I ran the full sweep using python -m nose -s -v --with-doctest nibabel 2>&1 | tee tests.log that doctest was reported as passed:

(sid_s390x-dchroot)yoh@zelenka:~/nibabel$ grep AFNIHeader.get_data_scaling  tests.log 
Doctest: nibabel.brikhead.AFNIHeader.get_data_scaling ... ok

but when I run only the doctest - it fails

(sid_s390x-dchroot)yoh@zelenka:~/nibabel$ python -m nose -s -v --with-doctest  nibabel/brikhead.py
Doctest: nibabel.brikhead.AFNIHeader.__init__ ... ok
Doctest: nibabel.brikhead.AFNIHeader.get_affine ... ok
Doctest: nibabel.brikhead.AFNIHeader.get_data_scaling ... FAIL
Doctest: nibabel.brikhead.AFNIHeader.get_volume_labels ... ok
Doctest: nibabel.brikhead.AFNIImage ... ok
Doctest: nibabel.brikhead._unpack_var ... ok
Doctest: nibabel.brikhead.parse_AFNI_header ... ok

======================================================================
FAIL: Doctest: nibabel.brikhead.AFNIHeader.get_data_scaling
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 2224, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for nibabel.brikhead.AFNIHeader.get_data_scaling
  File "/home/yoh/nibabel/nibabel/brikhead.py", line 414, in get_data_scaling

----------------------------------------------------------------------
File "/home/yoh/nibabel/nibabel/brikhead.py", line 422, in nibabel.brikhead.AFNIHeader.get_data_scaling
Failed example:
    header.get_data_scaling()
Expected:
    array([  3.88336300e-08])
Got:
    array([3.883363e-08])


----------------------------------------------------------------------
Ran 7 tests in 0.011s

that is numpy 1.16.2 . Happens to me also on my laptop (regular little endian amd64) with the same numpy

(git)hopa:~nipy-suite/nibabel[master]git
$> python -m nose -s -v --with-doctest  nibabel/brikhead.py
Doctest: nibabel.brikhead.AFNIHeader.__init__ ... ok
Doctest: nibabel.brikhead.AFNIHeader.get_affine ... ok
Doctest: nibabel.brikhead.AFNIHeader.get_data_scaling ... FAIL
Doctest: nibabel.brikhead.AFNIHeader.get_volume_labels ... ok
Doctest: nibabel.brikhead.AFNIImage ... ok
Doctest: nibabel.brikhead._unpack_var ... ok
Doctest: nibabel.brikhead.parse_AFNI_header ... ok

======================================================================
FAIL: Doctest: nibabel.brikhead.AFNIHeader.get_data_scaling
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 2224, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for nibabel.brikhead.AFNIHeader.get_data_scaling
  File "/home/yoh/proj/nipy/nipy-suite/nibabel/nibabel/brikhead.py", line 414, in get_data_scaling

----------------------------------------------------------------------
File "/home/yoh/proj/nipy/nipy-suite/nibabel/nibabel/brikhead.py", line 422, in nibabel.brikhead.AFNIHeader.get_data_scaling
Failed example:
    header.get_data_scaling()
Expected:
    array([  3.88336300e-08])
Got:
    array([3.883363e-08])


----------------------------------------------------------------------
Ran 7 tests in 0.017s

FAILED (failures=1)
@effigies
Copy link
Member

Looks like this isn't being used by nose in that case:

def setup_test():
""" Set numpy print options to "legacy" for new versions of numpy
If imported into a file, nosetest will run this before any doctests.
"""
import numpy
from distutils.version import LooseVersion
if LooseVersion(numpy.__version__) >= LooseVersion('1.14'):
numpy.set_printoptions(legacy="1.13")

@yarikoptic
Copy link
Member Author

eh, I see. Shouldn't there be a teardown_test of a kind which would restore to original settings?

@effigies
Copy link
Member

Probably, although is there any case where this would matter?

@yarikoptic
Copy link
Member Author

here or whenever I would invoke tests somehow in the existing python session? -- it changes formatting an doesn't change it back -- side effect.

@effigies
Copy link
Member

Fair enough. Let me know what you think of #785.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants