|
48 | 48 | """ |
49 | 49 |
|
50 | 50 | import re |
| 51 | +import struct |
51 | 52 | import warnings |
52 | 53 | from collections import Counter, OrderedDict, defaultdict, deque |
53 | 54 | from enum import Enum, Flag |
|
58 | 59 | from hypothesis import given, strategies as st |
59 | 60 | from hypothesis.control import current_build_context |
60 | 61 | from hypothesis.internal.compat import PYPY |
| 62 | +from hypothesis.internal.conjecture.floats import float_to_lex |
61 | 63 | from hypothesis.internal.floats import SIGNALING_NAN |
62 | 64 | from hypothesis.vendor import pretty |
63 | 65 |
|
@@ -603,13 +605,15 @@ def test_breakable_at_group_boundary(): |
603 | 605 | [ |
604 | 606 | (float("nan"), "nan"), |
605 | 607 | (-float("nan"), "-nan"), |
606 | | - (SIGNALING_NAN, "nan # Saw 1 signaling NaN"), |
607 | | - (-SIGNALING_NAN, "-nan # Saw 1 signaling NaN"), |
608 | | - ((SIGNALING_NAN, SIGNALING_NAN), "(nan, nan) # Saw 2 signaling NaNs"), |
| 608 | + (SIGNALING_NAN, "struct.unpack('d', struct.pack('Q', 0x7ff8000000000001))[0]"), |
| 609 | + (-SIGNALING_NAN, "struct.unpack('d', struct.pack('Q', 0xfff8000000000001))[0]"), |
609 | 610 | ], |
610 | 611 | ) |
611 | 612 | def test_nan_reprs(obj, rep): |
612 | 613 | assert pretty.pretty(obj) == rep |
| 614 | + assert float_to_lex(obj) == float_to_lex( |
| 615 | + eval(rep, {"struct": struct, "nan": float("nan")}) |
| 616 | + ) |
613 | 617 |
|
614 | 618 |
|
615 | 619 | def _repr_call(*args, **kwargs): |
@@ -739,3 +743,18 @@ def test_pprint_map_with_cycle(data): |
739 | 743 | p = pretty.RepresentationPrinter(context=current_build_context()) |
740 | 744 | p.pretty(x) |
741 | 745 | assert p.getvalue() == "ValidSyntaxRepr(...)" |
| 746 | + |
| 747 | + |
| 748 | +def test_pprint_large_integers(): |
| 749 | + p = pretty.RepresentationPrinter() |
| 750 | + p.pretty(1234567890) |
| 751 | + assert p.getvalue() == "1_234_567_890" |
| 752 | + |
| 753 | + |
| 754 | +def test_pprint_extremely_large_integers(): |
| 755 | + x = 10**5000 # repr fails with ddos error |
| 756 | + p = pretty.RepresentationPrinter() |
| 757 | + p.pretty(x) |
| 758 | + got = p.getvalue() |
| 759 | + assert got == f"{x:#_x}" # hexadecimal with underscores |
| 760 | + assert eval(got) == x |
0 commit comments