Skip to content

Commit dc3e8e7

Browse files
apteryksSteve Canny
authored andcommitted
tbl: add _Column.table
1 parent cbc2d60 commit dc3e8e7

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

docx/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def table(self):
255255
"""
256256
Reference to the |Table| object this column belongs to.
257257
"""
258-
raise NotImplementedError
258+
return self._parent.table
259259

260260
@property
261261
def width(self):

tests/test_table.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ def it_provides_access_to_its_cells(self, cells_fixture):
380380
column.table.column_cells.assert_called_once_with(column_idx)
381381
assert cells == expected_cells
382382

383+
def it_provides_access_to_the_table_it_belongs_to(self, table_fixture):
384+
column, table_ = table_fixture
385+
assert column.table is table_
386+
383387
def it_knows_its_width_in_EMU(self, width_get_fixture):
384388
column, expected_width = width_get_fixture
385389
assert column.width == expected_width
@@ -400,6 +404,12 @@ def cells_fixture(self, _index_, table_prop_, table_):
400404
table_.column_cells.return_value = list(expected_cells)
401405
return column, column_idx, expected_cells
402406

407+
@pytest.fixture
408+
def table_fixture(self, parent_, table_):
409+
column = _Column(None, None, parent_)
410+
parent_.table = table_
411+
return column, table_
412+
403413
@pytest.fixture(params=[
404414
('w:gridCol{w:w=4242}', 2693670),
405415
('w:gridCol{w:w=1440}', 914400),
@@ -431,6 +441,10 @@ def width_set_fixture(self, request):
431441
def _index_(self, request):
432442
return property_mock(request, _Column, '_index')
433443

444+
@pytest.fixture
445+
def parent_(self, request):
446+
return instance_mock(request, Table)
447+
434448
@pytest.fixture
435449
def table_(self, request):
436450
return instance_mock(request, Table)

0 commit comments

Comments
 (0)