Skip to content

Commit f0ade55

Browse files
author
Steve Canny
committed
tbl: add _Rows.table
1 parent acf76f4 commit f0ade55

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
@@ -386,3 +386,10 @@ def __iter__(self):
386386

387387
def __len__(self):
388388
return len(self._tbl.tr_lst)
389+
390+
@property
391+
def table(self):
392+
"""
393+
Reference to the |Table| object this row collection belongs to.
394+
"""
395+
return self._parent.table

tests/test_table.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ def it_raises_on_indexed_access_out_of_range(self, rows_fixture):
547547
too_high = row_count
548548
rows[too_high]
549549

550+
def it_provides_access_to_the_table_it_belongs_to(self, table_fixture):
551+
rows, table_ = table_fixture
552+
assert rows.table is table_
553+
550554
# fixtures -------------------------------------------------------
551555

552556
@pytest.fixture
@@ -556,6 +560,18 @@ def rows_fixture(self):
556560
rows = _Rows(tbl, None)
557561
return rows, row_count
558562

563+
@pytest.fixture
564+
def table_fixture(self, table_):
565+
rows = _Rows(None, table_)
566+
table_.table = table_
567+
return rows, table_
568+
569+
# fixture components ---------------------------------------------
570+
571+
@pytest.fixture
572+
def table_(self, request):
573+
return instance_mock(request, Table)
574+
559575

560576
# fixtures -----------------------------------------------------------
561577

0 commit comments

Comments
 (0)