diff options
| -rw-r--r-- | tests/docx/body_xml_tests.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 4cd54eb..0429805 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -1058,10 +1058,9 @@ class ImageTests(object): @istest - def alt_text_title_is_used_if_alt_text_description_is_blank(self): + def alt_text_title_is_used_if_alt_text_description_is_missing(self): drawing_element = _create_inline_image( blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID), - description=" ", title="It's a hat", ) @@ -1075,9 +1074,10 @@ class ImageTests(object): @istest - def alt_text_title_is_used_if_alt_text_description_is_missing(self): + def alt_text_title_is_used_if_alt_text_description_is_blank(self): drawing_element = _create_inline_image( blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID), + description=" ", title="It's a hat", ) @@ -1124,63 +1124,63 @@ class ImageTests(object): @istest @funk.with_mocks - def warning_if_unsupported_image_type(self, mocks): + def can_read_linked_pictures(self, mocks): drawing_element = _create_inline_image( - blip=_embedded_blip("rId5"), + blip=_linked_blip("rId5"), description="It's a hat", ) relationships = Relationships([ - _image_relationship("rId5", "media/hat.emf"), + _image_relationship("rId5", "file:///media/hat.png"), ]) - docx_file = mocks.mock() - funk.allows(docx_file).open("word/media/hat.emf").returns(io.BytesIO(self.IMAGE_BYTES)) + files = mocks.mock() + funk.allows(files).verify("file:///media/hat.png") + funk.allows(files).open("file:///media/hat.png").returns(io.BytesIO(self.IMAGE_BYTES)) content_types = mocks.mock() - funk.allows(content_types).find_content_type("word/media/hat.emf").returns("image/x-emf") + funk.allows(content_types).find_content_type("file:///media/hat.png").returns("image/png") - result = _read_document_xml_element( + image = _read_and_get_document_xml_element( drawing_element, content_types=content_types, relationships=relationships, - docx_file=docx_file, + files=files, ) - assert_equal("image/x-emf", result.value.content_type) - expected_warning = results.warning("Image of type image/x-emf is unlikely to display in web browsers") - assert_equal([expected_warning], result.messages) + assert_equal(documents.Image, type(image)) + assert_equal("It's a hat", image.alt_text) + assert_equal("image/png", image.content_type) + with image.open() as image_file: + assert_equal(self.IMAGE_BYTES, image_file.read()) @istest @funk.with_mocks - def can_read_linked_pictures(self, mocks): + def warning_if_unsupported_image_type(self, mocks): drawing_element = _create_inline_image( - blip=_linked_blip("rId5"), + blip=_embedded_blip("rId5"), description="It's a hat", ) relationships = Relationships([ - _image_relationship("rId5", "file:///media/hat.png"), + _image_relationship("rId5", "media/hat.emf"), ]) - files = mocks.mock() - funk.allows(files).verify("file:///media/hat.png") - funk.allows(files).open("file:///media/hat.png").returns(io.BytesIO(self.IMAGE_BYTES)) + docx_file = mocks.mock() + funk.allows(docx_file).open("word/media/hat.emf").returns(io.BytesIO(self.IMAGE_BYTES)) content_types = mocks.mock() - funk.allows(content_types).find_content_type("file:///media/hat.png").returns("image/png") + funk.allows(content_types).find_content_type("word/media/hat.emf").returns("image/x-emf") - image = _read_and_get_document_xml_element( + result = _read_document_xml_element( drawing_element, content_types=content_types, relationships=relationships, - files=files, + docx_file=docx_file, ) - assert_equal(documents.Image, type(image)) - assert_equal("It's a hat", image.alt_text) - assert_equal("image/png", image.content_type) - with image.open() as image_file: - assert_equal(self.IMAGE_BYTES, image_file.read()) + assert_equal("image/x-emf", result.value.content_type) + expected_warning = results.warning("Image of type image/x-emf is unlikely to display in web browsers") + assert_equal([expected_warning], result.messages) @istest |
