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
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 ]
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
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_
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 ]
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
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
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)
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)
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_
def __init__(self, pkg_file=None): super(Presentation, self).__init__() self._package = Package.open(pkg_file) self._presentation = self._package.presentation
def m_parts_fixture(self, _MediaParts_, media_parts_): package = Package() _MediaParts_.return_value = media_parts_ return package, _MediaParts_, media_parts_
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_
def it_provides_access_to_its_core_properties_part(self): pkg = Package.open('pptx/templates/default.pptx') assert isinstance(pkg.core_properties, CorePropertiesPart)
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'))
def it_provides_access_to_its_core_properties_part(self): pkg = Package.open() assert isinstance(pkg.core_properties, CoreProperties)
def it_gathers_package_image_parts_on_open(self): pkg = Package.open(images_pptx_path) assert len(pkg._images) == 7
def it_provides_ref_to_package_core_properties_part(self): pkg = Package.open() assert isinstance(pkg.core_properties, CoreProperties)
def it_provides_ref_to_package_presentation_part(self): pkg = Package.open() assert isinstance(pkg.presentation, PresentationPart)
def it_provides_access_to_its_core_properties_part(self): pkg = Package.open("pptx/templates/default.pptx") assert isinstance(pkg.core_properties, CorePropertiesPart)