diff --git a/python/tests/test_util.py b/python/tests/test_util.py
index 4a124619fa..a10b292db4 100644
--- a/python/tests/test_util.py
+++ b/python/tests/test_util.py
@@ -374,36 +374,52 @@ def test_naturalsize(value, expected):
@pytest.mark.parametrize(
"obj, expected",
[
- (0, "Test:0"),
+ (0, "Test: 0"),
(
{"a": 1},
- '
Test:dic'
- "ta:1
",
+ 'Test:'
+ "dict
a: 1
",
),
(
{"b": [1, 2, 3]},
- '",
+ 'Test:'
+ 'dict
b:'
+ "list
1
2
3
"
+ "details>
",
),
(
{"b": [1, 2, {"c": 1}]},
- '",
+ 'Test:'
+ 'dict
b:'
+ "list
1
2
dict'
+ "summary>c: 1
"
+ "details> ",
),
(
{"a": "1", "b": "2"},
- 'Test:dic'
- "ta:1
b:2
",
+ 'Test:'
+ "dict
a: 1
b: 2
",
),
+ (
+ {"a": "a very long thing that is broken in the output"},
+ 'Test:'
+ "dict
a: a very long thing that is
broken in"
+ " the output
",
+ ),
+ ],
+ 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
)
diff --git a/python/tskit/util.py b/python/tskit/util.py
index 90dbe1720b..834bf6a20a 100644
--- a/python/tskit/util.py
+++ b/python/tskit/util.py
@@ -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", "
")
- return f"{name} {html.escape(str(d_str))}"
+ return d_str
def truncate_string_end(string, length):