Skip to content

Commit

Permalink
pass dumps params
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Nov 5, 2021
1 parent 8cf9b68 commit 5d601fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,17 @@ def print_json(
raise TypeError(
f"json must be str. Did you mean print_json(data={json!r}) ?"
)
json_renderable = JSON(json, indent=indent, highlight=highlight)
json_renderable = JSON(
json,
indent=indent,
highlight=highlight,
skip_keys=skip_keys,
ensure_ascii=ensure_ascii,
check_circular=check_circular,
allow_nan=allow_nan,
default=default,
sort_keys=sort_keys,
)
self.print(json_renderable)

def update_screen(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def test_print_json_data():
assert result == expected


def test_print_json_ensure_ascii():
console = Console(file=io.StringIO(), color_system="truecolor")
console.print_json(data={"foo": "💩"}, ensure_ascii=False)
result = console.file.getvalue()
print(repr(result))
expected = '\x1b[1m{\x1b[0m\n \x1b[1;34m"foo"\x1b[0m: \x1b[32m"💩"\x1b[0m\n\x1b[1m}\x1b[0m\n'
assert result == expected


def test_log():
console = Console(
file=io.StringIO(),
Expand Down

0 comments on commit 5d601fa

Please sign in to comment.