|
9 | 9 | import pytest |
10 | 10 |
|
11 | 11 | from docx.compat import BytesIO |
12 | | -from docx.image import Image_OLD |
13 | 12 | from docx.image.bmp import Bmp |
14 | 13 | from docx.image.exceptions import UnrecognizedImageError |
15 | 14 | from docx.image.gif import Gif |
@@ -98,6 +97,20 @@ def it_knows_the_sha1_of_its_image(self): |
98 | 97 | image = Image(blob, None, None) |
99 | 98 | assert image.sha1 == '4921e7002ddfba690a937d54bda226a7b8bdeb68' |
100 | 99 |
|
| 100 | + def it_correctly_characterizes_known_images(self, known_image_fixture): |
| 101 | + image_path, characteristics = known_image_fixture |
| 102 | + ext, content_type, px_width, px_height, horz_dpi, vert_dpi = ( |
| 103 | + characteristics |
| 104 | + ) |
| 105 | + with open(test_file(image_path), 'rb') as stream: |
| 106 | + image = Image.from_file(stream) |
| 107 | + assert image.content_type == content_type |
| 108 | + assert image.ext == ext |
| 109 | + assert image.px_width == px_width |
| 110 | + assert image.px_height == px_height |
| 111 | + assert image.horz_dpi == horz_dpi |
| 112 | + assert image.vert_dpi == vert_dpi |
| 113 | + |
101 | 114 | # fixtures ------------------------------------------------------- |
102 | 115 |
|
103 | 116 | @pytest.fixture |
@@ -191,6 +204,23 @@ def image_header_(self, request): |
191 | 204 | def Image__init_(self, request): |
192 | 205 | return initializer_mock(request, Image) |
193 | 206 |
|
| 207 | + @pytest.fixture(params=[0, 1, 2, 3, 4, 5, 6, 7, 8]) |
| 208 | + def known_image_fixture(self, request): |
| 209 | + cases = ( |
| 210 | + ('python.bmp', ('bmp', CT.BMP, 211, 71, 96, 96)), |
| 211 | + ('sonic.gif', ('gif', CT.GIF, 290, 360, 72, 72)), |
| 212 | + ('python-icon.jpeg', ('jpg', CT.JPEG, 204, 204, 72, 72)), |
| 213 | + ('300-dpi.jpg', ('jpg', CT.JPEG, 1504, 1936, 300, 300)), |
| 214 | + ('monty-truth.png', ('png', CT.PNG, 150, 214, 72, 72)), |
| 215 | + ('150-dpi.png', ('png', CT.PNG, 901, 1350, 150, 150)), |
| 216 | + ('300-dpi.png', ('png', CT.PNG, 860, 579, 300, 300)), |
| 217 | + ('72-dpi.tiff', ('tiff', CT.TIFF, 48, 48, 72, 72)), |
| 218 | + ('300-dpi.TIF', ('tiff', CT.TIFF, 2464, 3248, 300, 300)), |
| 219 | + # ('CVS_LOGO.WMF', ('wmf', CT.X_WMF, 149, 59, 72, 72)), |
| 220 | + ) |
| 221 | + image_filename, characteristics = cases[request.param] |
| 222 | + return image_filename, characteristics |
| 223 | + |
194 | 224 | @pytest.fixture |
195 | 225 | def stream_(self, request): |
196 | 226 | return instance_mock(request, BytesIO) |
@@ -253,66 +283,3 @@ def it_knows_the_horz_and_vert_dpi_of_the_image(self): |
253 | 283 | image_header = BaseImageHeader(None, None, horz_dpi, vert_dpi) |
254 | 284 | assert image_header.horz_dpi == horz_dpi |
255 | 285 | assert image_header.vert_dpi == vert_dpi |
256 | | - |
257 | | - |
258 | | -class DescribeImage_OLD(object): |
259 | | - |
260 | | - def it_can_construct_from_an_image_path(self): |
261 | | - image_file_path = test_file('monty-truth.png') |
262 | | - image = Image_OLD.from_file(image_file_path) |
263 | | - assert isinstance(image, Image_OLD) |
264 | | - assert image.sha1 == '79769f1e202add2e963158b532e36c2c0f76a70c' |
265 | | - assert image.filename == 'monty-truth.png' |
266 | | - |
267 | | - def it_can_construct_from_an_image_stream(self): |
268 | | - image_file_path = test_file('monty-truth.png') |
269 | | - with open(image_file_path, 'rb') as image_file_stream: |
270 | | - image = Image_OLD.from_file(image_file_stream) |
271 | | - assert isinstance(image, Image_OLD) |
272 | | - assert image.sha1 == '79769f1e202add2e963158b532e36c2c0f76a70c' |
273 | | - assert image.filename == 'image.png' |
274 | | - |
275 | | - def it_knows_the_extension_of_a_file_based_image(self): |
276 | | - image_file_path = test_file('monty-truth.png') |
277 | | - image = Image_OLD.from_file(image_file_path) |
278 | | - assert image.ext == 'png' |
279 | | - |
280 | | - def it_knows_the_extension_of_a_stream_based_image(self): |
281 | | - image_file_path = test_file('monty-truth.png') |
282 | | - with open(image_file_path, 'rb') as image_file_stream: |
283 | | - image = Image_OLD.from_file(image_file_stream) |
284 | | - assert image.ext == 'png' |
285 | | - |
286 | | - def it_correctly_characterizes_a_few_known_images( |
287 | | - self, known_image_fixture): |
288 | | - image_path, characteristics = known_image_fixture |
289 | | - ext, content_type, px_width, px_height, horz_dpi, vert_dpi = ( |
290 | | - characteristics |
291 | | - ) |
292 | | - with open(test_file(image_path), 'rb') as stream: |
293 | | - image = Image_OLD.from_file(stream) |
294 | | - assert image.ext == ext |
295 | | - assert image.content_type == content_type |
296 | | - assert image.px_width == px_width |
297 | | - assert image.px_height == px_height |
298 | | - assert image.horz_dpi == horz_dpi |
299 | | - assert image.vert_dpi == vert_dpi |
300 | | - |
301 | | - # fixtures ------------------------------------------------------- |
302 | | - |
303 | | - @pytest.fixture(params=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
304 | | - def known_image_fixture(self, request): |
305 | | - cases = ( |
306 | | - ('python.bmp', ('bmp', CT.BMP, 211, 71, 72, 72)), |
307 | | - ('sonic.gif', ('gif', CT.GIF, 290, 360, 72, 72)), |
308 | | - ('python-icon.jpeg', ('jpg', CT.JPEG, 204, 204, 72, 72)), |
309 | | - ('300-dpi.jpg', ('jpg', CT.JPEG, 1504, 1936, 300, 300)), |
310 | | - ('monty-truth.png', ('png', CT.PNG, 150, 214, 72, 72)), |
311 | | - ('150-dpi.png', ('png', CT.PNG, 901, 1350, 150, 150)), |
312 | | - ('300-dpi.png', ('png', CT.PNG, 860, 579, 300, 300)), |
313 | | - ('72-dpi.tiff', ('tiff', CT.TIFF, 48, 48, 72, 72)), |
314 | | - ('300-dpi.TIF', ('tiff', CT.TIFF, 2464, 3248, 300, 300)), |
315 | | - ('CVS_LOGO.WMF', ('wmf', CT.X_WMF, 149, 59, 72, 72)), |
316 | | - ) |
317 | | - image_filename, characteristics = cases[request.param] |
318 | | - return image_filename, characteristics |
0 commit comments