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_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_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_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_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_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_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_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_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_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 margins_get_fixture(self, request): (has_pgMar_child, left, right, top, bottom, gutter, header, footer) = request.param pgMar_bldr = self.pgMar_bldr( **{ 'has_pgMar': has_pgMar_child, 'left': left, 'right': right, 'top': top, 'bottom': bottom, 'gutter': gutter, 'header': header, 'footer': footer }) sectPr = self.sectPr_bldr(pgMar_bldr).element section = Section(sectPr) expected_left = self.twips_to_emu(left) expected_right = self.twips_to_emu(right) expected_top = self.twips_to_emu(top) expected_bottom = self.twips_to_emu(bottom) expected_gutter = self.twips_to_emu(gutter) expected_header = self.twips_to_emu(header) expected_footer = self.twips_to_emu(footer) return (section, expected_left, expected_right, expected_top, expected_bottom, expected_gutter, expected_header, expected_footer)
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
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_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_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_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_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_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 page_width_set_fixture(self, request): new_page_width, expected_w_val = request.param # section ---------------------- sectPr = self.sectPr_bldr().element section = Section(sectPr) # expected_xml ----------------- pgSz_bldr = self.pgSz_bldr(w=expected_w_val) expected_xml = self.sectPr_bldr(pgSz_bldr).xml() return section, new_page_width, expected_xml
def orientation_set_fixture(self, request): new_orientation, expected_orient_val = request.param # section ---------------------- sectPr = self.sectPr_bldr().element section = Section(sectPr) # expected_xml ----------------- pgSz_bldr = self.pgSz_bldr(orient=expected_orient_val) expected_xml = self.sectPr_bldr(pgSz_bldr).xml() return section, new_orientation, expected_xml
def add_section(self, start_type=WD_SECTION.NEW_PAGE): """ Return a |Section| object representing a new section added at the end of the document. The optional *start_type* argument must be a member of the :ref:`WdSectionStart` enumeration, and defaults to ``WD_SECTION.NEW_PAGE`` if not provided. """ new_sectPr = self._element.body.add_section_break() new_sectPr.start_type = start_type return Section(new_sectPr, self._part)
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_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_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 start_type_set_fixture(self, request): (has_type_child, initial_type_val, new_type, has_type_child_after, expected_type_val) = request.param # section ---------------------- type_bldr = self.type_bldr(has_type_child, initial_type_val) sectPr = self.sectPr_bldr(type_bldr).element section = Section(sectPr) # expected_xml ----------------- type_bldr = self.type_bldr(has_type_child_after, expected_type_val) expected_xml = self.sectPr_bldr(type_bldr).xml() return section, new_type, expected_xml
def define_page_format(section: Section): """ Define the page setup of a section as default A4 setup (21 cm x 29.7 cm) with 2.5 cm margin. Args: section: Section whose setup will be defined. """ section.orientation = WD_ORIENT.PORTRAIT section.page_width = Cm(21) section.page_height = Cm(29.7) section.top_margin = Cm(2.5) section.bottom_margin = Cm(2.5) section.right_margin = Cm(2.5) section.left_margin = Cm(2.5)
def margins_set_fixture(self, request): margin_side, initial_margin, new_margin = request.param # section ---------------------- pgMar_bldr = self.pgMar_bldr(**{margin_side: initial_margin}) sectPr = self.sectPr_bldr(pgMar_bldr).element section = Section(sectPr) # property name ---------------- property_name = { 'left': 'left_margin', 'right': 'right_margin', 'top': 'top_margin', 'bottom': 'bottom_margin', 'gutter': 'gutter', 'header': 'header_distance', 'footer': 'footer_distance' }[margin_side] # expected_xml ----------------- pgMar_bldr = self.pgMar_bldr(**{margin_side: new_margin}) expected_xml = self.sectPr_bldr(pgMar_bldr).xml() new_value = self.twips_to_emu(new_margin) return section, property_name, new_value, expected_xml
def start_type_set_fixture(self, request): initial_cxml, new_start_type, expected_cxml = request.param section = Section(element(initial_cxml)) expected_xml = xml(expected_cxml) return section, new_start_type, expected_xml
def orientation_get_fixture(self, request): sectPr_cxml, expected_orientation = request.param section = Section(element(sectPr_cxml)) return section, expected_orientation
def margins_set_fixture(self, request): sectPr_cxml, property_name, new_value, expected_cxml = request.param section = Section(element(sectPr_cxml)) expected_xml = xml(expected_cxml) return section, property_name, new_value, expected_xml
def orientation_set_fixture(self, request): new_orientation, expected_cxml = request.param section = Section(element('w:sectPr')) expected_xml = xml(expected_cxml) return section, new_orientation, expected_xml
def page_width_get_fixture(self, request): sectPr_cxml, expected_page_width = request.param section = Section(element(sectPr_cxml)) return section, expected_page_width
def page_width_set_fixture(self, request): new_page_width, expected_cxml = request.param section = Section(element('w:sectPr')) expected_xml = xml(expected_cxml) return section, new_page_width, expected_xml
def start_type_get_fixture(self, request): sectPr_cxml, expected_start_type = request.param section = Section(element(sectPr_cxml)) return section, expected_start_type
def margins_get_fixture(self, request): sectPr_cxml, margin_prop_name, expected_value = request.param section = Section(element(sectPr_cxml)) return section, margin_prop_name, expected_value