Skip to content

Commit 7dfc9d9

Browse files
committed
Merge pull request #363 from matthew-brett/py35-doctests
MRG: fix for doctest errors on Python 3.5 Fix doctest errors using TripWire on Python 3.5. Add Python 3.5 tests to travis run.
2 parents 1478cc9 + 7db7544 commit 7dfc9d9

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ python:
2626
- 3.2
2727
- 3.3
2828
- 3.4
29+
- 3.5
2930
matrix:
3031
include:
3132
- python: 2.7
@@ -44,11 +45,13 @@ matrix:
4445
env:
4546
- DOC_DOC_TEST=1
4647
before_install:
48+
- source tools/travis_tools.sh
4749
- virtualenv --python=python venv
4850
- source venv/bin/activate
4951
- python --version # just to check
50-
- pip install nose # always
51-
- pip install --no-index -f http://travis-wheels.scikit-image.org $DEPENDS
52+
- pip install -U pip # upgrade to latest pip to find 3.5 wheels
53+
- retry pip install nose # always
54+
- wheelhouse_pip_install $DEPENDS
5255
# pydicom <= 0.9.8 doesn't install on python 3
5356
- if [ "${TRAVIS_PYTHON_VERSION:0:1}" == "2" ]; then
5457
if [ "$PYDICOM" == "1" ]; then

Changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ References like "pr/298" refer to github pull request numbers.
3434
are raising a DataError if the track is truncated when ``strict=True``
3535
(the default), rather than a TypeError when trying to create the points
3636
array.
37+
* tripwire.TripWire object now raises subclass of AttributeError when trying
38+
to get an attribute, rather than a direct subclass of Exception. This
39+
prevents Python 3.5 triggering the tripwire when doing inspection prior to
40+
running doctests.
41+
* Minor API change for tripwire.TripWire object; code that checked for
42+
AttributeError will now also catch TripWireError.
3743

3844
* 2.0.1 (Saturday 27 June 2015)
3945

nibabel/tests/test_tripwire.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" Testing tripwire module
2+
"""
3+
4+
from ..tripwire import TripWire, is_tripwire, TripWireError
5+
6+
from nose import SkipTest
7+
from nose.tools import (assert_true, assert_false, assert_raises,
8+
assert_equal, assert_not_equal)
9+
10+
11+
def test_is_tripwire():
12+
assert_false(is_tripwire(object()))
13+
assert_true(is_tripwire(TripWire('some message')))
14+
15+
16+
def test_tripwire():
17+
# Test tripwire object
18+
silly_module_name = TripWire('We do not have silly_module_name')
19+
assert_raises(TripWireError,
20+
getattr,
21+
silly_module_name,
22+
'do_silly_thing')
23+
# Check AttributeError can be checked too
24+
try:
25+
silly_module_name.__wrapped__
26+
except TripWireError as err:
27+
assert_true(isinstance(err, AttributeError))
28+
else:
29+
raise RuntimeError("No error raised, but expected")

nibabel/tripwire.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
"""
33

44

5-
class TripWireError(Exception):
5+
class TripWireError(AttributeError):
66
""" Exception if trying to use TripWire object """
7+
# Has to be subclass of AttributeError, to work round Python 3.5 inspection
8+
# for doctests. Python 3.5 looks for a ``__wrapped__`` attribute during
9+
# initialization of doctests, and only allows AttributeError as signal this
10+
# is not present.
711

812

913
def is_tripwire(obj):
@@ -32,14 +36,11 @@ class TripWire(object):
3236
3337
Examples
3438
--------
35-
>>> try:
36-
... import silly_module_name
37-
... except ImportError:
38-
... silly_module_name = TripWire('We do not have silly_module_name')
39-
>>> silly_module_name.do_silly_thing('with silly string') #doctest: +IGNORE_EXCEPTION_DETAIL
39+
>>> a_module = TripWire('We do not have a_module')
40+
>>> a_module.do_silly_thing('with silly string') #doctest: +IGNORE_EXCEPTION_DETAIL
4041
Traceback (most recent call last):
4142
...
42-
TripWireError: We do not have silly_module_name
43+
TripWireError: We do not have a_module
4344
"""
4445
def __init__(self, msg):
4546
self._msg = msg

tools/travis_tools.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Tools for working with travis-ci
2+
export WHEELHOST="travis-wheels.scikit-image.org"
3+
export WHEELHOUSE="http://${WHEELHOST}/"
4+
5+
retry () {
6+
# https://gist.github.com/fungusakafungus/1026804
7+
local retry_max=5
8+
local count=$retry_max
9+
while [ $count -gt 0 ]; do
10+
"$@" && break
11+
count=$(($count - 1))
12+
sleep 1
13+
done
14+
15+
[ $count -eq 0 ] && {
16+
echo "Retry failed [$retry_max]: $@" >&2
17+
return 1
18+
}
19+
return 0
20+
}
21+
22+
23+
wheelhouse_pip_install() {
24+
# Install pip requirements via travis wheelhouse
25+
retry pip install --timeout=60 --no-index --trusted-host $WHEELHOST --find-links $WHEELHOUSE $@
26+
}

0 commit comments

Comments
 (0)