Skip to content

Commit 8a9fdfc

Browse files
author
Steve Canny
committed
tbl: remove now-dead code
1 parent 2fda570 commit 8a9fdfc

File tree

3 files changed

+4
-96
lines changed

3 files changed

+4
-96
lines changed

docx/table.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,8 @@ def __init__(self, gridCol, tbl, parent):
237237
self._gridCol = gridCol
238238
self._tbl = tbl
239239

240-
@lazyproperty
241-
def cells(self):
242-
"""
243-
Sequence of |_Cell| instances corresponding to cells in this column.
244-
Supports ``len()``, iteration and indexed access.
245-
"""
246-
return _ColumnCells(self._tbl, self._gridCol, self)
247-
248240
@property
249-
def cells_new(self):
241+
def cells(self):
250242
"""
251243
Sequence of |_Cell| instances corresponding to cells in this column.
252244
"""
@@ -279,46 +271,6 @@ def _index(self):
279271
return self._gridCol.gridCol_idx
280272

281273

282-
class _ColumnCells(Parented):
283-
"""
284-
Sequence of |_Cell| instances corresponding to the cells in a table
285-
column.
286-
"""
287-
def __init__(self, tbl, gridCol, parent):
288-
super(_ColumnCells, self).__init__(parent)
289-
self._tbl = tbl
290-
self._gridCol = gridCol
291-
292-
def __getitem__(self, idx):
293-
"""
294-
Provide indexed access, (e.g. 'cells[0]')
295-
"""
296-
try:
297-
tr = self._tr_lst[idx]
298-
except IndexError:
299-
msg = "cell index [%d] is out of range" % idx
300-
raise IndexError(msg)
301-
tc = tr.tc_lst[self._col_idx]
302-
return _Cell(tc, self)
303-
304-
def __iter__(self):
305-
for tr in self._tr_lst:
306-
tc = tr.tc_lst[self._col_idx]
307-
yield _Cell(tc, self)
308-
309-
def __len__(self):
310-
return len(self._tr_lst)
311-
312-
@property
313-
def _col_idx(self):
314-
gridCol_lst = self._tbl.tblGrid.gridCol_lst
315-
return gridCol_lst.index(self._gridCol)
316-
317-
@property
318-
def _tr_lst(self):
319-
return self._tbl.tr_lst
320-
321-
322274
class _Columns(Parented):
323275
"""
324276
Sequence of |_Column| instances corresponding to the columns in a table.

features/steps/table.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ def then_table_cell_row_col_text_is_text(context, row, col, expected_text):
216216
@then('the column cells text is {expected_text}')
217217
def then_the_column_cells_text_is_expected_text(context, expected_text):
218218
table = context.table_
219-
cells_text = ' '.join(
220-
c.text for col in table.columns for c in col.cells_new
221-
)
219+
cells_text = ' '.join(c.text for col in table.columns for c in col.cells)
222220
assert cells_text == expected_text, 'got %s' % cells_text
223221

224222

tests/test_table.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
from docx.oxml import parse_xml
1212
from docx.shared import Inches
13-
from docx.table import (
14-
_Cell, _Column, _ColumnCells, _Columns, _Row, _Rows, Table
15-
)
13+
from docx.table import _Cell, _Column, _Columns, _Row, _Rows, Table
1614
from docx.text import Paragraph
1715

1816
from .oxml.unitdata.table import a_gridCol, a_tbl, a_tblGrid, a_tc, a_tr
@@ -390,7 +388,7 @@ class Describe_Column(object):
390388

391389
def it_provides_access_to_its_cells(self, cells_fixture):
392390
column, column_idx, expected_cells = cells_fixture
393-
cells = column.cells_new
391+
cells = column.cells
394392
column.table.column_cells.assert_called_once_with(column_idx)
395393
assert cells == expected_cells
396394

@@ -479,46 +477,6 @@ def table_prop_(self, request, table_):
479477
return property_mock(request, _Column, 'table', return_value=table_)
480478

481479

482-
class Describe_ColumnCells(object):
483-
484-
def it_knows_how_many_cells_it_contains(self, cells_fixture):
485-
cells, cell_count = cells_fixture
486-
assert len(cells) == cell_count
487-
488-
def it_can_iterate_over_its__Cell_instances(self, cells_fixture):
489-
cells, cell_count = cells_fixture
490-
actual_count = 0
491-
for cell in cells:
492-
assert isinstance(cell, _Cell)
493-
actual_count += 1
494-
assert actual_count == cell_count
495-
496-
def it_provides_indexed_access_to_cells(self, cells_fixture):
497-
cells, cell_count = cells_fixture
498-
for idx in range(-cell_count, cell_count):
499-
cell = cells[idx]
500-
assert isinstance(cell, _Cell)
501-
502-
def it_raises_on_indexed_access_out_of_range(self, cells_fixture):
503-
cells, cell_count = cells_fixture
504-
too_low = -1 - cell_count
505-
too_high = cell_count
506-
with pytest.raises(IndexError):
507-
cells[too_low]
508-
with pytest.raises(IndexError):
509-
cells[too_high]
510-
511-
# fixtures -------------------------------------------------------
512-
513-
@pytest.fixture
514-
def cells_fixture(self):
515-
cell_count = 2
516-
tbl = _tbl_bldr(rows=cell_count, cols=1).element
517-
gridCol = tbl.tblGrid.gridCol_lst[0]
518-
cells = _ColumnCells(tbl, gridCol, None)
519-
return cells, cell_count
520-
521-
522480
class Describe_Columns(object):
523481

524482
def it_knows_how_many_columns_it_contains(self, columns_fixture):

0 commit comments

Comments
 (0)