Skip to content

Commit

Permalink
NF+TEST - fix to substitution with start of testing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Jan 19, 2011
1 parent 5ff05b0 commit b04fe7c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
17 changes: 8 additions & 9 deletions nisext/sexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def version_getter(pkg_name):
'missing opt': 'Missing optional package "%s"',
'opt suffix' : '; you may get run-time errors',
'version too old': 'You have version %s of package "%s"'
' but we need version >= %s', }
' but we need version >= %s', }
msgs.update(messages)
try:
__import__(pkg_name)
Expand All @@ -125,12 +125,11 @@ def version_getter(pkg_name):
raise RuntimeError('Cannot find version for %s' % pkg_name)
if checker(have_version) < checker(version):
if optional:
log.warn(msgs['version too old'] + msgs['opt suffix'],
have_version,
pkg_name,
version)
log.warn(msgs['version too old'] % (have_version,
pkg_name,
version)
+ msgs['opt suffix'])
else:
raise RuntimeError(msgs['version too old'],
have_version,
pkg_name,
version)
raise RuntimeError(msgs['version too old'] % (have_version,
pkg_name,
version))
1 change: 1 addition & 0 deletions nisext/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tests for nisext package
33 changes: 33 additions & 0 deletions nisext/tests/test_sexts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
""" Tests for nisexts.sexts module
"""

import sys
import imp

from ..sexts import package_check

from nose.tools import assert_true, assert_false, assert_equal, assert_raises

FAKE_NAME = 'nisext_improbable'
assert FAKE_NAME not in sys.modules
FAKE_MODULE = imp.new_module('nisext_fake')


def test_package_check():
# Try to use a required package - raise error
assert_raises(RuntimeError, package_check, FAKE_NAME)
# Optional, log.warn
package_check(FAKE_NAME, optional=True)
# Make a package
sys.modules[FAKE_NAME] = FAKE_MODULE
# Now it passes if we don't check the version
package_check(FAKE_NAME)
# A fake version
FAKE_MODULE.__version__ = '0.2'
package_check(FAKE_NAME, version='0.2')
# fails when version not good enough
assert_raises(RuntimeError, package_check, FAKE_NAME, '0.3')
# Unless optional in which case log.warns
package_check(FAKE_NAME, version='0.3', optional=True)
# Might do custom version check
package_check(FAKE_NAME, version='0.2', version_getter=lambda x: '0.2')
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def main(**extra_args):
'nibabel.nicom.tests',
'nibabel.testing',
'nibabel.tests',
# required in setup.py, hence needs to go into source
# dist
'nisext'],
# install nisext as its own package
'nisext',
'nisext.tests'],
# The package_data spec has no effect for me (on python 2.6) -- even
# changing to data_files doesn't get this stuff included in the source
# distribution -- not sure if it has something to do with the magic
Expand Down

0 comments on commit b04fe7c

Please sign in to comment.