Example #1
0
 def filename_fixture(self, request, image_):
     partname = PackURI('/word/media/image666.png')
     if request.param == 'loaded':
         image_part = ImagePart(partname, None, None, None)
         expected_filename = 'image.png'
     elif request.param == 'new':
         image_.filename = 'foobar.PXG'
         image_part = ImagePart(partname, None, None, image_)
         expected_filename = image_.filename
     return image_part, expected_filename
Example #2
0
 def it_can_construct_from_an_Image_instance(self, from_image_fixture):
     image_, partname_, ImagePart__init__ = from_image_fixture
     image_part = ImagePart.from_image(image_, partname_)
     ImagePart__init__.assert_called_once_with(
         partname_, image_.content_type, image_.blob, image_
     )
     assert isinstance(image_part, ImagePart)
Example #3
0
 def it_can_construct_from_an_Image_instance(self, from_image_fixture):
     image_, partname_, ImagePart__init__ = from_image_fixture
     image_part = ImagePart.from_image(image_, partname_)
     ImagePart__init__.assert_called_once_with(partname_,
                                               image_.content_type,
                                               image_.blob, image_)
     assert isinstance(image_part, ImagePart)
Example #4
0
    def dimensions_fixture(self, request):
        image_file_path = test_file('monty-truth.png')
        image = Image.from_file(image_file_path)
        expected_cx, expected_cy = 1905000, 2717800

        # case 1: image part is loaded by PartFactory w/no Image inst
        if request.param == 'loaded':
            partname = PackURI('/word/media/image1.png')
            content_type = CT.PNG
            image_part = ImagePart.load(partname, content_type, image.blob,
                                        None)
        # case 2: image part is newly created from image file
        elif request.param == 'new':
            image_part = ImagePart.from_image(image, None)

        return image_part, expected_cx, expected_cy
    def it_can_construct_from_an_Image_instance(self, image_, partname_,
                                                _init_):
        image_part = ImagePart.from_image(image_, partname_)

        _init_.assert_called_once_with(ANY, partname_, image_.content_type,
                                       image_.blob, image_)
        assert isinstance(image_part, ImagePart)
Example #6
0
    def dimensions_fixture(self, request):
        image_file_path = test_file('monty-truth.png')
        image = Image.from_file(image_file_path)
        expected_cx, expected_cy = 1905000, 2717800

        # case 1: image part is loaded by PartFactory w/no Image inst
        if request.param == 'loaded':
            partname = PackURI('/word/media/image1.png')
            content_type = CT.PNG
            image_part = ImagePart.load(
                partname, content_type, image.blob, None
            )
        # case 2: image part is newly created from image file
        elif request.param == 'new':
            image_part = ImagePart.from_image(image, None)

        return image_part, expected_cx, expected_cy
Example #7
0
 def _add_image_part(self, image):
     """
     Return an |ImagePart| instance newly created from image and appended
     to the collection.
     """
     partname = self._next_image_partname(image.ext)
     image_part = ImagePart.from_image(image, partname)
     self.append(image_part)
     return image_part
Example #8
0
 def _add_image_part(self, image):
     """
     Return an |ImagePart| instance newly created from image and appended
     to the collection.
     """
     partname = self._next_image_partname(image.ext)
     image_part = ImagePart.from_image(image, partname)
     self.append(image_part)
     return image_part
Example #9
0
 def _get_parts(self):
     parts = []
     pkg_meta = self._get_pkg_meta()
     for part_name, content_type in pkg_meta:
         blob = self.blob_for(part_name)
         if 'image' in content_type:
             image = Image(blob, None, None, content_type)
             part = ImagePart.from_image(image, PackURI(part_name))
         else:
             part = XmlPart.load(PackURI(part_name), content_type, blob,
                                 None)
         parts.append(part)
     return parts
Example #10
0
 def it_knows_the_sha1_of_its_image(self):
     blob = b'fO0Bar'
     image_part = ImagePart(None, None, blob)
     assert image_part.sha1 == '4921e7002ddfba690a937d54bda226a7b8bdeb68'