def test__blob_value_for_xml_part(self): """_BasePart._blob value is correct for XML part""" # setup ------------------------ elm = oxml_fromstring('<root><elm1 attr="one"/></root>') self.basepart._element = elm self.basepart.partname = '/ppt/presentation.xml' # exercise --------------------- retval = self.basepart._blob # verify ----------------------- expected = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"\ '\n<root>\n <elm1 attr="one"/>\n</root>\n' actual = retval msg = "expected: \n'%s'\n, got \n'%s'" % (expected, actual) self.assertEqual(expected, actual, msg)
def test__blob_rewrites_sldIdLst(self): """Presentation._blob rewrites sldIdLst""" # setup ------------------------ rels = RelationshipCollectionBuilder() rels = rels.with_tuple_targets(2, RT_SLIDE_MASTER) rels = rels.with_tuple_targets(3, RT_SLIDE) rels = rels.with_ordering(RT_SLIDE_MASTER, RT_SLIDE) rels = rels.build() prs = Presentation() prs._relationships = rels prs.partname = '/ppt/presentation.xml' path = os.path.join(thisdir, 'test_files/presentation.xml') prs._element = oxml_parse(path).getroot() # exercise --------------------- blob = prs._blob # verify ----------------------- presentation = oxml_fromstring(blob) sldIds = presentation.xpath('./p:sldIdLst/p:sldId', namespaces=nsmap) expected = ['rId3', 'rId4', 'rId5'] actual = [sldId.get(qtag('r:id')) for sldId in sldIds] msg = "expected ordering %s, got %s" % (expected, actual) self.assertEqual(expected, actual, msg)
def _load(self, pkgpart, part_dict): """ Load part and relationships from package part, and propagate load process down the relationship graph. *pkgpart* is an instance of :class:`pptx.packaging.Part` containing the part contents read from the on-disk package. *part_dict* is a dictionary of already-loaded parts, keyed by partname. """ # set attributes from package part self.__content_type = pkgpart.content_type self.__partname = pkgpart.partname if pkgpart.partname.endswith('.xml'): self._element = oxml_fromstring(pkgpart.blob) else: self._load_blob = pkgpart.blob # discard any previously loaded relationships self._relationships = _RelationshipCollection() # load relationships and propagate load for related parts for pkgrel in pkgpart.relationships: # unpack working values for part to be loaded reltype = pkgrel.reltype target_pkgpart = pkgrel.target partname = target_pkgpart.partname content_type = target_pkgpart.content_type # create target part if partname in part_dict: part = part_dict[partname] else: part = _Part(reltype, content_type) part_dict[partname] = part part._load(target_pkgpart, part_dict) # create model-side package relationship model_rel = _Relationship(pkgrel.rId, reltype, part) self._relationships._additem(model_rel) return self
def isolated_tbl(self): return oxml_fromstring(test_table_xml.isolated_tbl)
def empty_spTree(self): return oxml_fromstring(test_shape_xml.empty_spTree)
def element(self): """Return element based on XML generated by builder""" return oxml_fromstring(self.xml)
def centered_paragraph(self): return oxml_fromstring(test_text_xml.centered_paragraph)
def paragraph(self): return oxml_fromstring(test_text_xml.paragraph)
def isolated_tbl_with_true_props(self): return oxml_fromstring(test_table_xml.isolated_tbl_with_true_props)
def top_aligned_cell(self): return oxml_fromstring(test_table_xml.top_aligned_cell)
def cell_with_margins(self): return oxml_fromstring(test_table_xml.cell_with_margins)
def autoshape(self): return oxml_fromstring(test_shape_xml.autoshape)
def cell(self): return oxml_fromstring(test_table_xml.cell)
def textbox(self): return oxml_fromstring(test_shape_xml.textbox)
def rounded_rectangle(self): return oxml_fromstring(test_shape_xml.rounded_rectangle)
def placeholder(self): return oxml_fromstring(test_shape_xml.placeholder)
def picture(self): return oxml_fromstring(test_shape_xml.picture)