Skip to content

Commit 99c713f

Browse files
author
Steve Canny
committed
api: remove old Document.add_page_break()
1 parent aaae2e6 commit 99c713f

File tree

4 files changed

+2
-51
lines changed

4 files changed

+2
-51
lines changed

docx/api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import os
1212

1313
from docx.enum.section import WD_SECTION
14-
from docx.enum.text import WD_BREAK
1514
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
1615
from docx.package import Package
1716
from docx.parts.numbering import NumberingPart
@@ -57,14 +56,7 @@ def add_heading(self, text='', level=1):
5756
return self._document.add_heading(text, level)
5857

5958
def add_page_break(self):
60-
"""
61-
Return a paragraph newly added to the end of the document and
62-
containing only a page break.
63-
"""
64-
p = self._document_part.add_paragraph()
65-
r = p.add_run()
66-
r.add_break(WD_BREAK.PAGE)
67-
return p
59+
return self._document.add_page_break()
6860

6961
def add_paragraph(self, text='', style=None):
7062
return self._document.add_paragraph(text, style)

docx/parts/document.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ class DocumentPart(XmlPart):
2525
"""
2626
Main document part of a WordprocessingML (WML) package, aka a .docx file.
2727
"""
28-
def add_paragraph(self, text='', style=None):
29-
"""
30-
Return a paragraph newly added to the end of body content.
31-
"""
32-
return self.body.add_paragraph(text, style)
33-
3428
def add_section(self, start_type=WD_SECTION.NEW_PAGE):
3529
"""
3630
Return a |Section| object representing a new section added at the end

tests/parts/test_document.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ def it_provides_access_to_the_inline_shapes_in_the_document(
6969
InlineShapes_.assert_called_once_with(body_elm, document)
7070
assert inline_shapes is InlineShapes_.return_value
7171

72-
def it_can_add_a_paragraph(self, add_paragraph_fixture):
73-
document_part, body_, p_ = add_paragraph_fixture
74-
p = document_part.add_paragraph()
75-
body_.add_paragraph.assert_called_once_with('', None)
76-
assert p is p_
77-
7872
def it_can_add_a_section(self, add_section_fixture):
7973
(document_part, start_type_, body_elm_, new_sectPr_, Section_,
8074
section_) = add_section_fixture
@@ -144,11 +138,6 @@ def it_creates_default_styles_part_if_not_present_to_help(
144138

145139
# fixtures -------------------------------------------------------
146140

147-
@pytest.fixture
148-
def add_paragraph_fixture(self, document_part_body_, body_, p_):
149-
document_part = DocumentPart(None, None, None, None)
150-
return document_part, body_, p_
151-
152141
@pytest.fixture
153142
def add_section_fixture(
154143
self, document_elm_, start_type_, body_elm_, sectPr_, Section_,

tests/test_api.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import docx
1414

1515
from docx.api import Document, DocumentNew
16-
from docx.enum.text import WD_BREAK
1716
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
1817
from docx.opc.coreprops import CoreProperties
1918
from docx.package import Package
@@ -23,7 +22,6 @@
2322
from docx.shape import InlineShape
2423
from docx.styles.styles import Styles
2524
from docx.table import Table
26-
from docx.text.paragraph import Paragraph
2725
from docx.text.run import Run
2826

2927
from .unitutil.mock import (
@@ -92,14 +90,6 @@ def Package_(self, request):
9290

9391
class DescribeDocumentOld(object):
9492

95-
def it_can_add_a_page_break(self, add_page_break_fixture):
96-
document, document_part_, paragraph_, run_ = add_page_break_fixture
97-
paragraph = document.add_page_break()
98-
document_part_.add_paragraph.assert_called_once_with()
99-
paragraph_.add_run.assert_called_once_with()
100-
run_.add_break.assert_called_once_with(WD_BREAK.PAGE)
101-
assert paragraph is paragraph_
102-
10393
def it_can_add_a_picture(self, add_picture_fixture):
10494
document, image_path_, width, height, run_, picture_ = (
10595
add_picture_fixture
@@ -177,11 +167,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
177167

178168
# fixtures -------------------------------------------------------
179169

180-
@pytest.fixture
181-
def add_page_break_fixture(
182-
self, document, document_part_, paragraph_, run_):
183-
return document, document_part_, paragraph_, run_
184-
185170
@pytest.fixture
186171
def add_picture_fixture(self, request, run_, picture_):
187172
document = Document()
@@ -255,13 +240,10 @@ def document_obj_(self, request):
255240
return instance_mock(request, docx.document.Document)
256241

257242
@pytest.fixture
258-
def document_part_(
259-
self, request, paragraph_, paragraphs_, section_, table_,
260-
tables_):
243+
def document_part_(self, request, paragraphs_, section_, table_, tables_):
261244
document_part_ = instance_mock(
262245
request, DocumentPart, content_type=CT.WML_DOCUMENT_MAIN
263246
)
264-
document_part_.add_paragraph.return_value = paragraph_
265247
document_part_.add_section.return_value = section_
266248
document_part_.add_table.return_value = table_
267249
document_part_.paragraphs = paragraphs_
@@ -309,12 +291,6 @@ def package_(self, request, document_part_):
309291
package_.main_document_part = document_part_
310292
return package_
311293

312-
@pytest.fixture
313-
def paragraph_(self, request, run_):
314-
paragraph_ = instance_mock(request, Paragraph)
315-
paragraph_.add_run.return_value = run_
316-
return paragraph_
317-
318294
@pytest.fixture
319295
def paragraphs_(self, request):
320296
return instance_mock(request, list)

0 commit comments

Comments
 (0)