File tree 3 files changed +43
-7
lines changed 3 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,12 @@ References like "pr/298" refer to github pull request numbers.
34
34
are raising a DataError if the track is truncated when ``strict=True ``
35
35
(the default), rather than a TypeError when trying to create the points
36
36
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.
37
43
38
44
* 2.0.1 (Saturday 27 June 2015)
39
45
Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change 2
2
"""
3
3
4
4
5
- class TripWireError (Exception ):
5
+ class TripWireError (AttributeError ):
6
6
""" 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.
7
11
8
12
9
13
def is_tripwire (obj ):
@@ -32,14 +36,11 @@ class TripWire(object):
32
36
33
37
Examples
34
38
--------
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
40
41
Traceback (most recent call last):
41
42
...
42
- TripWireError: We do not have silly_module_name
43
+ TripWireError: We do not have a_module
43
44
"""
44
45
def __init__ (self , msg ):
45
46
self ._msg = msg
You can’t perform that action at this time.
0 commit comments