Skip to content

Commit b04fe7c

Browse files
committed
NF+TEST - fix to substitution with start of testing
1 parent 5ff05b0 commit b04fe7c

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

nisext/sexts.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def version_getter(pkg_name):
107107
'missing opt': 'Missing optional package "%s"',
108108
'opt suffix' : '; you may get run-time errors',
109109
'version too old': 'You have version %s of package "%s"'
110-
' but we need version >= %s', }
110+
' but we need version >= %s', }
111111
msgs.update(messages)
112112
try:
113113
__import__(pkg_name)
@@ -125,12 +125,11 @@ def version_getter(pkg_name):
125125
raise RuntimeError('Cannot find version for %s' % pkg_name)
126126
if checker(have_version) < checker(version):
127127
if optional:
128-
log.warn(msgs['version too old'] + msgs['opt suffix'],
129-
have_version,
130-
pkg_name,
131-
version)
128+
log.warn(msgs['version too old'] % (have_version,
129+
pkg_name,
130+
version)
131+
+ msgs['opt suffix'])
132132
else:
133-
raise RuntimeError(msgs['version too old'],
134-
have_version,
135-
pkg_name,
136-
version)
133+
raise RuntimeError(msgs['version too old'] % (have_version,
134+
pkg_name,
135+
version))

nisext/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Tests for nisext package

nisext/tests/test_sexts.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
""" Tests for nisexts.sexts module
2+
"""
3+
4+
import sys
5+
import imp
6+
7+
from ..sexts import package_check
8+
9+
from nose.tools import assert_true, assert_false, assert_equal, assert_raises
10+
11+
FAKE_NAME = 'nisext_improbable'
12+
assert FAKE_NAME not in sys.modules
13+
FAKE_MODULE = imp.new_module('nisext_fake')
14+
15+
16+
def test_package_check():
17+
# Try to use a required package - raise error
18+
assert_raises(RuntimeError, package_check, FAKE_NAME)
19+
# Optional, log.warn
20+
package_check(FAKE_NAME, optional=True)
21+
# Make a package
22+
sys.modules[FAKE_NAME] = FAKE_MODULE
23+
# Now it passes if we don't check the version
24+
package_check(FAKE_NAME)
25+
# A fake version
26+
FAKE_MODULE.__version__ = '0.2'
27+
package_check(FAKE_NAME, version='0.2')
28+
# fails when version not good enough
29+
assert_raises(RuntimeError, package_check, FAKE_NAME, '0.3')
30+
# Unless optional in which case log.warns
31+
package_check(FAKE_NAME, version='0.3', optional=True)
32+
# Might do custom version check
33+
package_check(FAKE_NAME, version='0.2', version_getter=lambda x: '0.2')

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def main(**extra_args):
7171
'nibabel.nicom.tests',
7272
'nibabel.testing',
7373
'nibabel.tests',
74-
# required in setup.py, hence needs to go into source
75-
# dist
76-
'nisext'],
74+
# install nisext as its own package
75+
'nisext',
76+
'nisext.tests'],
7777
# The package_data spec has no effect for me (on python 2.6) -- even
7878
# changing to data_files doesn't get this stuff included in the source
7979
# distribution -- not sure if it has something to do with the magic

0 commit comments

Comments
 (0)