Skip to content

Commit 8f7f4fa

Browse files
author
Steve Canny
committed
doc: add Document.tables
1 parent a9608c8 commit 8f7f4fa

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

docx/document.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ def styles(self):
154154
"""
155155
return self._part.styles
156156

157+
@property
158+
def tables(self):
159+
"""
160+
A list of |Table| instances corresponding to the tables in the
161+
document, in document order. Note that only tables appearing at the
162+
top level of the document appear in this list; a table nested inside
163+
a table cell does not appear. A table within revision marks such as
164+
``<w:ins>`` or ``<w:del>`` will also not appear in the list.
165+
"""
166+
return self._body.tables
167+
157168
@property
158169
def _body(self):
159170
"""

tests/test_document.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def it_provides_access_to_its_styles(self, styles_fixture):
110110
document, styles_ = styles_fixture
111111
assert document.styles is styles_
112112

113+
def it_provides_access_to_its_tables(self, tables_fixture):
114+
document, tables_ = tables_fixture
115+
tables = document.tables
116+
assert tables is tables_
117+
113118
def it_provides_access_to_the_document_part(self, part_fixture):
114119
document, part_ = part_fixture
115120
assert document.part is part_
@@ -236,6 +241,12 @@ def styles_fixture(self, document_part_, styles_):
236241
document_part_.styles = styles_
237242
return document, styles_
238243

244+
@pytest.fixture
245+
def tables_fixture(self, body_prop_, tables_):
246+
document = Document(None, None)
247+
body_prop_.return_value.tables = tables_
248+
return document, tables_
249+
239250
# fixture components ---------------------------------------------
240251

241252
@pytest.fixture
@@ -301,3 +312,7 @@ def styles_(self, request):
301312
@pytest.fixture
302313
def table_(self, request):
303314
return instance_mock(request, Table, style='UNASSIGNED')
315+
316+
@pytest.fixture
317+
def tables_(self, request):
318+
return instance_mock(request, list)

0 commit comments

Comments
 (0)