def _pil_props(self): """ A tuple containing useful image properties extracted from this image using Pillow (Python Imaging Library, or 'PIL'). """ stream = BytesIO(self._blob) pil_image = PIL_Image.open(stream) format = pil_image.format width_px, height_px = pil_image.size dpi = pil_image.info.get("dpi") stream.close() return (format, (width_px, height_px), dpi)
def macStyle_fixture(self): bytes_ = b"xxxxyyyy....................................\xF0\xBA........" stream = _Stream(BytesIO(bytes_)) offset, length = 0, len(bytes_) head_table = _HeadTable(None, stream, offset, length) expected_value = 61626 return head_table, expected_value
def from_stream_fixture(self, video_, from_blob_): with open(TEST_VIDEO_PATH, "rb") as f: blob = f.read() movie_stream = BytesIO(blob) mime_type = "video/mp4" from_blob_.return_value = video_ return movie_stream, mime_type, blob, video_
def it_can_open_a_worksheet_in_a_context(self): xlsx_file = BytesIO() with WorkbookWriter._open_worksheet(xlsx_file) as worksheet: assert isinstance(worksheet, Worksheet) zipf = ZipFile(xlsx_file) assert 'xl/worksheets/sheet1.xml' in zipf.namelist() zipf.close
def it_constructs_ZipPkgReader_when_pkg_is_file_like( self, _ZipPkgReader_, zip_pkg_reader_): _ZipPkgReader_.return_value = zip_pkg_reader_ file_like_pkg = BytesIO(b"pkg-bytes") phys_reader = _PhysPkgReader.factory(file_like_pkg) _ZipPkgReader_.assert_called_once_with(file_like_pkg) assert phys_reader is zip_pkg_reader_
def _poster_frame_image_file(self): """Return the image file for video placeholder image. If no poster frame file is provided, the default "media loudspeaker" image is used. """ poster_frame_file = self._poster_frame_file if poster_frame_file is None: return BytesIO(SPEAKER_IMAGE_BYTES) return poster_frame_file
def it_can_write_a_blob(self, _zipf_prop_): """Integrates with zipfile.ZipFile.""" pack_uri = PackURI("/part/name.xml") _zipf_prop_.return_value = zipf = zipfile.ZipFile(BytesIO(), "w") pkg_writer = _ZipPkgWriter(None) pkg_writer.write(pack_uri, b"blob") members = { PackURI("/%s" % name): zipf.read(name) for name in zipf.namelist() } assert len(members) == 1 assert members[pack_uri] == b"blob"
def when_open_presentation_stream(context): with open(test_pptx("test"), "rb") as f: stream = BytesIO(f.read()) context.prs = Presentation(stream) stream.close()
def when_save_presentation_to_stream(context): context.stream = BytesIO() context.prs.save(context.stream)
def when_I_add_the_stream_image_filename_using_add_picture(context, filename): shapes = context.slide.shapes with open(test_image(filename), "rb") as f: stream = BytesIO(f.read()) shapes.add_picture(stream, Inches(1.25), Inches(1.25))
def when_open_presentation_stream(context): with open(test_pptx('test'), 'rb') as f: stream = BytesIO(f.read()) context.prs = Presentation(stream) stream.close()
def from_stream_fixture(self, from_blob_, image_): with open(test_image_path, 'rb') as f: blob = f.read() image_file = BytesIO(blob) from_blob_.return_value = image_ return image_file, blob, image_