def test_instance_refs_are_garbage_collected(self):
     """_Package instance refs are garbage collected with old instances"""
     pkg = _Package()
     pkg1_repr = "%r" % pkg
     pkg = _Package()
     # pkg2_repr = "%r" % pkg
     gc.collect()
     reprs = [repr(pkg_inst) for pkg_inst in _Package.instances()]
     # log.debug("pkg1, pkg2, reprs: %s, %s, %s"
     #           % (pkg1_repr, pkg2_repr, reprs))
     assert_that(pkg1_repr, is_not(is_in(reprs)))
 def test_containing_returns_correct_pkg(self):
     """_Package.containing() returns right package instance"""
     # setup ------------------------
     pkg1 = _Package(test_pptx_path)
     pkg1.presentation  # does nothing, just needed to fake out pep8 warning
     pkg2 = _Package(test_pptx_path)
     slide = pkg2.presentation.slides[0]
     # exercise ---------------------
     found_pkg = _Package.containing(slide)
     # verify -----------------------
     expected = pkg2
     actual = found_pkg
     msg = "expected %r, got %r" % (expected, actual)
     self.assertEqual(expected, actual, msg)
 def test_saved_file_has_plausible_contents(self):
     """_Package.save produces a .pptx with plausible contents"""
     # setup ------------------------
     pkg = _Package()
     # exercise ---------------------
     pkg.save(self.test_pptx_path)
     # verify -----------------------
     pkg = _Package(self.test_pptx_path)
     prs = pkg.presentation
     assert_that(prs, is_not(None))
     slidemasters = prs.slidemasters
     assert_that(slidemasters, is_not(None))
     assert_that(len(slidemasters), is_(1))
     slidelayouts = slidemasters[0].slidelayouts
     assert_that(slidelayouts, is_not(None))
     assert_that(len(slidelayouts), is_(11))
 def test_slides_correct_length_after_pkg_open(self):
     """Presentation.slides correct length after load"""
     # setup ------------------------
     pkg = _Package(test_pptx_path)
     prs = pkg.presentation
     # exercise ---------------------
     slides = prs.slides
     # verify -----------------------
     self.assertLength(slides, 1)
 def test_open_gathers_image_parts(self):
     """_Package open gathers image parts into image collection"""
     # exercise ---------------------
     pkg = _Package(images_pptx_path)
     # verify -----------------------
     expected = 7
     actual = len(pkg._Package__images)
     msg = "expected image count of %d, got %d" % (expected, actual)
     self.assertEqual(expected, actual, msg)
 def test_containing_raises_on_no_pkg_contains_part(self):
     """_Package.containing(part) raises on no package contains part"""
     # setup ------------------------
     pkg = _Package(test_pptx_path)
     pkg.presentation  # does nothing, just needed to fake out pep8 warning
     part = Mock(name='part')
     # verify -----------------------
     with self.assertRaises(KeyError):
         _Package.containing(part)
 def test_slidelayouts_correct_length_after_open(self):
     """_SlideMaster.slidelayouts correct length after open"""
     # setup ------------------------
     pkg = _Package(test_pptx_path)
     slidemaster = pkg.presentation.slidemasters[0]
     # exercise ---------------------
     slidelayouts = slidemaster.slidelayouts
     # verify -----------------------
     self.assertLength(slidelayouts, 11)
 def test_construction_with_no_path_loads_default_template(self):
     """_Package() call with no path loads default template"""
     prs = _Package().presentation
     assert_that(prs, is_not(None))
     slidemasters = prs.slidemasters
     assert_that(slidemasters, is_not(None))
     assert_that(len(slidemasters), is_(1))
     slidelayouts = slidemasters[0].slidelayouts
     assert_that(slidelayouts, is_not(None))
     assert_that(len(slidelayouts), is_(11))
 def test_presentation_presentation_after_open(self):
     """_Package.presentation is instance of Presentation after open()"""
     # setup ------------------------
     cls = Presentation
     pkg = _Package()
     # exercise ---------------------
     obj = pkg.presentation
     # verify -----------------------
     actual = isinstance(obj, cls)
     msg = ("expected instance of '%s', got type '%s'"
            % (cls.__name__, type(obj).__name__))
     self.assertTrue(actual, msg)
 def test_add_image_adds_new_image(self):
     """_ImageCollection.add_image() adds new image on no match"""
     # setup ------------------------
     pkg = _Package(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 test_add_image_returns_matching_image(self):
     """_ImageCollection.add_image() returns existing image on match"""
     # setup ------------------------
     pkg = _Package(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_it_should_have_core_props(self):
     """_Package should provide access to core document properties"""
     # setup ------------------------
     pkg = _Package()
     # verify -----------------------
     assert_that(pkg.core_properties, is_(instance_of(_CoreProperties)))
 def test_instances_are_tracked(self):
     """_Package instances are tracked"""
     pkg = _Package()
     self.assertIn(pkg, _Package.instances())
Example #14
0
 def __init__(self, file=None):
     super(Presentation, self).__init__()
     self.__package = _Package(file)
     self.__presentation = self.__package.presentation
Example #15
0
 def __init__(self, file=None):
     super(Presentation, self).__init__()
     self.__package = _Package(file)
     self.__presentation = self.__package.presentation