Skip to content

Commit

Permalink
Fix br tags in output
Browse files Browse the repository at this point in the history
  • Loading branch information
benjeffery authored and mergify[bot] committed Oct 18, 2024
1 parent eb2292a commit 84ebb0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
44 changes: 30 additions & 14 deletions python/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,36 +374,52 @@ def test_naturalsize(value, expected):
@pytest.mark.parametrize(
"obj, expected",
[
(0, "Test:0"),
(0, "Test: 0"),
(
{"a": 1},
'<div><spanclass="tskit-details-label">Test:</span><detailsopen><summary>dic'
"t</summary>a:1<br/></details></div>",
'<div><span class="tskit-details-label">Test:</span><details open>'
"<summary>dict</summary>a: 1<br/></details></div>",
),
(
{"b": [1, 2, 3]},
'<div><spanclass="tskit-details-label">Test:</span><detailsopen><summary>dic'
't</summary><div><spanclass="tskit-details-label">b:</span><details><summary'
">list</summary>1<br/>2<br/>3<br/></details></div><br/></details></div>",
'<div><span class="tskit-details-label">Test:</span><details open>'
'<summary>dict</summary><div><span class="tskit-details-label">b:'
"</span><details ><summary>list</summary> 1<br/> 2<br/> 3<br/></"
"details></div><br/></details></div>",
),
(
{"b": [1, 2, {"c": 1}]},
'<div><spanclass="tskit-details-label">Test:</span><detailsopen><summary>dic'
't</summary><div><spanclass="tskit-details-label">b:</span><details><summary'
'>list</summary>1<br/>2<br/><div><spanclass="tskit-details-label"></span><de'
"tails><summary>dict</summary>c:1<br/></details></div><br/></details></div><"
"br/></details></div>",
'<div><span class="tskit-details-label">Test:</span><details open>'
'<summary>dict</summary><div><span class="tskit-details-label">b:'
"</span><details ><summary>list</summary> 1<br/> 2<br/><div><span"
' class="tskit-details-label"></span><details ><summary>dict</'
"summary>c: 1<br/></details></div><br/></details></div><br/></"
"details></div>",
),
(
{"a": "1", "b": "2"},
'<div><spanclass="tskit-details-label">Test:</span><detailsopen><summary>dic'
"t</summary>a:1<br/>b:2<br/></details></div>",
'<div><span class="tskit-details-label">Test:</span><details open>'
"<summary>dict</summary>a: 1<br/>b: 2<br/></details></div>",
),
(
{"a": "a very long thing that is broken in the output"},
'<div><span class="tskit-details-label">Test:</span><details open>'
"<summary>dict</summary>a: a very long thing that is<br/>broken in"
" the output<br/></details></div>",
),
],
ids=[
"integer",
"simple_dict",
"dict_with_list",
"nested_dict_list",
"dict_with_strings",
"dict_with_multiline_strings",
],
)
def test_obj_to_collapsed_html(obj, expected):
assert (
util.obj_to_collapsed_html(obj, "Test", 1).replace(" ", "").replace("\n", "")
util.obj_to_collapsed_html(obj, "Test", 1).replace(" ", "").replace("\n", "")
== expected
)

Expand Down
3 changes: 2 additions & 1 deletion python/tskit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ def obj_to_collapsed_html(d, name=None, open_depth=0, max_items=30, max_item_len
if len(d_str) > max_item_len:
d_str = d_str[:max_item_len] + "..."
d_str = textwrap.fill(d_str, width=30)
d_str = f"{name} {html.escape(str(d_str))}"
d_str = d_str.replace("\n", "<br/>")
return f"{name} {html.escape(str(d_str))}"
return d_str


def truncate_string_end(string, length):
Expand Down

0 comments on commit 84ebb0b

Please sign in to comment.