##// END OF EJS Templates
[core][tests][formatters] Remove nose
Samuel Gaist -
Show More
@@ -7,7 +7,7 b' try:'
7 7 import numpy
8 8 except:
9 9 numpy = None
10 import nose.tools as nt
10 import pytest
11 11
12 12 from IPython import get_ipython
13 13 from traitlets.config import Config
@@ -95,24 +95,25 b' def test_bad_precision():'
95 95 """test various invalid values for float_precision."""
96 96 f = PlainTextFormatter()
97 97 def set_fp(p):
98 f.float_precision=p
99 nt.assert_raises(ValueError, set_fp, '%')
100 nt.assert_raises(ValueError, set_fp, '%.3f%i')
101 nt.assert_raises(ValueError, set_fp, 'foo')
102 nt.assert_raises(ValueError, set_fp, -1)
98 f.float_precision = p
99
100 pytest.raises(ValueError, set_fp, "%")
101 pytest.raises(ValueError, set_fp, "%.3f%i")
102 pytest.raises(ValueError, set_fp, "foo")
103 pytest.raises(ValueError, set_fp, -1)
103 104
104 105 def test_for_type():
105 106 f = PlainTextFormatter()
106 107
107 108 # initial return, None
108 nt.assert_is(f.for_type(C, foo_printer), None)
109 assert f.for_type(C, foo_printer) is None
109 110 # no func queries
110 nt.assert_is(f.for_type(C), foo_printer)
111 assert f.for_type(C) is foo_printer
111 112 # shouldn't change anything
112 nt.assert_is(f.for_type(C), foo_printer)
113 assert f.for_type(C) is foo_printer
113 114 # None should do the same
114 nt.assert_is(f.for_type(C, None), foo_printer)
115 nt.assert_is(f.for_type(C, None), foo_printer)
115 assert f.for_type(C, None) is foo_printer
116 assert f.for_type(C, None) is foo_printer
116 117
117 118 def test_for_type_string():
118 119 f = PlainTextFormatter()
@@ -120,13 +121,13 b' def test_for_type_string():'
120 121 type_str = '%s.%s' % (C.__module__, 'C')
121 122
122 123 # initial return, None
123 nt.assert_is(f.for_type(type_str, foo_printer), None)
124 assert f.for_type(type_str, foo_printer) is None
124 125 # no func queries
125 nt.assert_is(f.for_type(type_str), foo_printer)
126 nt.assert_in(_mod_name_key(C), f.deferred_printers)
127 nt.assert_is(f.for_type(C), foo_printer)
128 nt.assert_not_in(_mod_name_key(C), f.deferred_printers)
129 nt.assert_in(C, f.type_printers)
126 assert f.for_type(type_str) is foo_printer
127 assert _mod_name_key(C) in f.deferred_printers
128 assert f.for_type(C) is foo_printer
129 assert _mod_name_key(C) not in f.deferred_printers
130 assert C in f.type_printers
130 131
131 132 def test_for_type_by_name():
132 133 f = PlainTextFormatter()
@@ -134,21 +135,22 b' def test_for_type_by_name():'
134 135 mod = C.__module__
135 136
136 137 # initial return, None
137 nt.assert_is(f.for_type_by_name(mod, 'C', foo_printer), None)
138 assert f.for_type_by_name(mod, "C", foo_printer) is None
138 139 # no func queries
139 nt.assert_is(f.for_type_by_name(mod, 'C'), foo_printer)
140 assert f.for_type_by_name(mod, "C") is foo_printer
140 141 # shouldn't change anything
141 nt.assert_is(f.for_type_by_name(mod, 'C'), foo_printer)
142 assert f.for_type_by_name(mod, "C") is foo_printer
142 143 # None should do the same
143 nt.assert_is(f.for_type_by_name(mod, 'C', None), foo_printer)
144 nt.assert_is(f.for_type_by_name(mod, 'C', None), foo_printer)
144 assert f.for_type_by_name(mod, "C", None) is foo_printer
145 assert f.for_type_by_name(mod, "C", None) is foo_printer
146
145 147
146 148 def test_lookup():
147 149 f = PlainTextFormatter()
148 150
149 151 f.for_type(C, foo_printer)
150 nt.assert_is(f.lookup(C()), foo_printer)
151 with nt.assert_raises(KeyError):
152 assert f.lookup(C()) is foo_printer
153 with pytest.raises(KeyError):
152 154 f.lookup(A())
153 155
154 156 def test_lookup_string():
@@ -156,16 +158,16 b' def test_lookup_string():'
156 158 type_str = '%s.%s' % (C.__module__, 'C')
157 159
158 160 f.for_type(type_str, foo_printer)
159 nt.assert_is(f.lookup(C()), foo_printer)
161 assert f.lookup(C()) is foo_printer
160 162 # should move from deferred to imported dict
161 nt.assert_not_in(_mod_name_key(C), f.deferred_printers)
162 nt.assert_in(C, f.type_printers)
163 assert _mod_name_key(C) not in f.deferred_printers
164 assert C in f.type_printers
163 165
164 166 def test_lookup_by_type():
165 167 f = PlainTextFormatter()
166 168 f.for_type(C, foo_printer)
167 nt.assert_is(f.lookup_by_type(C), foo_printer)
168 with nt.assert_raises(KeyError):
169 assert f.lookup_by_type(C) is foo_printer
170 with pytest.raises(KeyError):
169 171 f.lookup_by_type(A)
170 172
171 173 def test_lookup_by_type_string():
@@ -174,69 +176,69 b' def test_lookup_by_type_string():'
174 176 f.for_type(type_str, foo_printer)
175 177
176 178 # verify insertion
177 nt.assert_in(_mod_name_key(C), f.deferred_printers)
178 nt.assert_not_in(C, f.type_printers)
179 assert _mod_name_key(C) in f.deferred_printers
180 assert C not in f.type_printers
179 181
180 nt.assert_is(f.lookup_by_type(type_str), foo_printer)
182 assert f.lookup_by_type(type_str) is foo_printer
181 183 # lookup by string doesn't cause import
182 nt.assert_in(_mod_name_key(C), f.deferred_printers)
183 nt.assert_not_in(C, f.type_printers)
184 assert _mod_name_key(C) in f.deferred_printers
185 assert C not in f.type_printers
184 186
185 nt.assert_is(f.lookup_by_type(C), foo_printer)
187 assert f.lookup_by_type(C) is foo_printer
186 188 # should move from deferred to imported dict
187 nt.assert_not_in(_mod_name_key(C), f.deferred_printers)
188 nt.assert_in(C, f.type_printers)
189 assert _mod_name_key(C) not in f.deferred_printers
190 assert C in f.type_printers
189 191
190 192 def test_in_formatter():
191 193 f = PlainTextFormatter()
192 194 f.for_type(C, foo_printer)
193 195 type_str = '%s.%s' % (C.__module__, 'C')
194 nt.assert_in(C, f)
195 nt.assert_in(type_str, f)
196 assert C in f
197 assert type_str in f
196 198
197 199 def test_string_in_formatter():
198 200 f = PlainTextFormatter()
199 201 type_str = '%s.%s' % (C.__module__, 'C')
200 202 f.for_type(type_str, foo_printer)
201 nt.assert_in(type_str, f)
202 nt.assert_in(C, f)
203 assert type_str in f
204 assert C in f
203 205
204 206 def test_pop():
205 207 f = PlainTextFormatter()
206 208 f.for_type(C, foo_printer)
207 nt.assert_is(f.lookup_by_type(C), foo_printer)
208 nt.assert_is(f.pop(C, None), foo_printer)
209 assert f.lookup_by_type(C) is foo_printer
210 assert f.pop(C, None) is foo_printer
209 211 f.for_type(C, foo_printer)
210 nt.assert_is(f.pop(C), foo_printer)
211 with nt.assert_raises(KeyError):
212 assert f.pop(C) is foo_printer
213 with pytest.raises(KeyError):
212 214 f.lookup_by_type(C)
213 with nt.assert_raises(KeyError):
215 with pytest.raises(KeyError):
214 216 f.pop(C)
215 with nt.assert_raises(KeyError):
217 with pytest.raises(KeyError):
216 218 f.pop(A)
217 nt.assert_is(f.pop(A, None), None)
219 assert f.pop(A, None) is None
218 220
219 221 def test_pop_string():
220 222 f = PlainTextFormatter()
221 223 type_str = '%s.%s' % (C.__module__, 'C')
222 224
223 with nt.assert_raises(KeyError):
225 with pytest.raises(KeyError):
224 226 f.pop(type_str)
225 227
226 228 f.for_type(type_str, foo_printer)
227 229 f.pop(type_str)
228 with nt.assert_raises(KeyError):
230 with pytest.raises(KeyError):
229 231 f.lookup_by_type(C)
230 with nt.assert_raises(KeyError):
232 with pytest.raises(KeyError):
231 233 f.pop(type_str)
232 234
233 235 f.for_type(C, foo_printer)
234 nt.assert_is(f.pop(type_str, None), foo_printer)
235 with nt.assert_raises(KeyError):
236 assert f.pop(type_str, None) is foo_printer
237 with pytest.raises(KeyError):
236 238 f.lookup_by_type(C)
237 with nt.assert_raises(KeyError):
239 with pytest.raises(KeyError):
238 240 f.pop(type_str)
239 nt.assert_is(f.pop(type_str, None), None)
241 assert f.pop(type_str, None) is None
240 242
241 243
242 244 def test_error_method():
@@ -247,10 +249,10 b' def test_error_method():'
247 249 bad = BadHTML()
248 250 with capture_output() as captured:
249 251 result = f(bad)
250 nt.assert_is(result, None)
251 nt.assert_in("Traceback", captured.stdout)
252 nt.assert_in("Bad HTML", captured.stdout)
253 nt.assert_in("_repr_html_", captured.stdout)
252 assert result is None
253 assert "Traceback" in captured.stdout
254 assert "Bad HTML" in captured.stdout
255 assert "_repr_html_" in captured.stdout
254 256
255 257 def test_nowarn_notimplemented():
256 258 f = HTMLFormatter()
@@ -260,7 +262,7 b' def test_nowarn_notimplemented():'
260 262 h = HTMLNotImplemented()
261 263 with capture_output() as captured:
262 264 result = f(h)
263 nt.assert_is(result, None)
265 assert result is None
264 266 assert "" == captured.stderr
265 267 assert "" == captured.stdout
266 268
@@ -270,10 +272,10 b' def test_warn_error_for_type():'
270 272 f.for_type(int, lambda i: name_error)
271 273 with capture_output() as captured:
272 274 result = f(5)
273 nt.assert_is(result, None)
274 nt.assert_in("Traceback", captured.stdout)
275 nt.assert_in("NameError", captured.stdout)
276 nt.assert_in("name_error", captured.stdout)
275 assert result is None
276 assert "Traceback" in captured.stdout
277 assert "NameError" in captured.stdout
278 assert "name_error" in captured.stdout
277 279
278 280 def test_error_pretty_method():
279 281 f = PlainTextFormatter()
@@ -283,11 +285,11 b' def test_error_pretty_method():'
283 285 bad = BadPretty()
284 286 with capture_output() as captured:
285 287 result = f(bad)
286 nt.assert_is(result, None)
287 nt.assert_in("Traceback", captured.stdout)
288 nt.assert_in("_repr_pretty_", captured.stdout)
289 nt.assert_in("given", captured.stdout)
290 nt.assert_in("argument", captured.stdout)
288 assert result is None
289 assert "Traceback" in captured.stdout
290 assert "_repr_pretty_" in captured.stdout
291 assert "given" in captured.stdout
292 assert "argument" in captured.stdout
291 293
292 294
293 295 def test_bad_repr_traceback():
@@ -296,10 +298,10 b' def test_bad_repr_traceback():'
296 298 with capture_output() as captured:
297 299 result = f(bad)
298 300 # catches error, returns None
299 nt.assert_is(result, None)
300 nt.assert_in("Traceback", captured.stdout)
301 nt.assert_in("__repr__", captured.stdout)
302 nt.assert_in("ValueError", captured.stdout)
301 assert result is None
302 assert "Traceback" in captured.stdout
303 assert "__repr__" in captured.stdout
304 assert "ValueError" in captured.stdout
303 305
304 306
305 307 class MakePDF(object):
@@ -319,8 +321,8 b' def test_print_method_bound():'
319 321 return "hello"
320 322 with capture_output() as captured:
321 323 result = f(MyHTML)
322 nt.assert_is(result, None)
323 nt.assert_not_in("FormatterWarning", captured.stderr)
324 assert result is None
325 assert "FormatterWarning" not in captured.stderr
324 326
325 327 with capture_output() as captured:
326 328 result = f(MyHTML())
@@ -341,8 +343,8 b' def test_print_method_weird():'
341 343 with capture_output() as captured:
342 344 result = f(text_hat)
343 345
344 nt.assert_is(result, None)
345 nt.assert_not_in("FormatterWarning", captured.stderr)
346 assert result is None
347 assert "FormatterWarning" not in captured.stderr
346 348
347 349 class CallableMagicHat(object):
348 350 def __getattr__(self, key):
@@ -362,8 +364,8 b' def test_print_method_weird():'
362 364 with capture_output() as captured:
363 365 result = f(bad)
364 366
365 nt.assert_is(result, None)
366 nt.assert_not_in("FormatterWarning", captured.stderr)
367 assert result is None
368 assert "FormatterWarning" not in captured.stderr
367 369
368 370
369 371 def test_format_config():
@@ -372,12 +374,12 b' def test_format_config():'
372 374 cfg = Config()
373 375 with capture_output() as captured:
374 376 result = f(cfg)
375 nt.assert_is(result, None)
377 assert result is None
376 378 assert captured.stderr == ""
377 379
378 380 with capture_output() as captured:
379 381 result = f(Config)
380 nt.assert_is(result, None)
382 assert result is None
381 383 assert captured.stderr == ""
382 384
383 385
General Comments 0
You need to be logged in to leave comments. Login now