예제 #1
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
    ]
예제 #2
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
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
0
 def __init__(self, pkg_file=None):
     super(Presentation, self).__init__()
     self._package = Package.open(pkg_file)
     self._presentation = self._package.presentation
예제 #11
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open('pptx/templates/default.pptx')
     assert isinstance(pkg.core_properties, CorePropertiesPart)
예제 #12
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open("pptx/templates/default.pptx")
     assert isinstance(pkg.core_properties, CorePropertiesPart)
예제 #13
0
 def it_provides_ref_to_package_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
예제 #14
0
 def it_gathers_package_image_parts_on_open(self):
     pkg = Package.open(images_pptx_path)
     assert len(pkg._images) == 7
예제 #15
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
예제 #16
0
 def it_provides_ref_to_package_presentation_part(self):
     pkg = Package.open()
     assert isinstance(pkg.presentation, PresentationPart)
예제 #17
0
 def it_gathers_package_image_parts_on_open(self):
     pkg = Package.open(images_pptx_path)
     assert len(pkg._images) == 7
예제 #18
0
 def it_provides_ref_to_package_presentation_part(self):
     pkg = Package.open()
     assert isinstance(pkg.presentation, PresentationPart)
예제 #19
0
 def it_provides_access_to_its_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
예제 #20
0
 def it_provides_ref_to_package_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
예제 #21
0
 def __init__(self, pkg_file=None):
     super(Presentation, self).__init__()
     self._package = Package.open(pkg_file)
     self._presentation = self._package.presentation