From 36e3ce588ad6f55d28a52ff9e10b6bfdb52e0a7b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Jul 2016 12:20:25 +0100 Subject: Add stubbed author_name and author_initials to Comment --- mammoth/documents.py | 2 ++ mammoth/docx/comments_xml.py | 4 +++- tests/docx/comments_xml_tests.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mammoth/documents.py b/mammoth/documents.py index ea376d4..93b080c 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -177,6 +177,8 @@ note_reference = NoteReference class Comment(object): comment_id = cobble.field() body = cobble.field() + author_name = cobble.field() + author_initials = cobble.field() comment = Comment diff --git a/mammoth/docx/comments_xml.py b/mammoth/docx/comments_xml.py index 9a92552..fbf1bc4 100644 --- a/mammoth/docx/comments_xml.py +++ b/mammoth/docx/comments_xml.py @@ -13,7 +13,9 @@ def create_comments_reader(body_reader): return body_reader.read_all(element.children).map(lambda body: documents.comment( comment_id=element.attributes["w:id"], - body=body + body=body, + author_name=None, + author_initials=None, )) return read_comments_xml_element diff --git a/tests/docx/comments_xml_tests.py b/tests/docx/comments_xml_tests.py index 2970922..5025a21 100644 --- a/tests/docx/comments_xml_tests.py +++ b/tests/docx/comments_xml_tests.py @@ -16,3 +16,12 @@ def id_and_body_of_comment_is_read(): assert_equal(comments.value[0].body, [documents.paragraph(children=[])]) assert_equal("1", comments.value[0].comment_id) + +@istest +def when_optional_attributes_of_comment_are_missing_then_they_are_as_none(): + comments = create_comments_reader(body_xml.reader())(xml_element("w:comments", {}, [ + xml_element("w:comment", {"w:id": "1"}, []), + ])) + comment, = comments.value + assert_equal(None, comment.author_name) + assert_equal(None, comment.author_initials) -- cgit v1.2.3