From 316be7bf67715410ad64ea497688bf93b5e92b88 Mon Sep 17 00:00:00 2001 From: James Estevez Date: Sat, 6 Nov 2021 11:49:33 -0700 Subject: [PATCH] Values exceeding the console's width break print_json --- tests/test_rich_print.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_rich_print.py b/tests/test_rich_print.py index f6ea5110..a92b8000 100644 --- a/tests/test_rich_print.py +++ b/tests/test_rich_print.py @@ -1,4 +1,5 @@ import io +import json import rich from rich.console import Console @@ -38,6 +39,27 @@ def test_rich_print_json(): assert result == expected +def test_rich_print_json_round_trip(): + data = ["x" * 100, 2e128] + console = rich.get_console() + with console.capture() as capture: + rich.print_json(data=data, indent=4) + result = capture.get() + print(repr(result)) + result_data = json.loads(result) + assert result_data == data + + +def test_rich_print_json_no_truncation(): + console = rich.get_console() + with console.capture() as capture: + rich.print_json(f'["{"x" * 100}", {int(2e128)}]', indent=4) + result = capture.get() + print(repr(result)) + assert ("x" * 100) in result + assert str(int(2e128)) in result + + def test_rich_print_X(): console = rich.get_console() output = io.StringIO()