Skip to content

Commit 7c88a58

Browse files
author
Steve Canny
committed
api: remove old Document.add_section()
1 parent 664905c commit 7c88a58

File tree

4 files changed

+3
-84
lines changed

4 files changed

+3
-84
lines changed

docx/api.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ def add_picture(self, image_descriptor, width=None, height=None):
6565
return self._document.add_picture(image_descriptor, width, height)
6666

6767
def add_section(self, start_type=WD_SECTION.NEW_PAGE):
68-
"""
69-
Return a |Section| object representing a new section added at the end
70-
of the document. The optional *start_type* argument must be a member
71-
of the :ref:`WdSectionStart` enumeration defaulting to
72-
``WD_SECTION.NEW_PAGE`` if not provided.
73-
"""
74-
return self._document_part.add_section(start_type)
68+
return self._document.add_section(start_type)
7569

7670
def add_table(self, rows, cols, style='Light Shading Accent 1'):
7771
"""

docx/parts/document.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from ..blkcntnr import BlockItemContainer
1414
from ..document import Document
15-
from ..enum.section import WD_SECTION
1615
from ..opc.constants import RELATIONSHIP_TYPE as RT
1716
from ..opc.part import XmlPart
1817
from ..section import Section
@@ -25,15 +24,6 @@ class DocumentPart(XmlPart):
2524
"""
2625
Main document part of a WordprocessingML (WML) package, aka a .docx file.
2726
"""
28-
def add_section(self, start_type=WD_SECTION.NEW_PAGE):
29-
"""
30-
Return a |Section| object representing a new section added at the end
31-
of the document.
32-
"""
33-
new_sectPr = self._element.body.add_section_break()
34-
new_sectPr.start_type = start_type
35-
return Section(new_sectPr)
36-
3727
def add_table(self, rows, cols):
3828
"""
3929
Return a table having *rows* rows and *cols* columns, newly appended

tests/parts/test_document.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import pytest
1010

1111
from docx.opc.constants import RELATIONSHIP_TYPE as RT
12-
from docx.oxml.parts.document import CT_Body, CT_Document
13-
from docx.oxml.section import CT_SectPr
12+
from docx.oxml.parts.document import CT_Body
1413
from docx.oxml.text.run import CT_R
1514
from docx.package import ImageParts, Package
1615
from docx.parts.document import _Body, DocumentPart, InlineShapes, Sections
@@ -69,15 +68,6 @@ def it_provides_access_to_the_inline_shapes_in_the_document(
6968
InlineShapes_.assert_called_once_with(body_elm, document)
7069
assert inline_shapes is InlineShapes_.return_value
7170

72-
def it_can_add_a_section(self, add_section_fixture):
73-
(document_part, start_type_, body_elm_, new_sectPr_, Section_,
74-
section_) = add_section_fixture
75-
section = document_part.add_section(start_type_)
76-
body_elm_.add_section_break.assert_called_once_with()
77-
assert new_sectPr_.start_type == start_type_
78-
Section_.assert_called_once_with(new_sectPr_)
79-
assert section is section_
80-
8171
def it_can_add_a_table(self, add_table_fixture):
8272
document_part, rows, cols, body_, table_ = add_table_fixture
8373
table = document_part.add_table(rows, cols)
@@ -138,16 +128,6 @@ def it_creates_default_styles_part_if_not_present_to_help(
138128

139129
# fixtures -------------------------------------------------------
140130

141-
@pytest.fixture
142-
def add_section_fixture(
143-
self, document_elm_, start_type_, body_elm_, sectPr_, Section_,
144-
section_):
145-
document_part = DocumentPart(None, None, document_elm_, None)
146-
return (
147-
document_part, start_type_, body_elm_, sectPr_, Section_,
148-
section_
149-
)
150-
151131
@pytest.fixture
152132
def add_table_fixture(self, document_part_body_, body_, table_):
153133
document_part = DocumentPart(None, None, None, None)
@@ -255,16 +235,6 @@ def body_(self, request, p_, table_):
255235
body_.add_table.return_value = table_
256236
return body_
257237

258-
@pytest.fixture
259-
def body_elm_(self, request, sectPr_):
260-
body_elm_ = instance_mock(request, CT_Body)
261-
body_elm_.add_section_break.return_value = sectPr_
262-
return body_elm_
263-
264-
@pytest.fixture
265-
def document_elm_(self, request, body_elm_):
266-
return instance_mock(request, CT_Document, body=body_elm_)
267-
268238
@pytest.fixture
269239
def document_part_body_(self, request, body_):
270240
return property_mock(
@@ -326,28 +296,10 @@ def relate_to_(self, request, rId_):
326296
def rId_(self, request):
327297
return instance_mock(request, str)
328298

329-
@pytest.fixture
330-
def Section_(self, request, section_):
331-
return class_mock(
332-
request, 'docx.parts.document.Section', return_value=section_
333-
)
334-
335-
@pytest.fixture
336-
def section_(self, request):
337-
return instance_mock(request, Section)
338-
339299
@pytest.fixture
340300
def Sections_(self, request):
341301
return class_mock(request, 'docx.parts.document.Sections')
342302

343-
@pytest.fixture
344-
def sectPr_(self, request):
345-
return instance_mock(request, CT_SectPr)
346-
347-
@pytest.fixture
348-
def start_type_(self, request):
349-
return instance_mock(request, int)
350-
351303
@pytest.fixture
352304
def style_(self, request):
353305
return instance_mock(request, BaseStyle)

tests/test_api.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ def Package_(self, request):
8989

9090
class DescribeDocumentOld(object):
9191

92-
def it_can_add_a_section(self, add_section_fixture):
93-
document, start_type_, section_ = add_section_fixture
94-
section = document.add_section(start_type_)
95-
document._document_part.add_section.assert_called_once_with(
96-
start_type_
97-
)
98-
assert section is section_
99-
10092
def it_can_add_a_table(self, add_table_fixture):
10193
document, rows, cols, style, table_ = add_table_fixture
10294
table = document.add_table(rows, cols, style)
@@ -158,10 +150,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
158150

159151
# fixtures -------------------------------------------------------
160152

161-
@pytest.fixture
162-
def add_section_fixture(self, document, start_type_, section_):
163-
return document, start_type_, section_
164-
165153
@pytest.fixture
166154
def add_table_fixture(self, request, document, document_part_, table_):
167155
rows, cols = 4, 2
@@ -222,11 +210,10 @@ def document_obj_(self, request):
222210
return instance_mock(request, docx.document.Document)
223211

224212
@pytest.fixture
225-
def document_part_(self, request, paragraphs_, section_, table_, tables_):
213+
def document_part_(self, request, paragraphs_, table_, tables_):
226214
document_part_ = instance_mock(
227215
request, DocumentPart, content_type=CT.WML_DOCUMENT_MAIN
228216
)
229-
document_part_.add_section.return_value = section_
230217
document_part_.add_table.return_value = table_
231218
document_part_.paragraphs = paragraphs_
232219
document_part_.tables = tables_
@@ -285,10 +272,6 @@ def run_(self, request):
285272
def section_(self, request):
286273
return instance_mock(request, Section)
287274

288-
@pytest.fixture
289-
def start_type_(self, request):
290-
return instance_mock(request, int)
291-
292275
@pytest.fixture
293276
def styles_(self, request):
294277
return instance_mock(request, Styles)

0 commit comments

Comments
 (0)