Beispiel #1
0
    def it_can_create_a_new_pic_element(self, desc, xml_desc):
        """`desc` attr (often filename) is XML-escaped to handle special characters.

        In particular, ampersand ('&'), less/greater-than ('</>') etc.
        """
        pic = CT_Picture.new_pic(
            shape_id=9, name="Picture 8", desc=desc, rId="rId42", x=1, y=2, cx=3, cy=4
        )

        assert pic.xml == (
            "<p:pic %s>\n"
            "  <p:nvPicPr>\n"
            '    <p:cNvPr id="9" name="Picture 8" descr="%s"/>\n'
            "    <p:cNvPicPr>\n"
            '      <a:picLocks noChangeAspect="1"/>\n'
            "    </p:cNvPicPr>\n"
            "    <p:nvPr/>\n"
            "  </p:nvPicPr>\n"
            "  <p:blipFill>\n"
            '    <a:blip r:embed="rId42"/>\n'
            "    <a:stretch>\n"
            "      <a:fillRect/>\n"
            "    </a:stretch>\n"
            "  </p:blipFill>\n"
            "  <p:spPr>\n"
            "    <a:xfrm>\n"
            '      <a:off x="1" y="2"/>\n'
            '      <a:ext cx="3" cy="4"/>\n'
            "    </a:xfrm>\n"
            '    <a:prstGeom prst="rect">\n'
            "      <a:avLst/>\n"
            "    </a:prstGeom>\n"
            "  </p:spPr>\n"
            "</p:pic>\n" % (nsdecls("a", "p", "r"), xml_desc)
        )
Beispiel #2
0
 def add_pic(self, id_, name, desc, rId, x, y, cx, cy):
     """
     Append a ``<p:pic>`` shape to the group/shapetree having properties
     as specified in call.
     """
     pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy)
     self.insert_element_before(pic, 'p:extLst')
     return pic
Beispiel #3
0
 def add_pic(self, id_, name, desc, rId, x, y, cx, cy):
     """
     Append a ``<p:pic>`` shape to the group/shapetree having properties
     as specified in call.
     """
     pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy)
     self.insert_element_before(pic, "p:extLst")
     return pic
Beispiel #4
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup ------------------------
     id_, name, desc, rId = 9, 'Picture 8', 'test-image.png', 'rId7'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:pic %s>\n  <p:nvPicPr>\n    <p:cNvPr id="%d" name="%s" descr='
         '"%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noChangeAspect="1"/>'
         '\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr>\n  <p:blipFil'
         'l>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n      <a:fillRe'
         'ct/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spPr>\n    <a:xfrm'
         '>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/>'
         '\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n      <a:avLst/>'
         '\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n' %
         (nsdecls('a', 'p',
                  'r'), id_, name, desc, rId, left, top, width, height))
     # exercise ---------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top, width,
                              height)
     # verify -----------------------
     assert pic.xml == xml
Beispiel #5
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup ------------------------
     id_, name, desc, rId = 9, 'Picture 8', 'test-image.png', 'rId7'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:pic %s>\n  <p:nvPicPr>\n    <p:cNvPr id="%d" name="%s" descr='
         '"%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noChangeAspect="1"/>'
         '\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr>\n  <p:blipFil'
         'l>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n      <a:fillRe'
         'ct/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spPr>\n    <a:xfrm'
         '>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/>'
         '\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n      <a:avLst/>'
         '\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n' %
         (nsdecls('a', 'p', 'r'), id_, name, desc, rId, left, top, width,
          height)
     )
     # exercise ---------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top,
                              width, height)
     # verify -----------------------
     assert pic.xml == xml
 def it_can_generate_a_new_pic_element(self, new_fixture):
     id_, name, desc, rId, x, y, cx, cy, expected_xml = new_fixture
     pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy)
     print(expected_xml)
     assert pic.xml == expected_xml
 def it_can_create_a_new_pic_element(self, pic_fixture):
     shape_id, name, desc, rId, x, y, cx, cy, expected_xml = pic_fixture
     pic = CT_Picture.new_pic(shape_id, name, desc, rId, x, y, cx, cy)
     assert pic.xml == expected_xml
Beispiel #8
0
 def it_can_create_a_new_pic_element(self, pic_fixture):
     shape_id, name, desc, rId, x, y, cx, cy, expected_xml = pic_fixture
     pic = CT_Picture.new_pic(shape_id, name, desc, rId, x, y, cx, cy)
     assert pic.xml == expected_xml