99 absolute_import , division , print_function , unicode_literals
1010)
1111
12- from docx .text .tabstops import TabStops
12+ from docx .text .tabstops import TabStop , TabStops
1313
1414import pytest
1515
1616from ..unitutil .cxml import element
17+ from ..unitutil .mock import call , class_mock , instance_mock
1718
1819
1920class DescribeTabStops (object ):
@@ -22,8 +23,32 @@ def it_knows_its_length(self, len_fixture):
2223 tab_stops , expected_value = len_fixture
2324 assert len (tab_stops ) == expected_value
2425
26+ def it_can_iterate_over_its_tab_stops (self , iter_fixture ):
27+ tab_stops , expected_count , tab_stop_ , TabStop_ , expected_calls = (
28+ iter_fixture
29+ )
30+ count = 0
31+ for tab_stop in tab_stops :
32+ assert tab_stop is tab_stop_
33+ count += 1
34+ assert count == expected_count
35+ assert TabStop_ .call_args_list == expected_calls
36+
2537 # fixture --------------------------------------------------------
2638
39+ @pytest .fixture (params = [
40+ ('w:pPr' , 0 ),
41+ ('w:pPr/w:tabs/w:tab{w:pos=2880}' , 1 ),
42+ ('w:pPr/w:tabs/(w:tab{w:pos=2880},w:tab{w:pos=5760})' , 2 ),
43+ ])
44+ def iter_fixture (self , request , TabStop_ , tab_stop_ ):
45+ pPr_cxml , expected_count = request .param
46+ pPr = element (pPr_cxml )
47+ tab_elms = pPr .xpath ('//w:tab' )
48+ tab_stops = TabStops (pPr )
49+ expected_calls = [call (tab ) for tab in tab_elms ]
50+ return tab_stops , expected_count , tab_stop_ , TabStop_ , expected_calls
51+
2752 @pytest .fixture (params = [
2853 ('w:pPr' , 0 ),
2954 ('w:pPr/w:tabs/w:tab{w:pos=2880}' , 1 ),
@@ -32,3 +57,15 @@ def len_fixture(self, request):
3257 tab_stops_cxml , expected_value = request .param
3358 tab_stops = TabStops (element (tab_stops_cxml ))
3459 return tab_stops , expected_value
60+
61+ # fixture components ---------------------------------------------
62+
63+ @pytest .fixture
64+ def TabStop_ (self , request , tab_stop_ ):
65+ return class_mock (
66+ request , 'docx.text.tabstops.TabStop' , return_value = tab_stop_
67+ )
68+
69+ @pytest .fixture
70+ def tab_stop_ (self , request ):
71+ return instance_mock (request , TabStop )
0 commit comments