|
12 | 12 | from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING
|
13 | 13 | from docx.shared import Pt
|
14 | 14 | from docx.text.parfmt import ParagraphFormat
|
| 15 | +from docx.text.tabstops import TabStops |
15 | 16 |
|
16 | 17 | import pytest
|
17 | 18 |
|
18 | 19 | from ..unitutil.cxml import element, xml
|
| 20 | +from ..unitutil.mock import class_mock, instance_mock |
19 | 21 |
|
20 | 22 |
|
21 | 23 | class DescribeParagraphFormat(object):
|
@@ -102,6 +104,17 @@ def it_can_change_its_on_off_props(self, on_off_set_fixture):
|
102 | 104 | setattr(paragraph_format, prop_name, value)
|
103 | 105 | assert paragraph_format._element.xml == expected_xml
|
104 | 106 |
|
| 107 | + def it_provides_access_to_its_tab_stops(self, tab_stops_fixture): |
| 108 | + paragraph_format, TabStops_, pPr, tab_stops_ = tab_stops_fixture |
| 109 | + tab_stops = paragraph_format.tab_stops |
| 110 | + TabStops_.assert_called_once_with(pPr, paragraph_format) |
| 111 | + assert tab_stops is tab_stops_ |
| 112 | + |
| 113 | + def it_reuses_the_tab_stops_object(self, tab_stops_lazy_fixture): |
| 114 | + paragraph_format, initial_tab_stops = tab_stops_lazy_fixture |
| 115 | + tab_stops = paragraph_format.tab_stops |
| 116 | + assert tab_stops is initial_tab_stops |
| 117 | + |
105 | 118 | # fixtures -------------------------------------------------------
|
106 | 119 |
|
107 | 120 | @pytest.fixture(params=[
|
@@ -393,3 +406,28 @@ def space_before_set_fixture(self, request):
|
393 | 406 | paragraph_format = ParagraphFormat(element(p_cxml))
|
394 | 407 | expected_xml = xml(expected_p_cxml)
|
395 | 408 | return paragraph_format, value, expected_xml
|
| 409 | + |
| 410 | + @pytest.fixture |
| 411 | + def tab_stops_fixture(self, TabStops_, tab_stops_): |
| 412 | + p = element('w:p/w:pPr') |
| 413 | + pPr = p.pPr |
| 414 | + paragraph_format = ParagraphFormat(p, None) |
| 415 | + return paragraph_format, TabStops_, pPr, tab_stops_ |
| 416 | + |
| 417 | + @pytest.fixture |
| 418 | + def tab_stops_lazy_fixture(self): |
| 419 | + paragraph_format = ParagraphFormat(element('w:p'), None) |
| 420 | + original_tab_stops = paragraph_format.tab_stops |
| 421 | + return paragraph_format, original_tab_stops |
| 422 | + |
| 423 | + # fixture components --------------------------------------------- |
| 424 | + |
| 425 | + @pytest.fixture |
| 426 | + def TabStops_(self, request, tab_stops_): |
| 427 | + return class_mock( |
| 428 | + request, 'docx.text.parfmt.TabStops', return_value=tab_stops_ |
| 429 | + ) |
| 430 | + |
| 431 | + @pytest.fixture |
| 432 | + def tab_stops_(self, request): |
| 433 | + return instance_mock(request, TabStops) |
0 commit comments