def add_column_fixture(self): snippets = snippet_seq('add-row-col') tbl = parse_xml(snippets[0]) table = Table(tbl, None) width = Inches(1.5) expected_xml = snippets[2] return table, width, expected_xml
def default_cx(self): """ Native width of this image, calculated from its width in pixels and horizontal dots per inch (dpi). """ px_width = self.image.px_width horz_dpi = self.image.horz_dpi width_in_inches = px_width / horz_dpi return Inches(width_in_inches)
def add_table(self, rows, cols): """ Return a table newly added to this cell after any existing cell content, having *rows* rows and *cols* columns. An empty paragraph is added after the table because Word requires a paragraph element as the last element in every cell. """ width = self.width if self.width is not None else Inches(1) table = super(_Cell, self).add_table(rows, cols, width) self.add_paragraph() return table
class DescribeSection(object): def it_knows_when_it_displays_a_distinct_first_page_header( self, diff_first_header_get_fixture): sectPr, expected_value = diff_first_header_get_fixture section = Section(sectPr, None) different_first_page_header_footer = section.different_first_page_header_footer assert different_first_page_header_footer is expected_value def it_can_change_whether_the_document_has_distinct_odd_and_even_headers( self, diff_first_header_set_fixture): sectPr, value, expected_xml = diff_first_header_set_fixture section = Section(sectPr, None) section.different_first_page_header_footer = value assert sectPr.xml == expected_xml def it_provides_access_to_its_even_page_footer(self, document_part_, _Footer_, footer_): sectPr = element('w:sectPr') _Footer_.return_value = footer_ section = Section(sectPr, document_part_) footer = section.even_page_footer _Footer_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.EVEN_PAGE) assert footer is footer_ def it_provides_access_to_its_even_page_header(self, document_part_, _Header_, header_): sectPr = element("w:sectPr") _Header_.return_value = header_ section = Section(sectPr, document_part_) header = section.even_page_header _Header_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.EVEN_PAGE) assert header is header_ def it_provides_access_to_its_first_page_footer(self, document_part_, _Footer_, footer_): sectPr = element("w:sectPr") _Footer_.return_value = footer_ section = Section(sectPr, document_part_) footer = section.first_page_footer _Footer_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.FIRST_PAGE) assert footer is footer_ def it_provides_access_to_its_first_page_header(self, document_part_, _Header_, header_): sectPr = element("w:sectPr") _Header_.return_value = header_ section = Section(sectPr, document_part_) header = section.first_page_header _Header_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.FIRST_PAGE) assert header is header_ def it_provides_access_to_its_default_footer(self, document_part_, _Footer_, footer_): sectPr = element('w:sectPr') _Footer_.return_value = footer_ section = Section(sectPr, document_part_) footer = section.footer _Footer_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY) assert footer is footer_ def it_provides_access_to_its_default_header(self, document_part_, _Header_, header_): sectPr = element('w:sectPr') _Header_.return_value = header_ section = Section(sectPr, document_part_) header = section.header _Header_.assert_called_once_with(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY) assert header is header_ def it_knows_its_start_type(self, start_type_get_fixture): sectPr, expected_start_type = start_type_get_fixture section = Section(sectPr, None) start_type = section.start_type assert start_type is expected_start_type def it_can_change_its_start_type(self, start_type_set_fixture): sectPr, new_start_type, expected_xml = start_type_set_fixture section = Section(sectPr, None) section.start_type = new_start_type assert section._sectPr.xml == expected_xml def it_knows_its_page_width(self, page_width_get_fixture): sectPr, expected_page_width = page_width_get_fixture section = Section(sectPr, None) page_width = section.page_width assert page_width == expected_page_width def it_can_change_its_page_width(self, page_width_set_fixture): sectPr, new_page_width, expected_xml = page_width_set_fixture section = Section(sectPr, None) section.page_width = new_page_width assert section._sectPr.xml == expected_xml def it_knows_its_page_height(self, page_height_get_fixture): sectPr, expected_page_height = page_height_get_fixture section = Section(sectPr, None) page_height = section.page_height assert page_height == expected_page_height def it_can_change_its_page_height(self, page_height_set_fixture): sectPr, new_page_height, expected_xml = page_height_set_fixture section = Section(sectPr, None) section.page_height = new_page_height assert section._sectPr.xml == expected_xml def it_knows_its_page_orientation(self, orientation_get_fixture): sectPr, expected_orientation = orientation_get_fixture section = Section(sectPr, None) orientation = section.orientation assert orientation is expected_orientation def it_can_change_its_orientation(self, orientation_set_fixture): sectPr, new_orientation, expected_xml = orientation_set_fixture section = Section(sectPr, None) section.orientation = new_orientation assert section._sectPr.xml == expected_xml def it_knows_its_page_margins(self, margins_get_fixture): sectPr, margin_prop_name, expected_value = margins_get_fixture section = Section(sectPr, None) value = getattr(section, margin_prop_name) assert value == expected_value def it_can_change_its_page_margins(self, margins_set_fixture): sectPr, margin_prop_name, new_value, expected_xml = margins_set_fixture section = Section(sectPr, None) setattr(section, margin_prop_name, new_value) assert section._sectPr.xml == expected_xml # fixtures ------------------------------------------------------- @pytest.fixture(params=[ ("w:sectPr", False), ("w:sectPr/w:titlePg", True), ("w:sectPr/w:titlePg{w:val=0}", False), ("w:sectPr/w:titlePg{w:val=1}", True), ("w:sectPr/w:titlePg{w:val=true}", True), ]) def diff_first_header_get_fixture(self, request): sectPr_cxml, expected_value = request.param sectPr = element(sectPr_cxml) return sectPr, expected_value @pytest.fixture(params=[ ("w:sectPr", True, "w:sectPr/w:titlePg"), ("w:sectPr/w:titlePg", False, "w:sectPr"), ("w:sectPr/w:titlePg{w:val=1}", True, "w:sectPr/w:titlePg"), ("w:sectPr/w:titlePg{w:val=off}", False, "w:sectPr"), ]) def diff_first_header_set_fixture(self, request): sectPr_cxml, value, expected_cxml = request.param sectPr = element(sectPr_cxml) expected_xml = xml(expected_cxml) return sectPr, value, expected_xml @pytest.fixture(params=[ ('w:sectPr/w:pgMar{w:left=120}', 'left_margin', 76200), ('w:sectPr/w:pgMar{w:right=240}', 'right_margin', 152400), ('w:sectPr/w:pgMar{w:top=-360}', 'top_margin', -228600), ('w:sectPr/w:pgMar{w:bottom=480}', 'bottom_margin', 304800), ('w:sectPr/w:pgMar{w:gutter=600}', 'gutter', 381000), ('w:sectPr/w:pgMar{w:header=720}', 'header_distance', 457200), ('w:sectPr/w:pgMar{w:footer=840}', 'footer_distance', 533400), ('w:sectPr/w:pgMar', 'left_margin', None), ('w:sectPr', 'top_margin', None), ]) def margins_get_fixture(self, request): sectPr_cxml, margin_prop_name, expected_value = request.param sectPr = element(sectPr_cxml) return sectPr, margin_prop_name, expected_value @pytest.fixture(params=[ ('w:sectPr', 'left_margin', Inches(1), 'w:sectPr/w:pgMar{w:left=1440}'), ('w:sectPr', 'right_margin', Inches(0.5), 'w:sectPr/w:pgMar{w:right=720}'), ('w:sectPr', 'top_margin', Inches(-0.25), 'w:sectPr/w:pgMar{w:top=-360}'), ('w:sectPr', 'bottom_margin', Inches(0.75), 'w:sectPr/w:pgMar{w:bottom=1080}'), ('w:sectPr', 'gutter', Inches(0.25), 'w:sectPr/w:pgMar{w:gutter=360}'), ('w:sectPr', 'header_distance', Inches(1.25), 'w:sectPr/w:pgMar{w:header=1800}'), ('w:sectPr', 'footer_distance', Inches(1.35), 'w:sectPr/w:pgMar{w:footer=1944}'), ('w:sectPr', 'left_margin', None, 'w:sectPr/w:pgMar'), ('w:sectPr/w:pgMar{w:top=-360}', 'top_margin', Inches(0.6), 'w:sectPr/w:pgMar{w:top=864}'), ]) def margins_set_fixture(self, request): sectPr_cxml, property_name, new_value, expected_cxml = request.param sectPr = element(sectPr_cxml) expected_xml = xml(expected_cxml) return sectPr, property_name, new_value, expected_xml @pytest.fixture(params=[ ('w:sectPr/w:pgSz{w:orient=landscape}', WD_ORIENT.LANDSCAPE), ('w:sectPr/w:pgSz{w:orient=portrait}', WD_ORIENT.PORTRAIT), ('w:sectPr/w:pgSz', WD_ORIENT.PORTRAIT), ('w:sectPr', WD_ORIENT.PORTRAIT), ]) def orientation_get_fixture(self, request): sectPr_cxml, expected_orientation = request.param sectPr = element(sectPr_cxml) return sectPr, expected_orientation @pytest.fixture(params=[ (WD_ORIENT.LANDSCAPE, 'w:sectPr/w:pgSz{w:orient=landscape}'), (WD_ORIENT.PORTRAIT, 'w:sectPr/w:pgSz'), (None, 'w:sectPr/w:pgSz'), ]) def orientation_set_fixture(self, request): new_orientation, expected_cxml = request.param sectPr = element('w:sectPr') expected_xml = xml(expected_cxml) return sectPr, new_orientation, expected_xml @pytest.fixture(params=[ ('w:sectPr/w:pgSz{w:h=2880}', Inches(2)), ('w:sectPr/w:pgSz', None), ('w:sectPr', None), ]) def page_height_get_fixture(self, request): sectPr_cxml, expected_page_height = request.param sectPr = element(sectPr_cxml) return sectPr, expected_page_height @pytest.fixture(params=[ (None, 'w:sectPr/w:pgSz'), (Inches(2), 'w:sectPr/w:pgSz{w:h=2880}'), ]) def page_height_set_fixture(self, request): new_page_height, expected_cxml = request.param sectPr = element('w:sectPr') expected_xml = xml(expected_cxml) return sectPr, new_page_height, expected_xml @pytest.fixture(params=[ ('w:sectPr/w:pgSz{w:w=1440}', Inches(1)), ('w:sectPr/w:pgSz', None), ('w:sectPr', None), ]) def page_width_get_fixture(self, request): sectPr_cxml, expected_page_width = request.param sectPr = element(sectPr_cxml) return sectPr, expected_page_width @pytest.fixture(params=[ (None, 'w:sectPr/w:pgSz'), (Inches(4), 'w:sectPr/w:pgSz{w:w=5760}'), ]) def page_width_set_fixture(self, request): new_page_width, expected_cxml = request.param sectPr = element('w:sectPr') expected_xml = xml(expected_cxml) return sectPr, new_page_width, expected_xml @pytest.fixture(params=[ ('w:sectPr', WD_SECTION.NEW_PAGE), ('w:sectPr/w:type', WD_SECTION.NEW_PAGE), ('w:sectPr/w:type{w:val=continuous}', WD_SECTION.CONTINUOUS), ('w:sectPr/w:type{w:val=nextPage}', WD_SECTION.NEW_PAGE), ('w:sectPr/w:type{w:val=oddPage}', WD_SECTION.ODD_PAGE), ('w:sectPr/w:type{w:val=evenPage}', WD_SECTION.EVEN_PAGE), ('w:sectPr/w:type{w:val=nextColumn}', WD_SECTION.NEW_COLUMN), ]) def start_type_get_fixture(self, request): sectPr_cxml, expected_start_type = request.param sectPr = element(sectPr_cxml) return sectPr, expected_start_type @pytest.fixture(params=[ ('w:sectPr/w:type{w:val=oddPage}', WD_SECTION.EVEN_PAGE, 'w:sectPr/w:type{w:val=evenPage}'), ('w:sectPr/w:type{w:val=nextPage}', None, 'w:sectPr'), ('w:sectPr', None, 'w:sectPr'), ('w:sectPr/w:type{w:val=continuous}', WD_SECTION.NEW_PAGE, 'w:sectPr'), ('w:sectPr/w:type', WD_SECTION.NEW_PAGE, 'w:sectPr'), ('w:sectPr/w:type', WD_SECTION.NEW_COLUMN, 'w:sectPr/w:type{w:val=nextColumn}'), ]) def start_type_set_fixture(self, request): initial_cxml, new_start_type, expected_cxml = request.param sectPr = element(initial_cxml) expected_xml = xml(expected_cxml) return sectPr, new_start_type, expected_xml # fixture components --------------------------------------------- @pytest.fixture def document_part_(self, request): return instance_mock(request, DocumentPart) @pytest.fixture def _Footer_(self, request): return class_mock(request, "docxx.section._Footer") @pytest.fixture def footer_(self, request): return instance_mock(request, _Footer) @pytest.fixture def _Header_(self, request): return class_mock(request, "docxx.section._Header") @pytest.fixture def header_(self, request): return instance_mock(request, _Header)
class Describe_Row(object): def it_knows_its_height(self, height_get_fixture): row, expected_height = height_get_fixture assert row.height == expected_height def it_can_change_its_height(self, height_set_fixture): row, value, expected_xml = height_set_fixture row.height = value assert row._tr.xml == expected_xml def it_knows_its_height_rule(self, height_rule_get_fixture): row, expected_rule = height_rule_get_fixture assert row.height_rule == expected_rule def it_can_change_its_height_rule(self, height_rule_set_fixture): row, rule, expected_xml = height_rule_set_fixture row.height_rule = rule assert row._tr.xml == expected_xml def it_provides_access_to_its_cells(self, cells_fixture): row, row_idx, expected_cells = cells_fixture cells = row.cells row.table.row_cells.assert_called_once_with(row_idx) assert cells == expected_cells def it_provides_access_to_the_table_it_belongs_to(self, table_fixture): row, table_ = table_fixture assert row.table is table_ def it_knows_its_index_in_table_to_help(self, idx_fixture): row, expected_idx = idx_fixture assert row._index == expected_idx # fixtures ------------------------------------------------------- @pytest.fixture def cells_fixture(self, _index_, table_prop_, table_): row = _Row(None, None) _index_.return_value = row_idx = 6 expected_cells = (1, 2, 3) table_.row_cells.return_value = list(expected_cells) return row, row_idx, expected_cells @pytest.fixture(params=[ ('w:tr', None), ('w:tr/w:trPr', None), ('w:tr/w:trPr/w:trHeight', None), ('w:tr/w:trPr/w:trHeight{w:val=0}', 0), ('w:tr/w:trPr/w:trHeight{w:val=1440}', 914400), ]) def height_get_fixture(self, request): tr_cxml, expected_height = request.param row = _Row(element(tr_cxml), None) return row, expected_height @pytest.fixture(params=[ ('w:tr', Inches(1), 'w:tr/w:trPr/w:trHeight{w:val=1440}'), ('w:tr/w:trPr', Inches(1), 'w:tr/w:trPr/w:trHeight{w:val=1440}'), ('w:tr/w:trPr/w:trHeight', Inches(1), 'w:tr/w:trPr/w:trHeight{w:val=1440}'), ('w:tr/w:trPr/w:trHeight{w:val=1440}', Inches(2), 'w:tr/w:trPr/w:trHeight{w:val=2880}'), ('w:tr/w:trPr/w:trHeight{w:val=2880}', None, 'w:tr/w:trPr/w:trHeight'), ('w:tr', None, 'w:tr/w:trPr'), ('w:tr/w:trPr', None, 'w:tr/w:trPr'), ('w:tr/w:trPr/w:trHeight', None, 'w:tr/w:trPr/w:trHeight'), ]) def height_set_fixture(self, request): tr_cxml, new_value, expected_cxml = request.param row = _Row(element(tr_cxml), None) expected_xml = xml(expected_cxml) return row, new_value, expected_xml @pytest.fixture(params=[ ('w:tr', None), ('w:tr/w:trPr', None), ('w:tr/w:trPr/w:trHeight{w:val=0, w:hRule=auto}', WD_ROW_HEIGHT.AUTO), ('w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=atLeast}', WD_ROW_HEIGHT.AT_LEAST), ('w:tr/w:trPr/w:trHeight{w:val=2880, w:hRule=exact}', WD_ROW_HEIGHT.EXACTLY), ]) def height_rule_get_fixture(self, request): tr_cxml, expected_rule = request.param row = _Row(element(tr_cxml), None) return row, expected_rule @pytest.fixture(params=[ ('w:tr', WD_ROW_HEIGHT.AUTO, 'w:tr/w:trPr/w:trHeight{w:hRule=auto}'), ('w:tr/w:trPr', WD_ROW_HEIGHT.AT_LEAST, 'w:tr/w:trPr/w:trHeight{w:hRule=atLeast}'), ('w:tr/w:trPr/w:trHeight', WD_ROW_HEIGHT.EXACTLY, 'w:tr/w:trPr/w:trHeight{w:hRule=exact}'), ('w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=exact}', WD_ROW_HEIGHT.AUTO, 'w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=auto}'), ('w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=auto}', None, 'w:tr/w:trPr/w:trHeight{w:val=1440}'), ('w:tr', None, 'w:tr/w:trPr'), ('w:tr/w:trPr', None, 'w:tr/w:trPr'), ('w:tr/w:trPr/w:trHeight', None, 'w:tr/w:trPr/w:trHeight'), ]) def height_rule_set_fixture(self, request): tr_cxml, new_rule, expected_cxml = request.param row = _Row(element(tr_cxml), None) expected_xml = xml(expected_cxml) return row, new_rule, expected_xml @pytest.fixture def idx_fixture(self): tbl = element('w:tbl/(w:tr,w:tr,w:tr)') tr, expected_idx = tbl[1], 1 row = _Row(tr, None) return row, expected_idx @pytest.fixture def table_fixture(self, parent_, table_): row = _Row(None, parent_) parent_.table = table_ return row, table_ # fixture components --------------------------------------------- @pytest.fixture def _index_(self, request): return property_mock(request, _Row, '_index') @pytest.fixture def parent_(self, request): return instance_mock(request, Table) @pytest.fixture def table_(self, request): return instance_mock(request, Table) @pytest.fixture def table_prop_(self, request, table_): return property_mock(request, _Row, 'table', return_value=table_)
class Describe_Cell(object): def it_knows_what_text_it_contains(self, text_get_fixture): cell, expected_text = text_get_fixture text = cell.text assert text == expected_text def it_can_replace_its_content_with_a_string_of_text( self, text_set_fixture): cell, text, expected_xml = text_set_fixture cell.text = text assert cell._tc.xml == expected_xml def it_knows_its_vertical_alignment(self, alignment_get_fixture): cell, expected_value = alignment_get_fixture vertical_alignment = cell.vertical_alignment assert vertical_alignment == expected_value def it_can_change_its_vertical_alignment(self, alignment_set_fixture): cell, new_value, expected_xml = alignment_set_fixture cell.vertical_alignment = new_value assert cell._element.xml == expected_xml def it_knows_its_width_in_EMU(self, width_get_fixture): cell, expected_width = width_get_fixture assert cell.width == expected_width def it_can_change_its_width(self, width_set_fixture): cell, value, expected_xml = width_set_fixture cell.width = value assert cell.width == value assert cell._tc.xml == expected_xml def it_provides_access_to_the_paragraphs_it_contains( self, paragraphs_fixture): cell = paragraphs_fixture paragraphs = cell.paragraphs assert len(paragraphs) == 2 count = 0 for idx, paragraph in enumerate(paragraphs): assert isinstance(paragraph, Paragraph) assert paragraph is paragraphs[idx] count += 1 assert count == 2 def it_provides_access_to_the_tables_it_contains(self, tables_fixture): # test len(), iterable, and indexed access cell, expected_count = tables_fixture tables = cell.tables assert len(tables) == expected_count count = 0 for idx, table in enumerate(tables): assert isinstance(table, Table) assert tables[idx] is table count += 1 assert count == expected_count def it_can_add_a_paragraph(self, add_paragraph_fixture): cell, expected_xml = add_paragraph_fixture p = cell.add_paragraph() assert cell._tc.xml == expected_xml assert isinstance(p, Paragraph) def it_can_add_a_table(self, add_table_fixture): cell, expected_xml = add_table_fixture table = cell.add_table(rows=2, cols=2) assert cell._element.xml == expected_xml assert isinstance(table, Table) def it_can_merge_itself_with_other_cells(self, merge_fixture): cell, other_cell, merged_tc_ = merge_fixture merged_cell = cell.merge(other_cell) cell._tc.merge.assert_called_once_with(other_cell._tc) assert isinstance(merged_cell, _Cell) assert merged_cell._tc is merged_tc_ assert merged_cell._parent is cell._parent # fixtures ------------------------------------------------------- @pytest.fixture(params=[ ('w:tc', 'w:tc/w:p'), ('w:tc/w:p', 'w:tc/(w:p, w:p)'), ('w:tc/w:tbl', 'w:tc/(w:tbl, w:p)'), ]) def add_paragraph_fixture(self, request): tc_cxml, after_tc_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(after_tc_cxml) return cell, expected_xml @pytest.fixture def add_table_fixture(self, request): cell = _Cell(element('w:tc/w:p'), None) expected_xml = snippet_seq('new-tbl')[1] return cell, expected_xml @pytest.fixture(params=[ ('w:tc', None), ('w:tc/w:tcPr', None), ('w:tc/w:tcPr/w:vAlign{w:val=bottom}', WD_ALIGN_VERTICAL.BOTTOM), ('w:tc/w:tcPr/w:vAlign{w:val=top}', WD_ALIGN_VERTICAL.TOP), ]) def alignment_get_fixture(self, request): tc_cxml, expected_value = request.param cell = _Cell(element(tc_cxml), None) return cell, expected_value @pytest.fixture(params=[ ('w:tc', WD_ALIGN_VERTICAL.TOP, 'w:tc/w:tcPr/w:vAlign{w:val=top}'), ('w:tc/w:tcPr', WD_ALIGN_VERTICAL.CENTER, 'w:tc/w:tcPr/w:vAlign{w:val=center}'), ('w:tc/w:tcPr/w:vAlign{w:val=center}', WD_ALIGN_VERTICAL.BOTTOM, 'w:tc/w:tcPr/w:vAlign{w:val=bottom}'), ('w:tc/w:tcPr/w:vAlign{w:val=center}', None, 'w:tc/w:tcPr'), ('w:tc', None, 'w:tc/w:tcPr'), ('w:tc/w:tcPr', None, 'w:tc/w:tcPr'), ]) def alignment_set_fixture(self, request): cxml, new_value, expected_cxml = request.param cell = _Cell(element(cxml), None) expected_xml = xml(expected_cxml) return cell, new_value, expected_xml @pytest.fixture def merge_fixture(self, tc_, tc_2_, parent_, merged_tc_): cell, other_cell = _Cell(tc_, parent_), _Cell(tc_2_, parent_) tc_.merge.return_value = merged_tc_ return cell, other_cell, merged_tc_ @pytest.fixture def paragraphs_fixture(self): return _Cell(element('w:tc/(w:p, w:p)'), None) @pytest.fixture(params=[ ('w:tc', 0), ('w:tc/w:tbl', 1), ('w:tc/(w:tbl,w:tbl)', 2), ('w:tc/(w:p,w:tbl)', 1), ('w:tc/(w:tbl,w:tbl,w:p)', 2), ]) def tables_fixture(self, request): cell_cxml, expected_count = request.param cell = _Cell(element(cell_cxml), None) return cell, expected_count @pytest.fixture(params=[ ('w:tc', ''), ('w:tc/w:p/w:r/w:t"foobar"', 'foobar'), ('w:tc/(w:p/w:r/w:t"foo",w:p/w:r/w:t"bar")', 'foo\nbar'), ('w:tc/(w:tcPr,w:p/w:r/w:t"foobar")', 'foobar'), ('w:tc/w:p/w:r/(w:t"fo",w:tab,w:t"ob",w:br,w:t"ar",w:br)', 'fo\tob\nar\n'), ]) def text_get_fixture(self, request): tc_cxml, expected_text = request.param cell = _Cell(element(tc_cxml), None) return cell, expected_text @pytest.fixture(params=[ ('w:tc/w:p', 'foobar', 'w:tc/w:p/w:r/w:t"foobar"'), ('w:tc/w:p', 'fo\tob\rar\n', 'w:tc/w:p/w:r/(w:t"fo",w:tab,w:t"ob",w:br,w:t"ar",w:br)'), ('w:tc/(w:tcPr, w:p, w:tbl, w:p)', 'foobar', 'w:tc/(w:tcPr, w:p/w:r/w:t"foobar")'), ]) def text_set_fixture(self, request): tc_cxml, new_text, expected_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(expected_cxml) return cell, new_text, expected_xml @pytest.fixture(params=[ ('w:tc', None), ('w:tc/w:tcPr', None), ('w:tc/w:tcPr/w:tcW{w:w=25%,w:type=pct}', None), ('w:tc/w:tcPr/w:tcW{w:w=1440,w:type=dxa}', 914400), ]) def width_get_fixture(self, request): tc_cxml, expected_width = request.param cell = _Cell(element(tc_cxml), None) return cell, expected_width @pytest.fixture(params=[ ('w:tc', Inches(1), 'w:tc/w:tcPr/w:tcW{w:w=1440,w:type=dxa}'), ('w:tc/w:tcPr/w:tcW{w:w=25%,w:type=pct}', Inches(2), 'w:tc/w:tcPr/w:tcW{w:w=2880,w:type=dxa}'), ]) def width_set_fixture(self, request): tc_cxml, new_value, expected_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(expected_cxml) return cell, new_value, expected_xml # fixture components --------------------------------------------- @pytest.fixture def merged_tc_(self, request): return instance_mock(request, CT_Tc) @pytest.fixture def parent_(self, request): return instance_mock(request, Table) @pytest.fixture def tc_(self, request): return instance_mock(request, CT_Tc) @pytest.fixture def tc_2_(self, request): return instance_mock(request, CT_Tc)
def add_table_fixture(self): blkcntnr = BlockItemContainer(element('w:body'), None) rows, cols, width = 2, 2, Inches(2) expected_xml = snippet_seq('new-tbl')[0] return blkcntnr, rows, cols, width, expected_xml