def test_new_placeholder_sp_generates_correct_xml(self):
     """CT_Shape._new_placeholder_sp() returns correct XML"""
     # setup ------------------------
     expected_xml_tmpl = (
         '<p:sp %s>\n  <p:nvSpPr>\n    <p:cNvPr id="%s" name="%s"/>\n    <'
         'p:cNvSpPr>\n      <a:spLocks noGrp="1"/>\n    </p:cNvSpPr>\n    '
         '<p:nvPr>\n      <p:ph%s/>\n    </p:nvPr>\n  </p:nvSpPr>\n  <p:sp'
         'Pr/>\n%s</p:sp>\n' % (nsdecls('a', 'p'), '%d', '%s', '%s', '%s')
     )
     txBody_snippet = (
         '  <p:txBody>\n    <a:bodyPr/>\n    <a:lstStyle/>\n    <a:p/>\n  '
         '</p:txBody>\n')
     test_cases = (
         (2, 'Title 1', PH_TYPE_CTRTITLE, PH_ORIENT_HORZ, PH_SZ_FULL,
          0),
         (3, 'Date Placeholder 2', PH_TYPE_DT, PH_ORIENT_HORZ, PH_SZ_HALF,
          10),
         (4, 'Vertical Subtitle 3', PH_TYPE_SUBTITLE, PH_ORIENT_VERT,
          PH_SZ_FULL, 1),
         (5, 'Table Placeholder 4', PH_TYPE_TBL, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 14),
         (6, 'Slide Number Placeholder 5', PH_TYPE_SLDNUM, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 12),
         (7, 'Footer Placeholder 6', PH_TYPE_FTR, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 11),
         (8, 'Content Placeholder 7', PH_TYPE_OBJ, PH_ORIENT_HORZ,
          PH_SZ_FULL, 15)
     )
     expected_values = (
         (2, 'Title 1', ' type="%s"' % PH_TYPE_CTRTITLE, txBody_snippet),
         (3, 'Date Placeholder 2', ' type="%s" sz="half" idx="10"' %
          PH_TYPE_DT, ''),
         (4, 'Vertical Subtitle 3', ' type="%s" orient="vert" idx="1"' %
          PH_TYPE_SUBTITLE, txBody_snippet),
         (5, 'Table Placeholder 4', ' type="%s" sz="quarter" idx="14"' %
          PH_TYPE_TBL, ''),
         (6, 'Slide Number Placeholder 5', ' type="%s" sz="quarter" '
          'idx="12"' % PH_TYPE_SLDNUM, ''),
         (7, 'Footer Placeholder 6', ' type="%s" sz="quarter" idx="11"' %
          PH_TYPE_FTR, ''),
         (8, 'Content Placeholder 7', ' idx="15"', txBody_snippet)
     )
     # exercise ---------------------
     for case_idx, argv in enumerate(test_cases):
         id_, name, ph_type, orient, sz, idx = argv
         sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz,
                                          idx)
         # verify ------------------
         expected_xml = expected_xml_tmpl % expected_values[case_idx]
         self.assertEqualLineByLine(expected_xml, sp)
Exemple #2
0
    def _clone_layout_placeholder(self, layout_ph):
        """
        Add a new placeholder shape based on the slide layout placeholder
        *layout_ph*.
        """
        id_ = self._next_shape_id
        ph_type = layout_ph.type
        orient = layout_ph.orient
        shapename = self._next_ph_name(ph_type, id_, orient)
        sz = layout_ph.sz
        idx = layout_ph.idx

        sp = CT_Shape.new_placeholder_sp(id_, shapename, ph_type, orient,
                                         sz, idx)
        shape = Shape(sp, self)

        self._spTree.append(sp)
        self._shapes.append(shape)
        return shape