@@ -30,6 +30,11 @@ def given_a_comments_object_with_count_comments(context: Context, count: str):
30
30
context .comments = Document (test_docx (testfile_name )).comments
31
31
32
32
33
+ @given ("a default Comment object" )
34
+ def given_a_default_comment_object (context : Context ):
35
+ context .comment = Document (test_docx ("comments-rich-para" )).comments .add_comment ()
36
+
37
+
33
38
@given ("a document having a comments part" )
34
39
def given_a_document_having_a_comments_part (context : Context ):
35
40
context .document = Document (test_docx ("comments-rich-para" ))
@@ -43,11 +48,48 @@ def given_a_document_having_no_comments_part(context: Context):
43
48
# when =====================================================
44
49
45
50
51
+ @when ('I assign "{author}" to comment.author' )
52
+ def when_I_assign_author_to_comment_author (context : Context , author : str ):
53
+ context .comment .author = author
54
+
55
+
56
+ @when ("I assign comment = comments.add_comment()" )
57
+ def when_I_assign_comment_eq_add_comment (context : Context ):
58
+ context .comment = context .comments .add_comment ()
59
+
60
+
61
+ @when ('I assign comment = comments.add_comment(author="John Doe", initials="JD")' )
62
+ def when_I_assign_comment_eq_comments_add_comment_with_author_and_initials (context : Context ):
63
+ context .comment = context .comments .add_comment (author = "John Doe" , initials = "JD" )
64
+
65
+
66
+ @when ('I assign "{initials}" to comment.initials' )
67
+ def when_I_assign_initials (context : Context , initials : str ):
68
+ context .comment .initials = initials
69
+
70
+
46
71
@when ("I assign para_text = comment.paragraphs[0].text" )
47
72
def when_I_assign_para_text (context : Context ):
48
73
context .para_text = context .comment .paragraphs [0 ].text
49
74
50
75
76
+ @when ("I assign paragraph = comment.add_paragraph()" )
77
+ def when_I_assign_default_add_paragraph (context : Context ):
78
+ context .paragraph = context .comment .add_paragraph ()
79
+
80
+
81
+ @when ("I assign paragraph = comment.add_paragraph(text, style)" )
82
+ def when_I_assign_add_paragraph_with_text_and_style (context : Context ):
83
+ context .para_text = text = "Comment text"
84
+ context .para_style = style = "Normal"
85
+ context .paragraph = context .comment .add_paragraph (text , style )
86
+
87
+
88
+ @when ("I assign run = paragraph.add_run()" )
89
+ def when_I_assign_paragraph_add_run (context : Context ):
90
+ context .run = context .paragraph .add_run ()
91
+
92
+
51
93
@when ("I call comments.get(2)" )
52
94
def when_I_call_comments_get_2 (context : Context ):
53
95
context .comment = context .comments .get (2 )
@@ -62,6 +104,17 @@ def then_comment_author_is_the_author_of_the_comment(context: Context):
62
104
assert actual == "Steve Canny" , f"expected author 'Steve Canny', got '{ actual } '"
63
105
64
106
107
+ @then ('comment.author == "{author}"' )
108
+ def then_comment_author_eq_author (context : Context , author : str ):
109
+ actual = context .comment .author
110
+ assert actual == author , f"expected author '{ author } ', got '{ actual } '"
111
+
112
+
113
+ @then ("comment.comment_id == 0" )
114
+ def then_comment_id_is_0 (context : Context ):
115
+ assert context .comment .comment_id == 0
116
+
117
+
65
118
@then ("comment.comment_id is the comment identifier" )
66
119
def then_comment_comment_id_is_the_comment_identifier (context : Context ):
67
120
assert context .comment .comment_id == 0
@@ -73,11 +126,42 @@ def then_comment_initials_is_the_initials_of_the_comment_author(context: Context
73
126
assert initials == "SJC" , f"expected initials 'SJC', got '{ initials } '"
74
127
75
128
129
+ @then ('comment.initials == "{initials}"' )
130
+ def then_comment_initials_eq_initials (context : Context , initials : str ):
131
+ actual = context .comment .initials
132
+ assert actual == initials , f"expected initials '{ initials } ', got '{ actual } '"
133
+
134
+
135
+ @then ("comment.paragraphs[{idx}] == paragraph" )
136
+ def then_comment_paragraphs_idx_eq_paragraph (context : Context , idx : str ):
137
+ actual = context .comment .paragraphs [int (idx )]._p
138
+ expected = context .paragraph ._p
139
+ assert actual == expected , "paragraphs do not compare equal"
140
+
141
+
142
+ @then ('comment.paragraphs[{idx}].style.name == "{style}"' )
143
+ def then_comment_paragraphs_idx_style_name_eq_style (context : Context , idx : str , style : str ):
144
+ actual = context .comment .paragraphs [int (idx )]._p .style
145
+ expected = style
146
+ assert actual == expected , f"expected style name '{ expected } ', got '{ actual } '"
147
+
148
+
76
149
@then ("comment.timestamp is the date and time the comment was authored" )
77
150
def then_comment_timestamp_is_the_date_and_time_the_comment_was_authored (context : Context ):
78
151
assert context .comment .timestamp == dt .datetime (2025 , 6 , 7 , 11 , 20 , 0 , tzinfo = dt .timezone .utc )
79
152
80
153
154
+ @then ("comments.get({id}) == comment" )
155
+ def then_comments_get_comment_id_eq_comment (context : Context , id : str ):
156
+ comment_id = int (id )
157
+ comment = context .comments .get (comment_id )
158
+
159
+ assert type (comment ) is Comment , f"expected a Comment object, got { type (comment )} "
160
+ assert comment .comment_id == comment_id , (
161
+ f"expected comment_id '{ comment_id } ', got '{ comment .comment_id } '"
162
+ )
163
+
164
+
81
165
@then ("document.comments is a Comments object" )
82
166
def then_document_comments_is_a_Comments_object (context : Context ):
83
167
document = context .document
@@ -109,6 +193,13 @@ def then_iterating_comments_yields_count_comments(context: Context, count: str):
109
193
assert len (remaining ) == int (count ) - 1 , "iterating comments did not yield the expected count"
110
194
111
195
196
+ @then ("len(comment.paragraphs) == {count}" )
197
+ def then_len_comment_paragraphs_eq_count (context : Context , count : str ):
198
+ actual = len (context .comment .paragraphs )
199
+ expected = int (count )
200
+ assert actual == expected , f"expected len(comment.paragraphs) of { expected } , got { actual } "
201
+
202
+
112
203
@then ("len(comments) == {count}" )
113
204
def then_len_comments_eq_count (context : Context , count : str ):
114
205
actual = len (context .comments )
@@ -123,6 +214,46 @@ def then_para_text_is_the_text_of_the_first_paragraph_in_the_comment(context: Co
123
214
assert actual == expected , f"expected para_text '{ expected } ', got '{ actual } '"
124
215
125
216
217
+ @then ("paragraph.style == style" )
218
+ def then_paragraph_style_eq_known_style (context : Context ):
219
+ actual = context .paragraph .style .name
220
+ expected = context .para_style
221
+ assert actual == expected , f"expected paragraph.style '{ expected } ', got '{ actual } '"
222
+
223
+
224
+ @then ('paragraph.style == "{style}"' )
225
+ def then_paragraph_style_eq_style (context : Context , style : str ):
226
+ actual = context .paragraph ._p .style
227
+ expected = style
228
+ assert actual == expected , f"expected paragraph.style '{ expected } ', got '{ actual } '"
229
+
230
+
231
+ @then ("paragraph.text == text" )
232
+ def then_paragraph_text_eq_known_text (context : Context ):
233
+ actual = context .paragraph .text
234
+ expected = context .para_text
235
+ assert actual == expected , f"expected paragraph.text '{ expected } ', got '{ actual } '"
236
+
237
+
238
+ @then ('paragraph.text == ""' )
239
+ def then_paragraph_text_eq_text (context : Context ):
240
+ actual = context .paragraph .text
241
+ expected = ""
242
+ assert actual == expected , f"expected paragraph.text '{ expected } ', got '{ actual } '"
243
+
244
+
245
+ @then ("run.iter_inner_content() yields a single Picture drawing" )
246
+ def then_run_iter_inner_content_yields_a_single_picture_drawing (context : Context ):
247
+ inner_content = list (context .run .iter_inner_content ())
248
+
249
+ assert len (inner_content ) == 1 , (
250
+ f"expected a single inner content element, got { len (inner_content )} "
251
+ )
252
+ inner_content_item = inner_content [0 ]
253
+ assert isinstance (inner_content_item , Drawing )
254
+ assert inner_content_item .has_picture
255
+
256
+
126
257
@then ("the result is a Comment object with id 2" )
127
258
def then_the_result_is_a_comment_object_with_id_2 (context : Context ):
128
259
comment = context .comment
0 commit comments