Skip to content

Commit 3a9523a

Browse files
author
Steve Canny
committed
api: remove old Document.add_heading()
1 parent 1d19d45 commit 3a9523a

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

docx/api.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,7 @@ def __init__(self, docx=None):
5454
self._package = document._part.package
5555

5656
def add_heading(self, text='', level=1):
57-
"""
58-
Return a heading paragraph newly added to the end of the document,
59-
containing *text* and having its paragraph style determined by
60-
*level*. If *level* is 0, the style is set to `Title`. If *level* is
61-
1 (or omitted), `Heading 1` is used. Otherwise the style is set to
62-
`Heading {level}`. Raises |ValueError| if *level* is outside the
63-
range 0-9.
64-
"""
65-
if not 0 <= level <= 9:
66-
raise ValueError("level must be in range 0-9, got %d" % level)
67-
style = 'Title' if level == 0 else 'Heading %d' % level
68-
return self.add_paragraph(text, style)
57+
return self._document.add_heading(text, level)
6958

7059
def add_page_break(self):
7160
"""

tests/test_api.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from docx.text.run import Run
2828

2929
from .unitutil.mock import (
30-
function_mock, instance_mock, class_mock, method_mock, property_mock
30+
function_mock, instance_mock, class_mock, property_mock
3131
)
3232

3333

@@ -92,18 +92,6 @@ def Package_(self, request):
9292

9393
class DescribeDocumentOld(object):
9494

95-
def it_can_add_a_heading(self, add_heading_fixture):
96-
document, text, level, style, paragraph_ = add_heading_fixture
97-
paragraph = document.add_heading(text, level)
98-
document.add_paragraph.assert_called_once_with(text, style)
99-
assert paragraph is paragraph_
100-
101-
def it_should_raise_on_heading_level_out_of_range(self, document):
102-
with pytest.raises(ValueError):
103-
document.add_heading(level=-1)
104-
with pytest.raises(ValueError):
105-
document.add_heading(level=10)
106-
10795
def it_can_add_a_page_break(self, add_page_break_fixture):
10896
document, document_part_, paragraph_, run_ = add_page_break_fixture
10997
paragraph = document.add_page_break()
@@ -189,18 +177,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
189177

190178
# fixtures -------------------------------------------------------
191179

192-
@pytest.fixture(params=[
193-
(0, 'Title'),
194-
(1, 'Heading 1'),
195-
(2, 'Heading 2'),
196-
(9, 'Heading 9'),
197-
])
198-
def add_heading_fixture(self, request, document, add_paragraph_,
199-
paragraph_):
200-
level, style = request.param
201-
text = 'Spam vs. Bacon'
202-
return document, text, level, style, paragraph_
203-
204180
@pytest.fixture
205181
def add_page_break_fixture(
206182
self, document, document_part_, paragraph_, run_):
@@ -260,12 +236,6 @@ def tables_fixture(self, document, tables_):
260236

261237
# fixture components ---------------------------------------------
262238

263-
@pytest.fixture
264-
def add_paragraph_(self, request, paragraph_):
265-
return method_mock(
266-
request, Document, 'add_paragraph', return_value=paragraph_
267-
)
268-
269239
@pytest.fixture
270240
def core_properties_(self, request):
271241
return instance_mock(request, CoreProperties)

0 commit comments

Comments
 (0)