##// END OF EJS Templates
Remove some nose
Matthias Bussonnier -
Show More
@@ -48,16 +48,16 b' def foo_printer(obj, pp, cycle):'
48 def test_pretty():
48 def test_pretty():
49 f = PlainTextFormatter()
49 f = PlainTextFormatter()
50 f.for_type(A, foo_printer)
50 f.for_type(A, foo_printer)
51 nt.assert_equal(f(A()), 'foo')
51 assert f(A()) == "foo"
52 nt.assert_equal(f(B()), 'B()')
52 assert f(B()) == "B()"
53 nt.assert_equal(f(GoodPretty()), 'foo')
53 assert f(GoodPretty()) == "foo"
54 # Just don't raise an exception for the following:
54 # Just don't raise an exception for the following:
55 f(BadPretty())
55 f(BadPretty())
56
56
57 f.pprint = False
57 f.pprint = False
58 nt.assert_equal(f(A()), 'A()')
58 assert f(A()) == "A()"
59 nt.assert_equal(f(B()), 'B()')
59 assert f(B()) == "B()"
60 nt.assert_equal(f(GoodPretty()), 'GoodPretty()')
60 assert f(GoodPretty()) == "GoodPretty()"
61
61
62
62
63 def test_deferred():
63 def test_deferred():
@@ -66,29 +66,30 b' def test_deferred():'
66 def test_precision():
66 def test_precision():
67 """test various values for float_precision."""
67 """test various values for float_precision."""
68 f = PlainTextFormatter()
68 f = PlainTextFormatter()
69 nt.assert_equal(f(pi), repr(pi))
69 assert f(pi) == repr(pi)
70 f.float_precision = 0
70 f.float_precision = 0
71 if numpy:
71 if numpy:
72 po = numpy.get_printoptions()
72 po = numpy.get_printoptions()
73 nt.assert_equal(po['precision'], 0)
73 assert po["precision"] == 0
74 nt.assert_equal(f(pi), '3')
74 assert f(pi) == "3"
75 f.float_precision = 2
75 f.float_precision = 2
76 if numpy:
76 if numpy:
77 po = numpy.get_printoptions()
77 po = numpy.get_printoptions()
78 nt.assert_equal(po['precision'], 2)
78 assert po["precision"] == 2
79 nt.assert_equal(f(pi), '3.14')
79 assert f(pi) == "3.14"
80 f.float_precision = '%g'
80 f.float_precision = "%g"
81 if numpy:
81 if numpy:
82 po = numpy.get_printoptions()
82 po = numpy.get_printoptions()
83 nt.assert_equal(po['precision'], 2)
83 assert po["precision"] == 2
84 nt.assert_equal(f(pi), '3.14159')
84 assert f(pi) == "3.14159"
85 f.float_precision = '%e'
85 f.float_precision = "%e"
86 nt.assert_equal(f(pi), '3.141593e+00')
86 assert f(pi) == "3.141593e+00"
87 f.float_precision = ''
87 f.float_precision = ""
88 if numpy:
88 if numpy:
89 po = numpy.get_printoptions()
89 po = numpy.get_printoptions()
90 nt.assert_equal(po['precision'], 8)
90 assert po["precision"] == 8
91 nt.assert_equal(f(pi), repr(pi))
91 assert f(pi) == repr(pi)
92
92
93
93 def test_bad_precision():
94 def test_bad_precision():
94 """test various invalid values for float_precision."""
95 """test various invalid values for float_precision."""
@@ -260,8 +261,9 b' def test_nowarn_notimplemented():'
260 with capture_output() as captured:
261 with capture_output() as captured:
261 result = f(h)
262 result = f(h)
262 nt.assert_is(result, None)
263 nt.assert_is(result, None)
263 nt.assert_equal("", captured.stderr)
264 assert "" == captured.stderr
264 nt.assert_equal("", captured.stdout)
265 assert "" == captured.stdout
266
265
267
266 def test_warn_error_for_type():
268 def test_warn_error_for_type():
267 f = HTMLFormatter()
269 f = HTMLFormatter()
@@ -307,7 +309,8 b' class MakePDF(object):'
307 def test_pdf_formatter():
309 def test_pdf_formatter():
308 pdf = MakePDF()
310 pdf = MakePDF()
309 f = PDFFormatter()
311 f = PDFFormatter()
310 nt.assert_equal(f(pdf), 'PDF')
312 assert f(pdf) == "PDF"
313
311
314
312 def test_print_method_bound():
315 def test_print_method_bound():
313 f = HTMLFormatter()
316 f = HTMLFormatter()
@@ -321,8 +324,9 b' def test_print_method_bound():'
321
324
322 with capture_output() as captured:
325 with capture_output() as captured:
323 result = f(MyHTML())
326 result = f(MyHTML())
324 nt.assert_equal(result, "hello")
327 assert result == "hello"
325 nt.assert_equal(captured.stderr, "")
328 assert captured.stderr == ""
329
326
330
327 def test_print_method_weird():
331 def test_print_method_weird():
328
332
@@ -331,9 +335,9 b' def test_print_method_weird():'
331 return key
335 return key
332
336
333 f = HTMLFormatter()
337 f = HTMLFormatter()
334
338
335 text_hat = TextMagicHat()
339 text_hat = TextMagicHat()
336 nt.assert_equal(text_hat._repr_html_, '_repr_html_')
340 assert text_hat._repr_html_ == "_repr_html_"
337 with capture_output() as captured:
341 with capture_output() as captured:
338 result = f(text_hat)
342 result = f(text_hat)
339
343
@@ -347,8 +351,8 b' def test_print_method_weird():'
347 call_hat = CallableMagicHat()
351 call_hat = CallableMagicHat()
348 with capture_output() as captured:
352 with capture_output() as captured:
349 result = f(call_hat)
353 result = f(call_hat)
350
354
351 nt.assert_equal(result, None)
355 assert result == None
352
356
353 class BadReprArgs(object):
357 class BadReprArgs(object):
354 def _repr_html_(self, extra, args):
358 def _repr_html_(self, extra, args):
@@ -369,24 +373,25 b' def test_format_config():'
369 with capture_output() as captured:
373 with capture_output() as captured:
370 result = f(cfg)
374 result = f(cfg)
371 nt.assert_is(result, None)
375 nt.assert_is(result, None)
372 nt.assert_equal(captured.stderr, "")
376 assert captured.stderr == ""
373
377
374 with capture_output() as captured:
378 with capture_output() as captured:
375 result = f(Config)
379 result = f(Config)
376 nt.assert_is(result, None)
380 nt.assert_is(result, None)
377 nt.assert_equal(captured.stderr, "")
381 assert captured.stderr == ""
382
378
383
379 def test_pretty_max_seq_length():
384 def test_pretty_max_seq_length():
380 f = PlainTextFormatter(max_seq_length=1)
385 f = PlainTextFormatter(max_seq_length=1)
381 lis = list(range(3))
386 lis = list(range(3))
382 text = f(lis)
387 text = f(lis)
383 nt.assert_equal(text, '[0, ...]')
388 assert text == "[0, ...]"
384 f.max_seq_length = 0
389 f.max_seq_length = 0
385 text = f(lis)
390 text = f(lis)
386 nt.assert_equal(text, '[0, 1, 2]')
391 assert text == "[0, 1, 2]"
387 text = f(list(range(1024)))
392 text = f(list(range(1024)))
388 lines = text.splitlines()
393 lines = text.splitlines()
389 nt.assert_equal(len(lines), 1024)
394 assert len(lines) == 1024
390
395
391
396
392 def test_ipython_display_formatter():
397 def test_ipython_display_formatter():
@@ -409,16 +414,16 b' def test_ipython_display_formatter():'
409
414
410 yes = SelfDisplaying()
415 yes = SelfDisplaying()
411 no = NotSelfDisplaying()
416 no = NotSelfDisplaying()
412
417
413 d, md = f.format(no)
418 d, md = f.format(no)
414 nt.assert_equal(d, {'text/plain': repr(no)})
419 assert d == {"text/plain": repr(no)}
415 nt.assert_equal(md, {})
420 assert md == {}
416 nt.assert_equal(catcher, [])
421 assert catcher == []
417
422
418 d, md = f.format(yes)
423 d, md = f.format(yes)
419 nt.assert_equal(d, {})
424 assert d == {}
420 nt.assert_equal(md, {})
425 assert md == {}
421 nt.assert_equal(catcher, [yes])
426 assert catcher == [yes]
422
427
423 f.ipython_display_formatter.enabled = save_enabled
428 f.ipython_display_formatter.enabled = save_enabled
424
429
@@ -431,8 +436,8 b' def test_json_as_string_deprecated():'
431 f = JSONFormatter()
436 f = JSONFormatter()
432 with warnings.catch_warnings(record=True) as w:
437 with warnings.catch_warnings(record=True) as w:
433 d = f(JSONString())
438 d = f(JSONString())
434 nt.assert_equal(d, {})
439 assert d == {}
435 nt.assert_equal(len(w), 1)
440 assert len(w) == 1
436
441
437
442
438 def test_repr_mime():
443 def test_repr_mime():
@@ -458,19 +463,22 b' def test_repr_mime():'
458 obj = HasReprMime()
463 obj = HasReprMime()
459 d, md = f.format(obj)
464 d, md = f.format(obj)
460 html_f.enabled = save_enabled
465 html_f.enabled = save_enabled
461
462 nt.assert_equal(sorted(d), ['application/json+test.v2',
463 'image/png',
464 'plain/text',
465 'text/html',
466 'text/plain'])
467 nt.assert_equal(md, {})
468
466
469 d, md = f.format(obj, include={'image/png'})
467 assert sorted(d) == [
470 nt.assert_equal(list(d.keys()), ['image/png'],
468 "application/json+test.v2",
471 'Include should filter out even things from repr_mimebundle')
469 "image/png",
472 nt.assert_equal(d['image/png'], 'i-overwrite', '_repr_mimebundle_ take precedence')
470 "plain/text",
471 "text/html",
472 "text/plain",
473 ]
474 assert md == {}
473
475
476 d, md = f.format(obj, include={"image/png"})
477 assert list(d.keys()) == [
478 "image/png"
479 ], "Include should filter out even things from repr_mimebundle"
480
481 assert d["image/png"] == "i-overwrite", "_repr_mimebundle_ take precedence"
474
482
475
483
476 def test_pass_correct_include_exclude():
484 def test_pass_correct_include_exclude():
@@ -514,13 +522,14 b' def test_repr_mime_meta():'
514 f = get_ipython().display_formatter
522 f = get_ipython().display_formatter
515 obj = HasReprMimeMeta()
523 obj = HasReprMimeMeta()
516 d, md = f.format(obj)
524 d, md = f.format(obj)
517 nt.assert_equal(sorted(d), ['image/png', 'text/plain'])
525 assert sorted(d) == ["image/png", "text/plain"]
518 nt.assert_equal(md, {
526 assert md == {
519 'image/png': {
527 "image/png": {
520 'width': 5,
528 "width": 5,
521 'height': 10,
529 "height": 10,
522 }
530 }
523 })
531 }
532
524
533
525 def test_repr_mime_failure():
534 def test_repr_mime_failure():
526 class BadReprMime(object):
535 class BadReprMime(object):
@@ -530,4 +539,4 b' def test_repr_mime_failure():'
530 f = get_ipython().display_formatter
539 f = get_ipython().display_formatter
531 obj = BadReprMime()
540 obj = BadReprMime()
532 d, md = f.format(obj)
541 d, md = f.format(obj)
533 nt.assert_in('text/plain', d)
542 assert "text/plain" in d
General Comments 0
You need to be logged in to leave comments. Login now