Ejemplo n.º 1
0
 def next_fixture(self, request, iter_parts_):
     idxs, idx = request.param
     package = Package()
     package.iter_parts.return_value = self.i_image_parts(request, idxs)
     ext = 'foo'
     expected_value = '/ppt/media/image%d.%s' % (idx, ext)
     return package, ext, expected_value
Ejemplo n.º 2
0
def step_then_a_ext_image_part_appears_in_the_pptx_file(context, ext):
    pkg = Package.open(saved_pptx_path)
    partnames = frozenset(p.partname for p in pkg.iter_parts())
    image_partname = "/ppt/media/image1.%s" % ext
    assert image_partname in partnames, "got %s" % [
        p for p in partnames if "image" in p
    ]
Ejemplo n.º 3
0
 def nmp_fixture(self, request, iter_parts_):
     idxs, idx = request.param
     package = Package(None)
     package.iter_parts.return_value = self.i_media_parts(request, idxs)
     ext = "foo"
     expected_value = "/ppt/media/media%d.%s" % (idx, ext)
     return package, ext, expected_value
Ejemplo n.º 4
0
 def image_part_fixture(self, image_parts_, image_part_,
                        _image_parts_prop_):
     package = Package()
     image_file = 'foobar.png'
     _image_parts_prop_.return_value = image_parts_
     image_parts_.get_or_add_image_part.return_value = image_part_
     return package, image_file, image_parts_, image_part_
Ejemplo n.º 5
0
def step_then_a_ext_image_part_appears_in_the_pptx_file(context, ext):
    pkg = Package().open(saved_pptx_path)
    partnames = [part.partname for part in pkg.parts]
    image_partname = "/ppt/media/image1.%s" % ext
    assert image_partname in partnames, "got %s" % [
        p for p in partnames if "image" in p
    ]
Ejemplo n.º 6
0
 def it_can_save_itself_to_a_pptx_file(self, temp_pptx_path):
     """
     Package.save produces a .pptx with plausible contents
     """
     # setup ------------------------
     pkg = Package.open()
     # exercise ---------------------
     pkg.save(temp_pptx_path)
     # verify -----------------------
     pkg = Package.open(temp_pptx_path)
     prs = pkg.presentation
     assert prs is not None
     slide_masters = prs.slide_masters
     assert slide_masters is not None
     assert len(slide_masters) == 1
     slide_layouts = slide_masters[0].slide_layouts
     assert slide_layouts is not None
     assert len(slide_layouts) == 11
Ejemplo n.º 7
0
 def it_loads_default_template_when_opened_with_no_path(self):
     prs = Package.open().presentation
     assert prs is not None
     slide_masters = prs.slide_masters
     assert slide_masters is not None
     assert len(slide_masters) == 1
     slide_layouts = slide_masters[0].slide_layouts
     assert slide_layouts is not None
     assert len(slide_layouts) == 11
Ejemplo n.º 8
0
 def it_loads_default_template_when_opened_with_no_path(self):
     prs = Package.open().presentation
     assert prs is not None
     slide_masters = prs.slide_masters
     assert slide_masters is not None
     assert len(slide_masters) == 1
     slide_layouts = slide_masters[0].slide_layouts
     assert slide_layouts is not None
     assert len(slide_layouts) == 11
Ejemplo n.º 9
0
 def it_can_save_itself_to_a_pptx_file(self, temp_pptx_path):
     """
     Package.save produces a .pptx with plausible contents
     """
     # setup ------------------------
     pkg = Package.open()
     # exercise ---------------------
     pkg.save(temp_pptx_path)
     # verify -----------------------
     pkg = Package.open(temp_pptx_path)
     prs = pkg.presentation
     assert prs is not None
     slide_masters = prs.slide_masters
     assert slide_masters is not None
     assert len(slide_masters) == 1
     slide_layouts = slide_masters[0].slide_layouts
     assert slide_layouts is not None
     assert len(slide_layouts) == 11
Ejemplo n.º 10
0
 def test_add_image_returns_matching_image(self):
     pkg = Package.open(images_pptx_path)
     matching_idx = 4
     matching_image = pkg._images[matching_idx]
     # exercise ---------------------
     image = pkg._images.add_image(test_image_path)
     # verify -----------------------
     expected = matching_image
     actual = image
     msg = ("expected images[%d], got images[%d]" %
            (matching_idx, pkg._images.index(image)))
     self.assertEqual(expected, actual, msg)
Ejemplo n.º 11
0
 def test_add_image_returns_matching_image(self):
     pkg = Package.open(images_pptx_path)
     matching_idx = 4
     matching_image = pkg._images[matching_idx]
     # exercise ---------------------
     image = pkg._images.add_image(test_image_path)
     # verify -----------------------
     expected = matching_image
     actual = image
     msg = ("expected images[%d], got images[%d]"
            % (matching_idx, pkg._images.index(image)))
     self.assertEqual(expected, actual, msg)
Ejemplo n.º 12
0
 def test_add_image_adds_new_image(self):
     """ImageCollection.add_image() adds new image on no match"""
     # setup ------------------------
     pkg = Package.open(images_pptx_path)
     expected_partname = '/ppt/media/image8.png'
     expected_len = len(pkg._images) + 1
     expected_sha1 = '79769f1e202add2e963158b532e36c2c0f76a70c'
     # exercise ---------------------
     image = pkg._images.add_image(new_image_path)
     # verify -----------------------
     expected = (expected_partname, expected_len, expected_sha1)
     actual = (image.partname, len(pkg._images), image._sha1)
     msg = "\nExpected: %s\n     Got: %s" % (expected, actual)
     self.assertEqual(expected, actual, msg)
Ejemplo n.º 13
0
 def test_add_image_adds_new_image(self):
     """ImageCollection.add_image() adds new image on no match"""
     # setup ------------------------
     pkg = Package.open(images_pptx_path)
     expected_partname = '/ppt/media/image8.png'
     expected_len = len(pkg._images) + 1
     expected_sha1 = '79769f1e202add2e963158b532e36c2c0f76a70c'
     # exercise ---------------------
     image = pkg._images.add_image(new_image_path)
     # verify -----------------------
     expected = (expected_partname, expected_len, expected_sha1)
     actual = (image.partname, len(pkg._images), image._sha1)
     msg = "\nExpected: %s\n     Got: %s" % (expected, actual)
     self.assertEqual(expected, actual, msg)
Ejemplo n.º 14
0
 def image_part_fixture(self, _image_parts_, image_part_):
     package = Package()
     image_file = 'foobar.png'
     package._image_parts.get_or_add_image_part.return_value = image_part_
     return package, image_file, image_part_
Ejemplo n.º 15
0
 def __init__(self, pkg_file=None):
     super(Presentation, self).__init__()
     self._package = Package.open(pkg_file)
     self._presentation = self._package.presentation
Ejemplo n.º 16
0
 def m_parts_fixture(self, _MediaParts_, media_parts_):
     package = Package()
     _MediaParts_.return_value = media_parts_
     return package, _MediaParts_, media_parts_
Ejemplo n.º 17
0
 def media_part_fixture(self, media_, media_part_, _media_parts_prop_,
                        media_parts_):
     package = Package()
     _media_parts_prop_.return_value = media_parts_
     media_parts_.get_or_add_media_part.return_value = media_part_
     return package, media_, media_part_
Ejemplo n.º 18
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open('pptx/templates/default.pptx')
     assert isinstance(pkg.core_properties, CorePropertiesPart)
Ejemplo n.º 19
0
def step_then_img_saved_in_pptx_file(context):
    pkg = Package().open(saved_pptx_path)
    partnames = [part.partname for part in pkg.parts]
    assert_that(partnames, has_item('/ppt/media/image1.png'))
Ejemplo n.º 20
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
Ejemplo n.º 21
0
 def it_gathers_package_image_parts_on_open(self):
     pkg = Package.open(images_pptx_path)
     assert len(pkg._images) == 7
Ejemplo n.º 22
0
 def it_provides_ref_to_package_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
Ejemplo n.º 23
0
 def it_provides_ref_to_package_presentation_part(self):
     pkg = Package.open()
     assert isinstance(pkg.presentation, PresentationPart)
Ejemplo n.º 24
0
 def it_provides_ref_to_package_presentation_part(self):
     pkg = Package.open()
     assert isinstance(pkg.presentation, PresentationPart)
Ejemplo n.º 25
0
 def it_gathers_package_image_parts_on_open(self):
     pkg = Package.open(images_pptx_path)
     assert len(pkg._images) == 7
Ejemplo n.º 26
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
Ejemplo n.º 27
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open("pptx/templates/default.pptx")
     assert isinstance(pkg.core_properties, CorePropertiesPart)
Ejemplo n.º 28
0
 def it_provides_ref_to_package_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
Ejemplo n.º 29
0
 def __init__(self, pkg_file=None):
     super(Presentation, self).__init__()
     self._package = Package.open(pkg_file)
     self._presentation = self._package.presentation