Skip to content

Commit bd16fc7

Browse files
author
Steve Canny
committed
api: remove old Document.add_table()
1 parent b00a46b commit bd16fc7

File tree

4 files changed

+4
-56
lines changed

4 files changed

+4
-56
lines changed

docx/api.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@ def add_section(self, start_type=WD_SECTION.NEW_PAGE):
6868
return self._document.add_section(start_type)
6969

7070
def add_table(self, rows, cols, style='Light Shading Accent 1'):
71-
"""
72-
Add a table having row and column counts of *rows* and *cols*
73-
respectively and table style of *style*. If *style* is |None|, a
74-
table with no style is produced.
75-
"""
76-
table = self._document_part.add_table(rows, cols)
77-
table.style = style
78-
return table
71+
return self._document.add_table(rows, cols, style)
7972

8073
@property
8174
def core_properties(self):

docx/parts/document.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ class DocumentPart(XmlPart):
2424
"""
2525
Main document part of a WordprocessingML (WML) package, aka a .docx file.
2626
"""
27-
def add_table(self, rows, cols):
28-
"""
29-
Return a table having *rows* rows and *cols* columns, newly appended
30-
to the main document story.
31-
"""
32-
return self.body.add_table(rows, cols)
33-
3427
@lazyproperty
3528
def body(self):
3629
"""

tests/parts/test_document.py

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

71-
def it_can_add_a_table(self, add_table_fixture):
72-
document_part, rows, cols, body_, table_ = add_table_fixture
73-
table = document_part.add_table(rows, cols)
74-
body_.add_table.assert_called_once_with(rows, cols)
75-
assert table is table_
76-
7771
def it_can_add_an_image_part_to_the_document(
7872
self, get_or_add_image_fixture):
7973
(document, image_descriptor_, image_parts_, relate_to_, image_part_,
@@ -128,12 +122,6 @@ def it_creates_default_styles_part_if_not_present_to_help(
128122

129123
# fixtures -------------------------------------------------------
130124

131-
@pytest.fixture
132-
def add_table_fixture(self, document_part_body_, body_, table_):
133-
document_part = DocumentPart(None, None, None, None)
134-
rows, cols = 2, 4
135-
return document_part, rows, cols, body_, table_
136-
137125
@pytest.fixture
138126
def body_fixture(self, _Body_):
139127
document_elm = (
@@ -229,11 +217,8 @@ def _Body_(self, request):
229217
return class_mock(request, 'docx.parts.document._Body')
230218

231219
@pytest.fixture
232-
def body_(self, request, p_, table_):
233-
body_ = instance_mock(request, _Body)
234-
body_.add_paragraph.return_value = p_
235-
body_.add_table.return_value = table_
236-
return body_
220+
def body_(self, request):
221+
return instance_mock(request, _Body)
237222

238223
@pytest.fixture
239224
def document_part_body_(self, request, body_):
@@ -326,10 +311,6 @@ def styles_prop_(self, request, styles_):
326311
def _styles_part_prop_(self, request):
327312
return property_mock(request, DocumentPart, '_styles_part')
328313

329-
@pytest.fixture
330-
def table_(self, request):
331-
return instance_mock(request, Table)
332-
333314
@pytest.fixture
334315
def tables_(self, request):
335316
return instance_mock(request, list)

tests/test_api.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from docx.parts.numbering import NumberingPart
2121
from docx.section import Section
2222
from docx.styles.styles import Styles
23-
from docx.table import Table
2423
from docx.text.run import Run
2524

2625
from .unitutil.mock import (
@@ -89,13 +88,6 @@ def Package_(self, request):
8988

9089
class DescribeDocumentOld(object):
9190

92-
def it_can_add_a_table(self, add_table_fixture):
93-
document, rows, cols, style, table_ = add_table_fixture
94-
table = document.add_table(rows, cols, style)
95-
document._document_part.add_table.assert_called_once_with(rows, cols)
96-
assert table.style == style
97-
assert table == table_
98-
9991
def it_provides_access_to_the_document_inline_shapes(self, document):
10092
body = document.inline_shapes
10193
assert body is document._document_part.inline_shapes
@@ -150,12 +142,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
150142

151143
# fixtures -------------------------------------------------------
152144

153-
@pytest.fixture
154-
def add_table_fixture(self, request, document, document_part_, table_):
155-
rows, cols = 4, 2
156-
style = 'Light Shading Accent 1'
157-
return document, rows, cols, style, table_
158-
159145
@pytest.fixture
160146
def core_props_fixture(self, document, core_properties_):
161147
document._package.core_properties = core_properties_
@@ -210,11 +196,10 @@ def document_obj_(self, request):
210196
return instance_mock(request, docx.document.Document)
211197

212198
@pytest.fixture
213-
def document_part_(self, request, paragraphs_, table_, tables_):
199+
def document_part_(self, request, paragraphs_, tables_):
214200
document_part_ = instance_mock(
215201
request, DocumentPart, content_type=CT.WML_DOCUMENT_MAIN
216202
)
217-
document_part_.add_table.return_value = table_
218203
document_part_.paragraphs = paragraphs_
219204
document_part_.tables = tables_
220205
return document_part_
@@ -276,10 +261,6 @@ def section_(self, request):
276261
def styles_(self, request):
277262
return instance_mock(request, Styles)
278263

279-
@pytest.fixture
280-
def table_(self, request):
281-
return instance_mock(request, Table, style=None)
282-
283264
@pytest.fixture
284265
def tables_(self, request):
285266
return instance_mock(request, list)

0 commit comments

Comments
 (0)