|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Step implementations for image characterization features |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import absolute_import, print_function, unicode_literals |
| 8 | + |
| 9 | +from behave import given, then, when |
| 10 | + |
| 11 | +from docx.image.image import Image |
| 12 | + |
| 13 | +from helpers import test_file_path |
| 14 | + |
| 15 | + |
| 16 | +# given =================================================== |
| 17 | + |
| 18 | +@given('the image file \'{filename}\'') |
| 19 | +def given_image_filename(context, filename): |
| 20 | + context.image_path = test_file_path(filename) |
| 21 | + |
| 22 | + |
| 23 | +# when ==================================================== |
| 24 | + |
| 25 | +@when('I construct an image using the image path') |
| 26 | +def when_construct_image_using_path(context): |
| 27 | + context.image = Image.from_file(context.image_path) |
| 28 | + |
| 29 | + |
| 30 | +# then ==================================================== |
| 31 | + |
| 32 | +@then('the image has content type \'{mime_type}\'') |
| 33 | +def then_image_has_content_type(context, mime_type): |
| 34 | + content_type = context.image.content_type |
| 35 | + assert content_type == mime_type, ( |
| 36 | + "expected MIME type '%s', got '%s'" % (mime_type, content_type) |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +@then('the image has {horz_dpi_str} horizontal dpi') |
| 41 | +def then_image_has_horizontal_dpi(context, horz_dpi_str): |
| 42 | + expected_horz_dpi = int(horz_dpi_str) |
| 43 | + horz_dpi = context.image.horz_dpi |
| 44 | + assert horz_dpi == expected_horz_dpi, ( |
| 45 | + "expected horizontal dpi %d, got %d" % (expected_horz_dpi, horz_dpi) |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +@then('the image has {vert_dpi_str} vertical dpi') |
| 50 | +def then_image_has_vertical_dpi(context, vert_dpi_str): |
| 51 | + expected_vert_dpi = int(vert_dpi_str) |
| 52 | + vert_dpi = context.image.vert_dpi |
| 53 | + assert vert_dpi == expected_vert_dpi, ( |
| 54 | + "expected vertical dpi %d, got %d" % (expected_vert_dpi, vert_dpi) |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +@then('the image is {px_height_str} pixels high') |
| 59 | +def then_image_is_cx_pixels_high(context, px_height_str): |
| 60 | + expected_px_height = int(px_height_str) |
| 61 | + px_height = context.image.px_height |
| 62 | + assert px_height == expected_px_height, ( |
| 63 | + "expected pixel height %d, got %d" % (expected_px_height, px_height) |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +@then('the image is {px_width_str} pixels wide') |
| 68 | +def then_image_is_cx_pixels_wide(context, px_width_str): |
| 69 | + expected_px_width = int(px_width_str) |
| 70 | + px_width = context.image.px_width |
| 71 | + assert px_width == expected_px_width, ( |
| 72 | + "expected pixel width %d, got %d" % (expected_px_width, px_width) |
| 73 | + ) |
0 commit comments