Skip to content

Commit 7e22dc8

Browse files
apteryksSteve Canny
authored andcommitted
tbl: add _Columns.table
1 parent dc3e8e7 commit 7e22dc8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

docx/table.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ def __iter__(self):
344344
def __len__(self):
345345
return len(self._gridCol_lst)
346346

347+
@property
348+
def table(self):
349+
"""
350+
Reference to the |Table| object this column collection belongs to.
351+
"""
352+
return self._parent.table
353+
347354
@property
348355
def _gridCol_lst(self):
349356
"""

tests/test_table.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ def it_raises_on_indexed_access_out_of_range(self, columns_fixture):
523523
with pytest.raises(IndexError):
524524
columns[too_high]
525525

526+
def it_provides_access_to_the_table_it_belongs_to(self, table_fixture):
527+
columns, table_ = table_fixture
528+
assert columns.table is table_
529+
526530
# fixtures -------------------------------------------------------
527531

528532
@pytest.fixture
@@ -532,6 +536,18 @@ def columns_fixture(self):
532536
columns = _Columns(tbl, None)
533537
return columns, column_count
534538

539+
@pytest.fixture
540+
def table_fixture(self, table_):
541+
columns = _Columns(None, table_)
542+
table_.table = table_
543+
return columns, table_
544+
545+
# fixture components ---------------------------------------------
546+
547+
@pytest.fixture
548+
def table_(self, request):
549+
return instance_mock(request, Table)
550+
535551

536552
class Describe_Row(object):
537553

0 commit comments

Comments
 (0)