def _read_and_get_document_xml_element(*args, **kwargs):
    body_reader = body_xml.reader()
    result = read_document_xml_element(*args,
                                       body_reader=body_reader,
                                       **kwargs)
    assert_equal([], result.messages)
    return result.value
    def warning_if_unsupported_image_type(self, context):
        drawing_element = _create_inline_image(
            relationship_id="rId5",
            description="It's a hat",
        )

        image_bytes = b"Not an image at all!"

        relationships = Relationships(
            {"rId5": Relationship(target="media/hat.emf")})

        docx_file = context.mock()
        funk.allows(docx_file).open("word/media/hat.emf").returns(
            io.BytesIO(image_bytes))

        content_types = context.mock()
        funk.allows(content_types).find_content_type(
            "word/media/hat.emf").returns("image/x-emf")

        result = read_document_xml_element(
            drawing_element,
            content_types=content_types,
            relationships=relationships,
            docx_file=docx_file,
        )
        assert_equal("image/x-emf", result.value[0].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)
 def warning_if_unsupported_image_type(self, context):
     drawing_element = _create_inline_image(
         relationship_id="rId5",
         description="It's a hat",
     )
     
     image_bytes = b"Not an image at all!"
     
     relationships = Relationships({
         "rId5": Relationship(target="media/hat.emf")
     })
     
     docx_file = context.mock()
     funk.allows(docx_file).open("word/media/hat.emf").returns(io.BytesIO(image_bytes))
     
     content_types = context.mock()
     funk.allows(content_types).find_content_type("word/media/hat.emf").returns("image/x-emf")
     
     result = read_document_xml_element(
         drawing_element,
         content_types=content_types,
         relationships=relationships,
         docx_file=docx_file,
     )
     assert_equal("image/x-emf", result.value[0].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)
def _read_and_get_document_xml_element(*args, **kwargs):
    result = read_document_xml_element(*args, **kwargs)
    assert_equal([], result.messages)
    return result.value
 def unrecognised_children_are_ignored(self):
     element = xml_element("w:r", {}, [_text_element("Hello!"), xml_element("w:huh", {}, [])])
     assert_equal(
         documents.run([documents.Text("Hello!")]),
         read_document_xml_element(element).value
     )
 def unrecognised_elements_are_ignored(self):
     element = xml_element("w:huh", {}, [])
     assert_equal(None, read_document_xml_element(element).value)
 def unrecognised_elements_emit_warning(self):
     element = xml_element("w:huh", {}, [])
     result = read_document_xml_element(element)
     expected_warning = results.warning("An unrecognised element was ignored: w:huh")
     assert_equal([expected_warning], result.messages)
 def ignored_elements_are_ignored_without_message(self):
     element = xml_element("w:bookmarkStart")
     result = read_document_xml_element(element)
     assert_equal(None, result.value)
     assert_equal([], result.messages)
 def warning_on_breaks_that_arent_line_breaks(self):
     break_element = xml_element("w:br", {"w:type": "page"}, [])
     result = read_document_xml_element(break_element)
     expected_warning = results.warning("Unsupported break type: page")
     assert_equal([expected_warning], result.messages)
     assert_equal(None, result.value)
 def unrecognised_children_are_ignored(self):
     element = xml_element(
         "w:r", {}, [_text_element("Hello!"),
                     xml_element("w:huh", {}, [])])
     assert_equal(documents.run([documents.Text("Hello!")]),
                  read_document_xml_element(element).value)
 def unrecognised_elements_are_ignored(self):
     element = xml_element("w:huh", {}, [])
     assert_equal(None, read_document_xml_element(element).value)
 def unrecognised_elements_emit_warning(self):
     element = xml_element("w:huh", {}, [])
     result = read_document_xml_element(element)
     expected_warning = results.warning(
         "An unrecognised element was ignored: w:huh")
     assert_equal([expected_warning], result.messages)
 def ignored_elements_are_ignored_without_message(self):
     element = xml_element("w:bookmarkStart")
     result = read_document_xml_element(element)
     assert_equal(None, result.value)
     assert_equal([], result.messages)
 def warning_on_breaks_that_arent_line_breaks(self):
     break_element = xml_element("w:br", {"w:type": "page"}, [])
     result = read_document_xml_element(break_element)
     expected_warning = results.warning("Unsupported break type: page")
     assert_equal([expected_warning], result.messages)
     assert_equal(None, result.value)