summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pprint.py
diff options
context:
space:
mode:
authorsblondon <sblondon@users.noreply.github.com>2021-03-24 08:23:20 (GMT)
committerGitHub <noreply@github.com>2021-03-24 08:23:20 (GMT)
commit3ba3d513b1e3c63d09cb798b982a9e6c369cea4c (patch)
tree22b40601f7e0464896a42a82bf7146b943830866 /Lib/test/test_pprint.py
parenta02683ac38183fa3a45c32319dfd329c5e622f0e (diff)
downloadcpython-3ba3d513b1e3c63d09cb798b982a9e6c369cea4c.zip
cpython-3ba3d513b1e3c63d09cb798b982a9e6c369cea4c.tar.gz
cpython-3ba3d513b1e3c63d09cb798b982a9e6c369cea4c.tar.bz2
bpo-42914: add a pprint underscore_numbers option (GH-24864)
pprint() gains a new boolean underscore_numbers kwarg to emit integers with thousands separated by an underscore character for improved readability (for example 1_000_000 instead of 1000000).
Diffstat (limited to 'Lib/test/test_pprint.py')
-rw-r--r--Lib/test/test_pprint.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index c4a8578..e5d2ac5 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -206,6 +206,7 @@ class QueryTestCase(unittest.TestCase):
self.assertEqual(pprint.pformat(simple), native)
self.assertEqual(pprint.pformat(simple, width=1, indent=0)
.replace('\n', ' '), native)
+ self.assertEqual(pprint.pformat(simple, underscore_numbers=True), native)
self.assertEqual(pprint.saferepr(simple), native)
def test_container_repr_override_called(self):
@@ -323,6 +324,18 @@ class QueryTestCase(unittest.TestCase):
'1 '
'2']]]]]""")
+ def test_integer(self):
+ self.assertEqual(pprint.pformat(1234567), '1234567')
+ self.assertEqual(pprint.pformat(1234567, underscore_numbers=True), '1_234_567')
+
+ class Temperature(int):
+ def __new__(cls, celsius_degrees):
+ return super().__new__(Temperature, celsius_degrees)
+ def __repr__(self):
+ kelvin_degrees = self + 273.15
+ return f"{kelvin_degrees}°K"
+ self.assertEqual(pprint.pformat(Temperature(1000)), '1273.15°K')
+
def test_sorted_dict(self):
# Starting in Python 2.5, pprint sorts dict displays by key regardless
# of how small the dictionary may be.