2
2
3
3
from __future__ import annotations
4
4
5
+ from typing import cast
6
+
7
+ import pytest
8
+
9
+ from docx .comments import Comments
5
10
from docx .opc .constants import CONTENT_TYPE as CT
11
+ from docx .opc .packuri import PackURI
12
+ from docx .oxml .comments import CT_Comments
6
13
from docx .package import Package
7
14
from docx .parts .comments import CommentsPart
8
15
16
+ from ..unitutil .cxml import element
17
+ from ..unitutil .mock import FixtureRequest , Mock , class_mock , instance_mock
18
+
9
19
10
20
class DescribeCommentsPart :
11
21
"""Unit test suite for `docx.parts.comments.CommentsPart` objects."""
12
22
23
+ def it_provides_access_to_its_comments_collection (
24
+ self , Comments_ : Mock , comments_ : Mock , package_ : Mock
25
+ ):
26
+ Comments_ .return_value = comments_
27
+ comments_elm = cast (CT_Comments , element ("w:comments" ))
28
+ comments_part = CommentsPart (
29
+ PackURI ("/word/comments.xml" ), CT .WML_COMMENTS , comments_elm , package_
30
+ )
31
+
32
+ comments = comments_part .comments
33
+
34
+ Comments_ .assert_called_once_with (comments_part .element , comments_part )
35
+ assert comments is comments_
36
+
13
37
def it_constructs_a_default_comments_part_to_help (self ):
14
38
package = Package ()
15
39
@@ -23,3 +47,17 @@ def it_constructs_a_default_comments_part_to_help(self):
23
47
"{http://schemas.openxmlformats.org/wordprocessingml/2006/main}comments"
24
48
)
25
49
assert len (comments_part .element ) == 0
50
+
51
+ # -- fixtures --------------------------------------------------------------------------------
52
+
53
+ @pytest .fixture
54
+ def Comments_ (self , request : FixtureRequest ) -> Mock :
55
+ return class_mock (request , "docx.parts.comments.Comments" )
56
+
57
+ @pytest .fixture
58
+ def comments_ (self , request : FixtureRequest ) -> Mock :
59
+ return instance_mock (request , Comments )
60
+
61
+ @pytest .fixture
62
+ def package_ (self , request : FixtureRequest ) -> Mock :
63
+ return instance_mock (request , Package )
0 commit comments