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