88
99import pytest
1010
11+ from docx .enum .style import WD_STYLE_TYPE
1112from docx .enum .table import WD_TABLE_ALIGNMENT
1213from docx .oxml import parse_xml
1314from docx .oxml .table import CT_Tc
15+ from docx .parts .document import DocumentPart
1416from docx .shared import Inches
1517from docx .table import _Cell , _Column , _Columns , _Row , _Rows , Table
1618from docx .text .paragraph import Paragraph
@@ -42,9 +44,13 @@ def it_can_change_its_autofit_setting(self, autofit_set_fixture):
4244 table .autofit = new_value
4345 assert table ._tbl .xml == expected_xml
4446
45- def it_knows_its_table_style (self , table_style_get_fixture ):
46- table , style = table_style_get_fixture
47- assert table .style == style
47+ def it_knows_its_table_style (self , style_get_fixture ):
48+ table , style_id_ , style_ = style_get_fixture
49+ style = table .style
50+ table .part .get_style .assert_called_once_with (
51+ style_id_ , WD_STYLE_TYPE .TABLE
52+ )
53+ assert style is style_
4854
4955 def it_can_apply_a_table_style_by_name (self , table_style_set_fixture ):
5056 table , style_name , expected_xml = table_style_set_fixture
@@ -219,20 +225,19 @@ def row_cells_fixture(self, _cells_, _column_count_):
219225 expected_cells = [3 , 4 , 5 ]
220226 return table , row_idx , expected_cells
221227
228+ @pytest .fixture
229+ def style_get_fixture (self , part_prop_ ):
230+ style_id = 'Barbaz'
231+ tbl_cxml = 'w:tbl/w:tblPr/w:tblStyle{w:val=%s}' % style_id
232+ table = Table (element (tbl_cxml ), None )
233+ style_ = part_prop_ .return_value .get_style .return_value
234+ return table , style_id , style_
235+
222236 @pytest .fixture
223237 def table_fixture (self ):
224238 table = Table (None , None )
225239 return table
226240
227- @pytest .fixture (params = [
228- ('w:tbl/w:tblPr' , None ),
229- ('w:tbl/w:tblPr/w:tblStyle{w:val=foobar}' , 'foobar' ),
230- ])
231- def table_style_get_fixture (self , request ):
232- tbl_cxml , expected_style = request .param
233- table = Table (element (tbl_cxml ), None )
234- return table , expected_style
235-
236241 @pytest .fixture (params = [
237242 ('w:tbl/w:tblPr' , 'foobar' ,
238243 'w:tbl/w:tblPr/w:tblStyle{w:val=foobar}' ),
@@ -259,6 +264,16 @@ def _cells_(self, request):
259264 def _column_count_ (self , request ):
260265 return property_mock (request , Table , '_column_count' )
261266
267+ @pytest .fixture
268+ def document_part_ (self , request ):
269+ return instance_mock (request , DocumentPart )
270+
271+ @pytest .fixture
272+ def part_prop_ (self , request , document_part_ ):
273+ return property_mock (
274+ request , Table , 'part' , return_value = document_part_
275+ )
276+
262277 @pytest .fixture
263278 def table (self ):
264279 tbl = _tbl_bldr (rows = 2 , cols = 2 ).element
0 commit comments