def _append_run(self, run, text, style=None): new_r = run._r.add_r_after() new_r = Run(new_r, self) if text: new_r.text = text if style: new_r.style = style return new_r
def bool_prop_get_fixture(self, request): bool_prop_name, expected_state = request.param bool_prop_bldr = { 'all_caps': a_caps, 'bold': a_b, 'complex_script': a_cs, 'cs_bold': a_bCs, 'cs_italic': an_iCs, 'double_strike': a_dstrike, 'emboss': an_emboss, 'hidden': a_vanish, 'italic': an_i, 'imprint': an_imprint, 'math': an_oMath, 'no_proof': a_noProof, 'outline': an_outline, 'rtl': an_rtl, 'shadow': a_shadow, 'small_caps': a_smallCaps, 'snap_to_grid': a_snapToGrid, 'spec_vanish': a_specVanish, 'strike': a_strike, 'web_hidden': a_webHidden, }[bool_prop_name] r_bldr = an_r().with_nsdecls() if expected_state is not None: child_bldr = bool_prop_bldr() if expected_state is False: child_bldr.with_val('off') rPr_bldr = an_rPr().with_child(child_bldr) r_bldr.with_child(rPr_bldr) r = r_bldr.element run = Run(r) return run, bool_prop_name, expected_state
def replace(self, text, base=None, allowed_styles=None): log.debug("Replacing content from %s with '%s' in %s", self, text, base) if base is None or True: start, end = self.start, self.end else: start = base.xpath(self.xpath_start)[0] end = base.xpath(self.xpath_end)[0] log.debug("Using start: %s %s %s", start, self.xpath_start, start.getparent()) log.debug("Using end: %s %s %s", end, self.xpath_end, end.getparent() if end is not None else None) for sibl in start.itersiblings(): sibl.getparent().remove(sibl) if [sibl] == end: break if start.tag.endswith('r'): r = Run(start, self._parent) if hasattr(r._r, 'clear_content'): r._r.clear_content() self.insert(r, text, allowed_styles=allowed_styles) return r else: # TODO pass
def add_picture_fixture(self, request, body_, document_, image_descriptor_, InlineShape_, r_, image_part_, rId_, shape_id_, new_picture_shape_): inline_shapes = InlineShapes(body_, None) property_mock(request, InlineShapes, 'part', return_value=document_) run = Run(r_, None) return (inline_shapes, image_descriptor_, document_, InlineShape_, run, r_, image_part_, rId_, shape_id_, new_picture_shape_)
def add_picture_fixture(self, request, paragraph_, inline_shapes_, picture_): width, height, expected_width, expected_height = request.param paragraph_.part.inline_shapes = inline_shapes_ run = Run(None, paragraph_) image_descriptor_ = 'image_descriptor_' picture_.width, picture_.height = 200, 100 return (run, image_descriptor_, width, height, inline_shapes_, expected_width, expected_height, picture_)
def bold_get_fixture(self, request): is_bold = request.param r_bldr = an_r().with_nsdecls() if is_bold is not None: b_bldr = a_b() if is_bold is False: b_bldr.with_val('off') rPr_bldr = an_rPr().with_child(b_bldr) r_bldr.with_child(rPr_bldr) r = r_bldr.element run = Run(r) return run, is_bold
def italic_get_fixture(self, request): is_italic = request.param r_bldr = an_r().with_nsdecls() if is_italic is not None: i_bldr = an_i() if is_italic is False: i_bldr.with_val('off') rPr_bldr = an_rPr().with_child(i_bldr) r_bldr.with_child(rPr_bldr) r = r_bldr.element run = Run(r) return run, is_italic
def italic_set_fixture(self, request): # run -------------------------- r = an_r().with_nsdecls().element run = Run(r) # italic_value ------------------- italic_value = request.param # expected_xml ----------------- rPr_bldr = an_rPr() if italic_value is not None: i_bldr = an_i() if italic_value is False: i_bldr.with_val(0) rPr_bldr.with_child(i_bldr) expected_xml = an_r().with_nsdecls().with_child(rPr_bldr).xml() return run, italic_value, expected_xml
def bold_set_fixture(self, request): # run -------------------------- r = an_r().with_nsdecls().element run = Run(r) # bold_value ------------------- bold_value = request.param # expected_xml ----------------- rPr_bldr = an_rPr() if bold_value is not None: b_bldr = a_b() if bold_value is False: b_bldr.with_val(0) rPr_bldr.with_child(b_bldr) expected_xml = an_r().with_nsdecls().with_child(rPr_bldr).xml() return run, bold_value, expected_xml
def given_a_run_having_mixed_text_content(context): """ Mixed here meaning it contains ``<w:tab/>``, ``<w:cr/>``, etc. elements. """ r_xml = """\ <w:r %s> <w:t>abc</w:t> <w:tab/> <w:t>def</w:t> <w:cr/> <w:t>ghi</w:t> <w:drawing/> <w:br/> <w:t>jkl</w:t> </w:r>""" % nsdecls('w') r = parse_xml(r_xml) context.run = Run(r, None)
def style_set_fixture(self, request): before_style, after_style = request.param r = self.r_bldr_with_style(before_style).element run = Run(r) expected_xml = self.r_bldr_with_style(after_style).xml() return run, after_style, expected_xml
def underline_raise_fixture(self, request): invalid_underline_setting = request.param run = Run(element('w:r/w:rPr'), None) return run, invalid_underline_setting
def underline_set_fixture(self, request): initial_r_cxml, new_underline, expected_cxml = request.param run = Run(element(initial_r_cxml), None) expected_xml = xml(expected_cxml) return run, new_underline, expected_xml
def underline_get_fixture(self, request): r_cxml, expected_underline = request.param run = Run(element(r_cxml), None) return run, expected_underline
def text_set_fixture(self, request): new_text, expected_cxml = request.param initial_r_cxml = 'w:r/w:t"should get deleted"' run = Run(element(initial_r_cxml), None) expected_xml = xml(expected_cxml) return run, new_text, expected_xml
def underline_set_fixture(self, request): before_val, underline, expected_val = request.param r = self.r_bldr_with_underline(before_val).element run = Run(r) expected_xml = self.r_bldr_with_underline(expected_val).xml() return run, underline, expected_xml
def style_get_fixture(self, request): r_cxml, expected_style = request.param run = Run(element(r_cxml), None) return run, expected_style
def underline_get_fixture(self, request): underline_type, expected_prop_value = request.param r = self.r_bldr_with_underline(underline_type).element run = Run(r) return run, expected_prop_value
def run(self): r = an_r().with_nsdecls().element return Run(r)
def add_text_fixture(self, request, Text_): r_cxml, text, expected_cxml = request.param run = Run(element(r_cxml), None) expected_xml = xml(expected_cxml) return run, text, expected_xml, Text_
def add_tab_fixture(self, request): r_cxml, expected_cxml = request.param run = Run(element(r_cxml), None) expected_xml = xml(expected_cxml) return run, expected_xml
def style_get_fixture(self, request): style = request.param r = self.r_bldr_with_style(style).element run = Run(r) return run, style
def text_get_fixture(self, request): r_cxml, expected_text = request.param run = Run(element(r_cxml), None) return run, expected_text
def bool_prop_get_fixture(self, request): r_cxml, bool_prop_name, expected_value = request.param run = Run(element(r_cxml), None) return run, bool_prop_name, expected_value
def add_break_fixture(self, request): break_type, expected_cxml = request.param run = Run(element('w:r'), None) expected_xml = xml(expected_cxml) return run, break_type, expected_xml
def bool_prop_set_fixture(self, request): initial_r_cxml, bool_prop_name, value, expected_cxml = request.param run = Run(element(initial_r_cxml), None) expected_xml = xml(expected_cxml) return run, bool_prop_name, value, expected_xml
def clear_fixture(self, request): initial_r_cxml, expected_cxml = request.param run = Run(element(initial_r_cxml), None) expected_xml = xml(expected_cxml) return run, expected_xml
def text_prop_fixture(self, Text_): r = (an_r().with_nsdecls().with_child( a_t().with_text('foo')).with_child(a_t().with_text('bar'))).element run = Run(r) return run, 'foobar'
def underline_raise_fixture(self, request): underline = request.param r = self.r_bldr_with_underline(None).element run = Run(r) return run, underline