##// END OF EJS Templates
[testing][tests][decorators] Remove nose
Samuel Gaist -
Show More
@@ -1,164 +1,162 b''
1 1 """Tests for the decorators we've created for IPython.
2 2 """
3 3
4 4 # Module imports
5 5 # Std lib
6 6 import inspect
7 7 import sys
8 8
9 # Third party
10 import nose.tools as nt
11
12 9 # Our own
13 10 from IPython.testing import decorators as dec
14 11
15 12 #-----------------------------------------------------------------------------
16 13 # Utilities
17 14
18 15 # Note: copied from OInspect, kept here so the testing stuff doesn't create
19 16 # circular dependencies and is easier to reuse.
20 17 def getargspec(obj):
21 18 """Get the names and default values of a function's arguments.
22 19
23 20 A tuple of four things is returned: (args, varargs, varkw, defaults).
24 21 'args' is a list of the argument names (it may contain nested lists).
25 22 'varargs' and 'varkw' are the names of the * and ** arguments or None.
26 23 'defaults' is an n-tuple of the default values of the last n arguments.
27 24
28 25 Modified version of inspect.getargspec from the Python Standard
29 26 Library."""
30 27
31 28 if inspect.isfunction(obj):
32 29 func_obj = obj
33 30 elif inspect.ismethod(obj):
34 31 func_obj = obj.__func__
35 32 else:
36 33 raise TypeError('arg is not a Python function')
37 34 args, varargs, varkw = inspect.getargs(func_obj.__code__)
38 35 return args, varargs, varkw, func_obj.__defaults__
39 36
40 37 #-----------------------------------------------------------------------------
41 38 # Testing functions
42 39
43 40 @dec.as_unittest
44 41 def trivial():
45 42 """A trivial test"""
46 43 pass
47 44
48 45
49 46 @dec.skip()
50 47 def test_deliberately_broken():
51 48 """A deliberately broken test - we want to skip this one."""
52 49 1/0
53 50
54 51 @dec.skip('Testing the skip decorator')
55 52 def test_deliberately_broken2():
56 53 """Another deliberately broken test - we want to skip this one."""
57 54 1/0
58 55
59 56
60 57 # Verify that we can correctly skip the doctest for a function at will, but
61 58 # that the docstring itself is NOT destroyed by the decorator.
62 59 def doctest_bad(x,y=1,**k):
63 60 """A function whose doctest we need to skip.
64 61
65 62 >>> 1+1
66 63 3
67 64 """
68 65 print('x:',x)
69 66 print('y:',y)
70 67 print('k:',k)
71 68
72 69
73 70 def call_doctest_bad():
74 71 """Check that we can still call the decorated functions.
75 72
76 73 >>> doctest_bad(3,y=4)
77 74 x: 3
78 75 y: 4
79 76 k: {}
80 77 """
81 78 pass
82 79
83 80
84 81 def test_skip_dt_decorator():
85 82 """Doctest-skipping decorator should preserve the docstring.
86 83 """
87 84 # Careful: 'check' must be a *verbatim* copy of the doctest_bad docstring!
88 85 check = """A function whose doctest we need to skip.
89 86
90 87 >>> 1+1
91 88 3
92 89 """
93 90 # Fetch the docstring from doctest_bad after decoration.
94 91 val = doctest_bad.__doc__
95 92
96 nt.assert_equal(check,val,"doctest_bad docstrings don't match")
93 assert check == val, "doctest_bad docstrings don't match"
97 94
98 95
99 96 # Doctest skipping should work for class methods too
100 97 class FooClass(object):
101 98 """FooClass
102 99
103 100 Example:
104 101
105 102 >>> 1+1
106 103 2
107 104 """
108 105
109 106 def __init__(self,x):
110 107 """Make a FooClass.
111 108
112 109 Example:
113 110
114 111 >>> f = FooClass(3)
115 112 junk
116 113 """
117 114 print('Making a FooClass.')
118 115 self.x = x
119 116
120 117 def bar(self,y):
121 118 """Example:
122 119
123 120 >>> ff = FooClass(3)
124 121 >>> ff.bar(0)
125 122 boom!
126 123 >>> 1/0
127 124 bam!
128 125 """
129 126 return 1/y
130 127
131 128 def baz(self,y):
132 129 """Example:
133 130
134 131 >>> ff2 = FooClass(3)
135 132 Making a FooClass.
136 133 >>> ff2.baz(3)
137 134 True
138 135 """
139 136 return self.x==y
140 137
141 138
142 139 def test_skip_dt_decorator2():
143 140 """Doctest-skipping decorator should preserve function signature.
144 141 """
145 142 # Hardcoded correct answer
146 143 dtargs = (['x', 'y'], None, 'k', (1,))
147 144 # Introspect out the value
148 145 dtargsr = getargspec(doctest_bad)
149 146 assert dtargsr==dtargs, \
150 147 "Incorrectly reconstructed args for doctest_bad: %s" % (dtargsr,)
151 148
152 149
153 150 @dec.skip_linux
154 151 def test_linux():
155 nt.assert_false(sys.platform.startswith('linux'),"This test can't run under linux")
152 assert sys.platform.startswith("linux") is False, "This test can't run under linux"
153
156 154
157 155 @dec.skip_win32
158 156 def test_win32():
159 nt.assert_not_equal(sys.platform,'win32',"This test can't run under windows")
157 assert sys.platform != "win32", "This test can't run under windows"
158
160 159
161 160 @dec.skip_osx
162 161 def test_osx():
163 nt.assert_not_equal(sys.platform,'darwin',"This test can't run under osx")
164
162 assert sys.platform != "darwin", "This test can't run under osx"
General Comments 0
You need to be logged in to leave comments. Login now