def it_can_construct_from_an_image_blob(self, blob_, BytesIO_, _from_stream_, stream_, image_): image = Image.from_blob(blob_) BytesIO_.assert_called_once_with(blob_) _from_stream_.assert_called_once_with(stream_, blob_) assert image is image_
def it_can_construct_from_an_image_stream(self, from_stream_fixture): stream_, blob_, filename_in = from_stream_fixture[:3] _ImageHeaderFactory_, image_header_ = from_stream_fixture[3:5] Image__init_, filename_out = from_stream_fixture[5:] image = Image._from_stream(stream_, blob_, filename_in) _ImageHeaderFactory_.assert_called_once_with(stream_) Image__init_.assert_called_once_with(ANY, blob_, filename_out, image_header_) assert isinstance(image, Image)
def get_or_add_image_part(self, image_descriptor): """Return |ImagePart| object containing image identified by *image_descriptor*. The image-part is 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)
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
def it_knows_the_image_content_type(self, content_type_fixture): image_header_, content_type = content_type_fixture image = Image(None, None, image_header_) assert image.content_type == content_type
def it_provides_access_to_the_image_blob(self): blob = b'foobar' image = Image(blob, None, None) assert image.blob == blob
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_
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_
def scale_fixture(self, request, width_prop_, height_prop_): width, height, scaled_width, scaled_height = request.param width_prop_.return_value = Emu(1000) height_prop_.return_value = Emu(2000) image = Image(None, None, None) return image, width, height, (scaled_width, scaled_height)
def it_knows_the_sha1_of_its_image(self): blob = b'fO0Bar' image = Image(blob, None, None) assert image.sha1 == '4921e7002ddfba690a937d54bda226a7b8bdeb68'
def it_knows_the_image_filename_extension(self): image = Image(None, 'foobar.png', None) assert image.ext == 'png'
def it_knows_the_image_filename(self): filename = 'foobar.png' image = Image(None, filename, None) assert image.filename == filename
def it_knows_the_image_px_dimensions(self, dimensions_fixture): image_header_, px_width, px_height = dimensions_fixture image = Image(None, None, image_header_) assert image.px_width == px_width assert image.px_height == px_height
def size_fixture(self, image_header_): image_header_.px_width, image_header_.px_height = 150, 75 image_header_.horz_dpi, image_header_.vert_dpi = 72, 200 image = Image(None, None, image_header_) return image, 1905000, 342900
def it_knows_the_horz_and_vert_dpi_of_the_image(self, dpi_fixture): image_header_, horz_dpi, vert_dpi = dpi_fixture image = Image(None, None, image_header_) assert image.horz_dpi == horz_dpi assert image.vert_dpi == vert_dpi
def image(self): if self._image is None: self._image = Image.from_blob(self.blob) return self._image