Skip to content

Commit ba3c757

Browse files
author
Steve Canny
committed
tbl: remove now-dead code
* remove _RowCells and tests * make _Row.cells_new _Row.cells and remove prior version
1 parent 22752a9 commit ba3c757

File tree

3 files changed

+4
-81
lines changed

3 files changed

+4
-81
lines changed

docx/table.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,8 @@ def __init__(self, tr, parent):
335335
super(_Row, self).__init__(parent)
336336
self._tr = tr
337337

338-
@lazyproperty
339-
def cells(self):
340-
"""
341-
Sequence of |_Cell| instances corresponding to cells in this row.
342-
Supports ``len()``, iteration and indexed access.
343-
"""
344-
return _RowCells(self._tr, self)
345-
346338
@property
347-
def cells_new(self):
339+
def cells(self):
348340
"""
349341
Sequence of |_Cell| instances corresponding to cells in this row.
350342
"""
@@ -365,32 +357,6 @@ def _index(self):
365357
return self._tr.tr_idx
366358

367359

368-
class _RowCells(Parented):
369-
"""
370-
Sequence of |_Cell| instances corresponding to the cells in a table row.
371-
"""
372-
def __init__(self, tr, parent):
373-
super(_RowCells, self).__init__(parent)
374-
self._tr = tr
375-
376-
def __getitem__(self, idx):
377-
"""
378-
Provide indexed access, (e.g. 'cells[0]')
379-
"""
380-
try:
381-
tc = self._tr.tc_lst[idx]
382-
except IndexError:
383-
msg = "cell index [%d] is out of range" % idx
384-
raise IndexError(msg)
385-
return _Cell(tc, self)
386-
387-
def __iter__(self):
388-
return (_Cell(tc, self) for tc in self._tr.tc_lst)
389-
390-
def __len__(self):
391-
return len(self._tr.tc_lst)
392-
393-
394360
class _Rows(Parented):
395361
"""
396362
Sequence of |_Row| instances corresponding to the rows in a table.

features/steps/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def then_the_reported_width_of_the_cell_is_width(context, width):
269269
@then('the row cells text is {expected_text}')
270270
def then_the_row_cells_text_is_expected_text(context, expected_text):
271271
table = context.table_
272-
cells_text = ' '.join(c.text for row in table.rows for c in row.cells_new)
272+
cells_text = ' '.join(c.text for row in table.rows for c in row.cells)
273273
assert cells_text == expected_text, 'got %s' % cells_text
274274

275275

tests/test_table.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from docx.oxml import parse_xml
1212
from docx.shared import Inches
1313
from docx.table import (
14-
_Cell, _Column, _ColumnCells, _Columns, _Row, _RowCells, _Rows, Table
14+
_Cell, _Column, _ColumnCells, _Columns, _Row, _Rows, Table
1515
)
1616
from docx.text import Paragraph
1717

@@ -500,15 +500,10 @@ class Describe_Row(object):
500500

501501
def it_provides_access_to_its_cells(self, cells_fixture):
502502
row, row_idx, expected_cells = cells_fixture
503-
cells = row.cells_new
503+
cells = row.cells
504504
row.table.row_cells.assert_called_once_with(row_idx)
505505
assert cells == expected_cells
506506

507-
def it_provides_access_to_the_row_cells(self):
508-
row = _Row(element('w:tr'), None)
509-
cells = row.cells
510-
assert isinstance(cells, _RowCells)
511-
512507
def it_provides_access_to_the_table_it_belongs_to(self, table_fixture):
513508
row, table_ = table_fixture
514509
assert row.table is table_
@@ -559,44 +554,6 @@ def table_prop_(self, request, table_):
559554
return property_mock(request, _Row, 'table', return_value=table_)
560555

561556

562-
class Describe_RowCells(object):
563-
564-
def it_knows_how_many_cells_it_contains(self, cell_count_fixture):
565-
cells, cell_count = cell_count_fixture
566-
assert len(cells) == cell_count
567-
568-
def it_can_iterate_over_its__Cell_instances(self, cell_count_fixture):
569-
cells, cell_count = cell_count_fixture
570-
actual_count = 0
571-
for cell in cells:
572-
assert isinstance(cell, _Cell)
573-
actual_count += 1
574-
assert actual_count == cell_count
575-
576-
def it_provides_indexed_access_to_cells(self, cell_count_fixture):
577-
cells, cell_count = cell_count_fixture
578-
for idx in range(-cell_count, cell_count):
579-
cell = cells[idx]
580-
assert isinstance(cell, _Cell)
581-
582-
def it_raises_on_indexed_access_out_of_range(self, cell_count_fixture):
583-
cells, cell_count = cell_count_fixture
584-
too_low = -1 - cell_count
585-
too_high = cell_count
586-
with pytest.raises(IndexError):
587-
cells[too_low]
588-
with pytest.raises(IndexError):
589-
cells[too_high]
590-
591-
# fixtures -------------------------------------------------------
592-
593-
@pytest.fixture
594-
def cell_count_fixture(self):
595-
cells = _RowCells(element('w:tr/(w:tc, w:tc)'), None)
596-
cell_count = 2
597-
return cells, cell_count
598-
599-
600557
class Describe_Rows(object):
601558

602559
def it_knows_how_many_rows_it_contains(self, rows_fixture):

0 commit comments

Comments
 (0)