|
12 | 12 |
|
13 | 13 | from docx.enum.style import WD_STYLE_TYPE |
14 | 14 | from docx.oxml.styles import CT_Style, CT_Styles |
| 15 | +from docx.styles.latent import LatentStyles |
15 | 16 | from docx.styles.style import BaseStyle |
16 | 17 | from docx.styles.styles import Styles |
17 | 18 |
|
18 | 19 | from ..unitutil.cxml import element |
19 | | -from ..unitutil.mock import call, function_mock, instance_mock, method_mock |
| 20 | +from ..unitutil.mock import ( |
| 21 | + call, class_mock, function_mock, instance_mock, method_mock |
| 22 | +) |
20 | 23 |
|
21 | 24 |
|
22 | 25 | class DescribeStyles(object): |
@@ -135,6 +138,12 @@ def it_raises_on_style_type_mismatch(self, id_style_raises_fixture): |
135 | 138 | with pytest.raises(ValueError): |
136 | 139 | styles._get_style_id_from_style(style_, style_type) |
137 | 140 |
|
| 141 | + def it_provides_access_to_the_latent_styles(self, latent_styles_fixture): |
| 142 | + styles, LatentStyles_, latent_styles_ = latent_styles_fixture |
| 143 | + latent_styles = styles.latent_styles |
| 144 | + LatentStyles_.assert_called_once_with(styles._element.latentStyles) |
| 145 | + assert latent_styles is latent_styles_ |
| 146 | + |
138 | 147 | # fixture -------------------------------------------------------- |
139 | 148 |
|
140 | 149 | @pytest.fixture(params=[ |
@@ -319,6 +328,11 @@ def iter_fixture(self, request, StyleFactory_, style_): |
319 | 328 | StyleFactory_.return_value = style_ |
320 | 329 | return styles, expected_count, style_, StyleFactory_, expected_calls |
321 | 330 |
|
| 331 | + @pytest.fixture |
| 332 | + def latent_styles_fixture(self, LatentStyles_, latent_styles_): |
| 333 | + styles = Styles(element('w:styles/w:latentStyles')) |
| 334 | + return styles, LatentStyles_, latent_styles_ |
| 335 | + |
322 | 336 | @pytest.fixture(params=[ |
323 | 337 | ('w:styles', 0), |
324 | 338 | ('w:styles/w:style', 1), |
@@ -352,6 +366,17 @@ def _get_style_id_from_name_(self, request): |
352 | 366 | def _get_style_id_from_style_(self, request): |
353 | 367 | return method_mock(request, Styles, '_get_style_id_from_style') |
354 | 368 |
|
| 369 | + @pytest.fixture |
| 370 | + def LatentStyles_(self, request, latent_styles_): |
| 371 | + return class_mock( |
| 372 | + request, 'docx.styles.styles.LatentStyles', |
| 373 | + return_value=latent_styles_ |
| 374 | + ) |
| 375 | + |
| 376 | + @pytest.fixture |
| 377 | + def latent_styles_(self, request): |
| 378 | + return instance_mock(request, LatentStyles) |
| 379 | + |
355 | 380 | @pytest.fixture |
356 | 381 | def style_(self, request): |
357 | 382 | return instance_mock(request, BaseStyle) |
|
0 commit comments