| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,17 @@ def when_I_assign_comment_eq_comments_add_comment_with_author_and_initials(conte | |||
| 63 | 63 | context.comment = context.comments.add_comment(author="John Doe", initials="JD") | |
| 64 | 64 | ||
| 65 | 65 | ||
| 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 | + | ||
| 66 | 77 | @when('I assign "{initials}" to comment.initials') | |
| 67 | 78 | def when_I_assign_initials(context: Context, initials: str): | |
| 68 | 79 | context.comment.initials = initials | |
@@ -98,10 +109,9 @@ def when_I_call_comments_get_2(context: Context): | |||
| 98 | 109 | # then ===================================================== | |
| 99 | 110 | ||
| 100 | 111 | ||
| 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 | ||
| 105 | 115 | ||
| 106 | 116 | ||
| 107 | 117 | @then('comment.author == "{author}"') | |
@@ -110,6 +120,12 @@ def then_comment_author_eq_author(context: Context, author: str): | |||
| 110 | 120 | assert actual == author, f"expected author '{author}', got '{actual}'" | |
| 111 | 121 | ||
| 112 | 122 | ||
| 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 | + | ||
| 113 | 129 | @then("comment.comment_id == 0") | |
| 114 | 130 | def then_comment_id_is_0(context: Context): | |
| 115 | 131 | assert context.comment.comment_id == 0 | |
@@ -146,6 +162,13 @@ def then_comment_paragraphs_idx_style_name_eq_style(context: Context, idx: str, | |||
| 146 | 162 | assert actual == expected, f"expected style name '{expected}', got '{actual}'" | |
| 147 | 163 | ||
| 148 | 164 | ||
| 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 | + | ||
| 149 | 172 | @then("comment.timestamp is the date and time the comment was authored") | |
| 150 | 173 | def then_comment_timestamp_is_the_date_and_time_the_comment_was_authored(context: Context): | |
| 151 | 174 | assert context.comment.timestamp == dt.datetime(2025, 6, 7, 11, 20, 0, tzinfo=dt.timezone.utc) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | """Step implementations for document settings-related features.""" | |
| 2 | 2 | ||
| 3 | 3 | from behave import given, then, when | |
| 4 | + from behave.runner import Context | ||
| 4 | 5 | ||
| 5 | 6 | from docx import Document | |
| 6 | 7 | from docx.settings import Settings | |
@@ -11,17 +12,19 @@ | |||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | 14 | @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): | ||
| 15 | 16 | context.document = Document(test_docx("doc-word-default-blank")) | |
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | 19 | @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): | ||
| 20 | 21 | context.document = Document(test_docx("set-no-settings-part")) | |
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | @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 | + ): | ||
| 25 | 28 | testfile_name = {"with": "doc-odd-even-hdrs", "without": "sct-section-props"}[with_or_without] | |
| 26 | 29 | context.settings = Document(test_docx(testfile_name)).settings | |
| 27 | 30 | ||
@@ -30,21 +33,23 @@ def given_a_Settings_object_with_or_without_odd_and_even_hdrs(context, with_or_w | |||
| 30 | 33 | ||
| 31 | 34 | ||
| 32 | 35 | @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 | + ): | ||
| 34 | 39 | context.settings.odd_and_even_pages_header_footer = eval(bool_val) | |
| 35 | 40 | ||
| 36 | 41 | ||
| 37 | 42 | # then ===================================================== | |
| 38 | 43 | ||
| 39 | 44 | ||
| 40 | 45 | @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): | ||
| 42 | 47 | document = context.document | |
| 43 | 48 | assert type(document.settings) is Settings | |
| 44 | 49 | ||
| 45 | 50 | ||
| 46 | 51 | @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): | ||
| 48 | 53 | actual = context.settings.odd_and_even_pages_header_footer | |
| 49 | 54 | expected = eval(bool_val) | |
| 50 | 55 | assert actual == expected, "settings.odd_and_even_pages_header_footer is %s" % actual | |
| Back | FazBrowse Home | New Git URL |
0 commit comments