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