Skip to content

Commit 66da522

Browse files
committed
xfail: acceptance test for Document.add_comment()
1 parent 761f4cc commit 66da522

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

features/doc-add-comment.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: Add a comment to a document
2+
In order add a comment to a document
3+
As a developer using python-docx
4+
I need a way to add a comment specifying both its content and its reference
5+
6+
7+
@wip
8+
Scenario: Document.add_comment(runs, text, author, initials)
9+
Given a document having a comments part
10+
When I assign comment = document.add_comment(runs, "A comment", "John Doe", "JD")
11+
Then comment is a Comment object
12+
And comment.text == "A comment"
13+
And comment.author == "John Doe"
14+
And comment.initials == "JD"

features/steps/comments.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ def when_I_assign_comment_eq_comments_add_comment_with_author_and_initials(conte
6363
context.comment = context.comments.add_comment(author="John Doe", initials="JD")
6464

6565

66+
@when('I assign comment = document.add_comment(runs, "A comment", "John Doe", "JD")')
67+
def when_I_assign_comment_eq_document_add_comment(context: Context):
68+
runs = list(context.document.paragraphs[0].runs)
69+
context.comment = context.document.add_comment(
70+
runs=runs,
71+
text="A comment",
72+
author="John Doe",
73+
initials="JD",
74+
)
75+
76+
6677
@when('I assign "{initials}" to comment.initials')
6778
def when_I_assign_initials(context: Context, initials: str):
6879
context.comment.initials = initials
@@ -98,10 +109,9 @@ def when_I_call_comments_get_2(context: Context):
98109
# then =====================================================
99110

100111

101-
@then("comment.author is the author of the comment")
102-
def then_comment_author_is_the_author_of_the_comment(context: Context):
103-
actual = context.comment.author
104-
assert actual == "Steve Canny", f"expected author 'Steve Canny', got '{actual}'"
112+
@then("comment is a Comment object")
113+
def then_comment_is_a_Comment_object(context: Context):
114+
assert type(context.comment) is Comment
105115

106116

107117
@then('comment.author == "{author}"')
@@ -110,6 +120,12 @@ def then_comment_author_eq_author(context: Context, author: str):
110120
assert actual == author, f"expected author '{author}', got '{actual}'"
111121

112122

123+
@then("comment.author is the author of the comment")
124+
def then_comment_author_is_the_author_of_the_comment(context: Context):
125+
actual = context.comment.author
126+
assert actual == "Steve Canny", f"expected author 'Steve Canny', got '{actual}'"
127+
128+
113129
@then("comment.comment_id == 0")
114130
def then_comment_id_is_0(context: Context):
115131
assert context.comment.comment_id == 0
@@ -146,6 +162,13 @@ def then_comment_paragraphs_idx_style_name_eq_style(context: Context, idx: str,
146162
assert actual == expected, f"expected style name '{expected}', got '{actual}'"
147163

148164

165+
@then('comment.text == "{text}"')
166+
def then_comment_text_eq_text(context: Context, text: str):
167+
actual = context.comment.text
168+
expected = text
169+
assert actual == expected, f"expected text '{expected}', got '{actual}'"
170+
171+
149172
@then("comment.timestamp is the date and time the comment was authored")
150173
def then_comment_timestamp_is_the_date_and_time_the_comment_was_authored(context: Context):
151174
assert context.comment.timestamp == dt.datetime(2025, 6, 7, 11, 20, 0, tzinfo=dt.timezone.utc)

features/steps/settings.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Step implementations for document settings-related features."""
22

33
from behave import given, then, when
4+
from behave.runner import Context
45

56
from docx import Document
67
from docx.settings import Settings
@@ -11,17 +12,19 @@
1112

1213

1314
@given("a document having a settings part")
14-
def given_a_document_having_a_settings_part(context):
15+
def given_a_document_having_a_settings_part(context: Context):
1516
context.document = Document(test_docx("doc-word-default-blank"))
1617

1718

1819
@given("a document having no settings part")
19-
def given_a_document_having_no_settings_part(context):
20+
def given_a_document_having_no_settings_part(context: Context):
2021
context.document = Document(test_docx("set-no-settings-part"))
2122

2223

2324
@given("a Settings object {with_or_without} odd and even page headers as settings")
24-
def given_a_Settings_object_with_or_without_odd_and_even_hdrs(context, with_or_without):
25+
def given_a_Settings_object_with_or_without_odd_and_even_hdrs(
26+
context: Context, with_or_without: str
27+
):
2528
testfile_name = {"with": "doc-odd-even-hdrs", "without": "sct-section-props"}[with_or_without]
2629
context.settings = Document(test_docx(testfile_name)).settings
2730

@@ -30,21 +33,23 @@ def given_a_Settings_object_with_or_without_odd_and_even_hdrs(context, with_or_w
3033

3134

3235
@when("I assign {bool_val} to settings.odd_and_even_pages_header_footer")
33-
def when_I_assign_value_to_settings_odd_and_even_pages_header_footer(context, bool_val):
36+
def when_I_assign_value_to_settings_odd_and_even_pages_header_footer(
37+
context: Context, bool_val: str
38+
):
3439
context.settings.odd_and_even_pages_header_footer = eval(bool_val)
3540

3641

3742
# then =====================================================
3843

3944

4045
@then("document.settings is a Settings object")
41-
def then_document_settings_is_a_Settings_object(context):
46+
def then_document_settings_is_a_Settings_object(context: Context):
4247
document = context.document
4348
assert type(document.settings) is Settings
4449

4550

4651
@then("settings.odd_and_even_pages_header_footer is {bool_val}")
47-
def then_settings_odd_and_even_pages_header_footer_is(context, bool_val):
52+
def then_settings_odd_and_even_pages_header_footer_is(context: Context, bool_val: str):
4853
actual = context.settings.odd_and_even_pages_header_footer
4954
expected = eval(bool_val)
5055
assert actual == expected, "settings.odd_and_even_pages_header_footer is %s" % actual

0 commit comments

Comments
 (0)