88
99import pytest
1010
11- from docx .table import _Column , _Row , Table
11+ from docx .table import _Column , _Row , _RowCollection , Table
1212
1313from .oxml .unitdata .table import a_gridCol , a_tbl , a_tblGrid , a_tc , a_tr
1414from .oxml .unitdata .text import a_p
1515
1616
1717class DescribeTable (object ):
1818
19+ def it_provides_access_to_the_table_rows (self , row_access_fixture ):
20+ table = row_access_fixture
21+ rows = table .rows
22+ assert isinstance (rows , _RowCollection )
23+
1924 def it_can_add_a_column (self , add_column_fixture ):
2025 table , expected_xml = add_column_fixture
2126 col = table .add_column ()
@@ -32,34 +37,45 @@ def it_can_add_a_row(self, add_row_fixture):
3237
3338 @pytest .fixture
3439 def add_column_fixture (self ):
35- tbl = self . _tbl_bldr (2 , 1 ).element
40+ tbl = _tbl_bldr (2 , 1 ).element
3641 table = Table (tbl )
37- expected_xml = self . _tbl_bldr (2 , 2 ).xml ()
42+ expected_xml = _tbl_bldr (2 , 2 ).xml ()
3843 return table , expected_xml
3944
4045 @pytest .fixture
4146 def add_row_fixture (self ):
42- tbl = self . _tbl_bldr (rows = 1 , cols = 2 ).element
47+ tbl = _tbl_bldr (rows = 1 , cols = 2 ).element
4348 table = Table (tbl )
44- expected_xml = self . _tbl_bldr (rows = 2 , cols = 2 ).xml ()
49+ expected_xml = _tbl_bldr (rows = 2 , cols = 2 ).xml ()
4550 return table , expected_xml
4651
47- def _tbl_bldr (self , rows , cols ):
48- tblGrid_bldr = a_tblGrid ()
49- for i in range (cols ):
50- tblGrid_bldr .with_child (a_gridCol ())
51- tbl_bldr = a_tbl ().with_nsdecls ().with_child (tblGrid_bldr )
52- for i in range (rows ):
53- tr_bldr = self ._tr_bldr (cols )
54- tbl_bldr .with_child (tr_bldr )
55- return tbl_bldr
56-
57- def _tc_bldr (self ):
58- return a_tc ().with_child (a_p ())
59-
60- def _tr_bldr (self , cols ):
61- tr_bldr = a_tr ()
62- for i in range (cols ):
63- tc_bldr = self ._tc_bldr ()
64- tr_bldr .with_child (tc_bldr )
65- return tr_bldr
52+ @pytest .fixture
53+ def row_access_fixture (self ):
54+ tbl = _tbl_bldr (rows = 2 , cols = 2 ).element
55+ table = Table (tbl )
56+ return table
57+
58+
59+ # fixtures -----------------------------------------------------------
60+
61+ def _tbl_bldr (rows , cols ):
62+ tblGrid_bldr = a_tblGrid ()
63+ for i in range (cols ):
64+ tblGrid_bldr .with_child (a_gridCol ())
65+ tbl_bldr = a_tbl ().with_nsdecls ().with_child (tblGrid_bldr )
66+ for i in range (rows ):
67+ tr_bldr = _tr_bldr (cols )
68+ tbl_bldr .with_child (tr_bldr )
69+ return tbl_bldr
70+
71+
72+ def _tc_bldr ():
73+ return a_tc ().with_child (a_p ())
74+
75+
76+ def _tr_bldr (cols ):
77+ tr_bldr = a_tr ()
78+ for i in range (cols ):
79+ tc_bldr = _tc_bldr ()
80+ tr_bldr .with_child (tc_bldr )
81+ return tr_bldr
0 commit comments