Exemple #1
0
 def it_can_construct_from_an_image_path(self, from_path_fixture):
     image_path, _from_stream_, stream_, blob, filename, image_ = (
         from_path_fixture
     )
     image = Image.from_file(image_path)
     _from_stream_.assert_called_once_with(stream_, blob, filename)
     assert image is image_
Exemple #2
0
 def replace_part(items, raw_items):
     for k, p in items:
         if path.basename(p.partname) == from_pic:
             image = Image.from_file(to_pic)
             partname = path.join(path.dirname(p.partname), image.filename)
             partname = PackURI(partname)
             img_part = ImagePart.from_image(image, partname)
             raw_items.__setitem__(k, img_part)
             break
Exemple #3
0
 def get_or_add_image_part(self, image_descriptor):
     """
     Return an |ImagePart| instance containing the image identified by
     *image_descriptor*, newly created if a matching one is not present in
     the collection.
     """
     image = Image.from_file(image_descriptor)
     matching_image_part = self._get_by_sha1(image.sha1)
     if matching_image_part is not None:
         return matching_image_part
     return self._add_image_part(image)
Exemple #4
0
 def get_or_add_image_part(self, image_descriptor):
     """
     Return an |ImagePart| instance containing the image identified by
     *image_descriptor*, newly created if a matching one is not present in
     the collection.
     """
     image = Image.from_file(image_descriptor)
     matching_image_part = self._get_by_sha1(image.sha1)
     if matching_image_part is not None:
         return matching_image_part
     return self._add_image_part(image)
Exemple #5
0
 def it_correctly_characterizes_known_images(self, known_image_fixture):
     image_path, characteristics = known_image_fixture
     ext, content_type, px_width, px_height, horz_dpi, vert_dpi = (
         characteristics)
     with open(test_file(image_path), 'rb') as stream:
         image = Image.from_file(stream)
         assert image.content_type == content_type
         assert image.ext == ext
         assert image.px_width == px_width
         assert image.px_height == px_height
         assert image.horz_dpi == horz_dpi
         assert image.vert_dpi == vert_dpi
Exemple #6
0
 def it_correctly_characterizes_known_images(self, known_image_fixture):
     image_path, characteristics = known_image_fixture
     ext, content_type, px_width, px_height, horz_dpi, vert_dpi = (
         characteristics
     )
     with open(test_file(image_path), 'rb') as stream:
         image = Image.from_file(stream)
         assert image.content_type == content_type
         assert image.ext == ext
         assert image.px_width == px_width
         assert image.px_height == px_height
         assert image.horz_dpi == horz_dpi
         assert image.vert_dpi == vert_dpi
    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
Exemple #8
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
Exemple #9
0
 def it_can_construct_from_an_image_file_like(self, from_filelike_fixture):
     image_stream, _from_stream_, blob, image_ = from_filelike_fixture
     image = Image.from_file(image_stream)
     _from_stream_.assert_called_once_with(image_stream, blob, None)
     assert image is image_
Exemple #10
0
def when_construct_image_using_path(context):
    context.image = Image.from_file(context.image_path)
Exemple #11
0
 def it_can_construct_from_an_image_file_like(self, from_filelike_fixture):
     image_stream, _from_stream_, blob, image_ = from_filelike_fixture
     image = Image.from_file(image_stream)
     _from_stream_.assert_called_once_with(image_stream, blob, None)
     assert image is image_