@@ -25,7 +25,7 @@ async def test_landscape_no_page_size() -> None:
2525 )
2626
2727 docx_doc = await doc .to_docx ()
28- section = docx_doc .sections [- 2 ]
28+ section = docx_doc .sections [- 1 ]
2929 assert section .page_width is not None
3030 assert section .page_height is not None
3131 assert section .page_width > section .page_height
@@ -52,7 +52,7 @@ async def test_landscape_with_page_size() -> None:
5252 )
5353
5454 docx_doc = await doc .to_docx ()
55- section = docx_doc .sections [- 2 ]
55+ section = docx_doc .sections [- 1 ]
5656 assert section .page_width is not None
5757 assert section .page_height is not None
5858 assert section .page_width > section .page_height
@@ -77,7 +77,7 @@ async def test_portrait_no_page_size() -> None:
7777 )
7878
7979 docx_doc = await doc .to_docx ()
80- section = docx_doc .sections [- 2 ]
80+ section = docx_doc .sections [- 1 ]
8181 assert section .page_width is not None
8282 assert section .page_height is not None
8383 assert section .page_width < section .page_height
@@ -99,7 +99,7 @@ async def test_no_orientation() -> None:
9999 )
100100
101101 docx_doc = await doc .to_docx ()
102- section = docx_doc .sections [- 2 ]
102+ section = docx_doc .sections [- 1 ]
103103 assert section .page_width is not None
104104 assert section .page_height is not None
105105
@@ -109,13 +109,8 @@ async def test_landscape_multi_section() -> None:
109109 """Test that landscape properties apply to the correct section index.
110110
111111 With 2 declarative sections (portrait then landscape), the resulting
112- docx_doc.sections list has 3 entries: sections[0] is portrait, sections[1]
113- is landscape, and sections[2] is the trailing empty section added by the
114- final add_section() call.
115-
116- This test would have failed with the old off-by-one bug, where landscape
117- properties were applied to sections[2] (the trailing sentinel) instead of
118- sections[1] (the second declarative section).
112+ docx_doc.sections list has exactly 2 entries: sections[0] is portrait
113+ and sections[1] is landscape.
119114 """
120115 doc = declarative .Document (
121116 sections = [
@@ -137,8 +132,8 @@ async def test_landscape_multi_section() -> None:
137132 docx_doc = await doc .to_docx ()
138133 sections = list (docx_doc .sections )
139134
140- # 2 declarative sections produce 3 total sections (trailing sentinel at [-1]) .
141- expected_section_count = 3
135+ # 2 declarative sections produce exactly 2 sections.
136+ expected_section_count = 2
142137 assert len (sections ) == expected_section_count
143138
144139 portrait_section = sections [0 ]
0 commit comments