Skip to content

Commit 8e9f36a

Browse files
author
Steve Canny
committed
tbl: add _Row.cells
1 parent cdb413c commit 8e9f36a

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

docx/table.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class _CellCollection(object):
5252
"""
5353
Sequence of |_Cell| instances corresponding to the cells in a table row.
5454
"""
55+
def __init__(self, tr):
56+
super(_CellCollection, self).__init__()
57+
self._tr = tr
5558

5659

5760
class _Column(object):
@@ -71,6 +74,13 @@ def __init__(self, tr):
7174
super(_Row, self).__init__()
7275
self._tr = tr
7376

77+
@property
78+
def cells(self):
79+
"""
80+
Sequence of |_Cell| instances corresponding to the cells in this row.
81+
"""
82+
return _CellCollection(self._tr)
83+
7484

7585
class _RowCollection(object):
7686
"""

tests/test_table.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from docx.table import _Column, _Row, _RowCollection, Table
11+
from docx.table import _CellCollection, _Column, _Row, _RowCollection, Table
1212

1313
from .oxml.unitdata.table import a_gridCol, a_tbl, a_tblGrid, a_tc, a_tr
1414
from .oxml.unitdata.text import a_p
@@ -56,6 +56,22 @@ def row_access_fixture(self):
5656
return table
5757

5858

59+
class Describe_Row(object):
60+
61+
def it_provides_access_to_the_row_cells(self, cells_access_fixture):
62+
row = cells_access_fixture
63+
cells = row.cells
64+
assert isinstance(cells, _CellCollection)
65+
66+
# fixtures -------------------------------------------------------
67+
68+
@pytest.fixture
69+
def cells_access_fixture(self):
70+
tr = a_tr().with_nsdecls().element
71+
row = _Row(tr)
72+
return row
73+
74+
5975
class Describe_RowCollection(object):
6076

6177
def it_contains__Row_instances(self, row_count_fixture):

0 commit comments

Comments
 (0)