22
33from __future__ import annotations
44
5+ from typing import cast
6+
7+ import pytest
8+
9+ from docx .comments import Comments
510from docx .opc .constants import CONTENT_TYPE as CT
11+ from docx .opc .packuri import PackURI
12+ from docx .oxml .comments import CT_Comments
613from docx .package import Package
714from docx .parts .comments import CommentsPart
815
16+ from ..unitutil .cxml import element
17+ from ..unitutil .mock import FixtureRequest , Mock , class_mock , instance_mock
18+
919
1020class DescribeCommentsPart :
1121 """Unit test suite for `docx.parts.comments.CommentsPart` objects."""
1222
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+
1337 def it_constructs_a_default_comments_part_to_help (self ):
1438 package = Package ()
1539
@@ -23,3 +47,17 @@ def it_constructs_a_default_comments_part_to_help(self):
2347 "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}comments"
2448 )
2549 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