2
2
3
3
"""Test suite for the docx.bookmark module."""
4
4
5
- from __future__ import (
6
- absolute_import , division , print_function , unicode_literals
7
- )
5
+ from __future__ import absolute_import , division , print_function , unicode_literals
8
6
9
7
import pytest
10
8
11
- from docx .bookmark import Bookmarks , _DocumentBookmarkFinder
12
- from docx .opc .part import Part
9
+ from docx .bookmark import Bookmarks , _DocumentBookmarkFinder , _PartBookmarkFinder
10
+ from docx .opc .part import Part , XmlPart
13
11
from docx .parts .document import DocumentPart
14
12
15
- from .unitutil .mock import call , class_mock , instance_mock , property_mock
13
+ from .unitutil .mock import (
14
+ ANY ,
15
+ call ,
16
+ class_mock ,
17
+ initializer_mock ,
18
+ instance_mock ,
19
+ method_mock ,
20
+ property_mock ,
21
+ )
16
22
17
23
18
24
class DescribeBookmarks (object ):
19
25
20
26
def it_knows_how_many_bookmarks_the_document_contains (
21
- self , _finder_prop_ , finder_ ):
27
+ self , _finder_prop_ , finder_
28
+ ):
22
29
_finder_prop_ .return_value = finder_
23
30
finder_ .bookmark_pairs = tuple ((1 , 2 ) for _ in range (42 ))
24
31
bookmarks = Bookmarks (None )
@@ -28,7 +35,8 @@ def it_knows_how_many_bookmarks_the_document_contains(
28
35
assert count == 42
29
36
30
37
def it_provides_access_to_its_bookmark_finder_to_help (
31
- self , document_part_ , _DocumentBookmarkFinder_ , finder_ ):
38
+ self , document_part_ , _DocumentBookmarkFinder_ , finder_
39
+ ):
32
40
_DocumentBookmarkFinder_ .return_value = finder_
33
41
bookmarks = Bookmarks (document_part_ )
34
42
@@ -105,3 +113,29 @@ def _PartBookmarkFinder_(self, request):
105
113
@pytest .fixture
106
114
def document_part_ (self , request ):
107
115
return instance_mock (request , DocumentPart )
116
+
117
+
118
+ class Describe_PartBookmarkFinder (object ):
119
+
120
+ def it_provides_an_iter_start_end_pairs_interface_method (
121
+ self , part_ , _init_ , _iter_start_end_pairs_
122
+ ):
123
+ pairs = _PartBookmarkFinder .iter_start_end_pairs (part_ )
124
+
125
+ _init_ .assert_called_once_with (ANY , part_ )
126
+ _iter_start_end_pairs_ .assert_called_once_with ()
127
+ assert pairs == _iter_start_end_pairs_ .return_value
128
+
129
+ # fixture components ---------------------------------------------
130
+
131
+ @pytest .fixture
132
+ def _init_ (self , request ):
133
+ return initializer_mock (request , _PartBookmarkFinder )
134
+
135
+ @pytest .fixture
136
+ def _iter_start_end_pairs_ (self , request ):
137
+ return method_mock (request , _PartBookmarkFinder , '_iter_start_end_pairs' )
138
+
139
+ @pytest .fixture
140
+ def part_ (self , request ):
141
+ return instance_mock (request , XmlPart )
0 commit comments