Values exceeding the console's width break print_json

This commit is contained in:
James Estevez 2021-11-06 11:49:33 -07:00
parent 9b42555e26
commit 316be7bf67
No known key found for this signature in database
GPG Key ID: C0C050782B9D5B32
1 changed files with 22 additions and 0 deletions

View File

@ -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()