Skip to content

Commit 367caee

Browse files
committed
Simplify toggle test
1 parent b60f5ff commit 367caee

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

tests/test_integration.py

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ def _assert_rst_converts_to_notion_objects(
6565
expected_objects: list[NotionObject[Any]],
6666
make_app: Callable[..., SphinxTestApp],
6767
tmp_path: Path,
68+
extensions: tuple[str, ...] = ("sphinx_notion",),
6869
) -> None:
6970
"""
7071
The given rST content is converted to the given expected objects.
7172
"""
7273
srcdir = tmp_path / "src"
7374
srcdir.mkdir()
75+
7476
(srcdir / "conf.py").write_text(data="")
7577

7678
cleaned_content = textwrap.dedent(text=rst_content).strip()
@@ -80,7 +82,7 @@ def _assert_rst_converts_to_notion_objects(
8082
srcdir=srcdir,
8183
builddir=tmp_path / "build",
8284
buildername="notion",
83-
confoverrides={"extensions": ["sphinx_notion"]},
85+
confoverrides={"extensions": list(extensions)},
8486
)
8587
app.build()
8688

@@ -1020,7 +1022,7 @@ def test_collapse_block(
10201022
"""
10211023
Test that collapse directives convert to Notion ToggleItem blocks.
10221024
"""
1023-
rst_content = textwrap.dedent("""
1025+
rst_content = """
10241026
Regular paragraph.
10251027
10261028
.. collapse:: Click to expand
@@ -1030,7 +1032,7 @@ def test_collapse_block(
10301032
It supports **formatting**.
10311033
10321034
Another paragraph.
1033-
""")
1035+
"""
10341036

10351037
# Create the toggle block with nested content
10361038
toggle_block = UnoToggleItem(text="Click to expand")
@@ -1044,7 +1046,7 @@ def test_collapse_block(
10441046
+ text(text=".", bold=False)
10451047
)
10461048

1047-
# Add nested content to toggle (ignoring formatting due to complexity)
1049+
# Add nested content to toggle
10481050
obj_ref_1 = nested_para1.obj_ref # pyright: ignore[reportUnknownMemberType]
10491051
obj_ref_2 = nested_para2.obj_ref # pyright: ignore[reportUnknownMemberType]
10501052
toggle_block.obj_ref.value.children.append(obj_ref_1) # pyright: ignore[reportUnknownMemberType]
@@ -1056,38 +1058,10 @@ def test_collapse_block(
10561058
UnoParagraph(text="Another paragraph."),
10571059
]
10581060

1059-
# Use a custom test helper for this specific test with sphinx-toolbox
1060-
srcdir = tmp_path / "src"
1061-
srcdir.mkdir()
1062-
1063-
# Create conf.py with both extensions
1064-
conf_content = """
1065-
extensions = ['sphinx_notion', 'sphinx_toolbox.collapse']
1066-
"""
1067-
(srcdir / "conf.py").write_text(data=conf_content)
1068-
1069-
cleaned_content = textwrap.dedent(text=rst_content).strip()
1070-
(srcdir / "index.rst").write_text(data=cleaned_content)
1071-
1072-
app = make_app(
1073-
srcdir=srcdir,
1074-
builddir=tmp_path / "build",
1075-
buildername="notion",
1061+
_assert_rst_converts_to_notion_objects(
1062+
rst_content=rst_content,
1063+
expected_objects=expected_objects,
1064+
make_app=make_app,
1065+
tmp_path=tmp_path,
1066+
extensions=["sphinx_notion", "sphinx_toolbox.collapse"],
10761067
)
1077-
app.build()
1078-
1079-
output_path = tmp_path / "build" / "notion" / "index.json"
1080-
assert output_path.exists()
1081-
1082-
with output_path.open() as file:
1083-
actual_json = file.read()
1084-
1085-
actual_objects = json.loads(s=actual_json)
1086-
1087-
expected_json_objects = [
1088-
obj.obj_ref.serialize_for_api()
1089-
for obj in expected_objects
1090-
if isinstance(obj.obj_ref, GenericObject)
1091-
]
1092-
1093-
assert actual_objects == expected_json_objects

0 commit comments

Comments
 (0)