|
17 | 17 | ) |
18 | 18 |
|
19 | 19 | from ..unitutil.cxml import element, xml |
20 | | -from ..unitutil.mock import class_mock, instance_mock |
| 20 | +from ..unitutil.mock import call, class_mock, function_mock, instance_mock |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class DescribeStyleFactory(object): |
@@ -198,3 +198,44 @@ def type_get_fixture(self, request): |
198 | 198 | style_cxml, expected_value = request.param |
199 | 199 | style = BaseStyle(element(style_cxml)) |
200 | 200 | return style, expected_value |
| 201 | + |
| 202 | + |
| 203 | +class Describe_CharacterStyle(object): |
| 204 | + |
| 205 | + def it_knows_which_style_it_is_based_on(self, base_get_fixture): |
| 206 | + style, StyleFactory_, StyleFactory_calls, base_style_ = ( |
| 207 | + base_get_fixture |
| 208 | + ) |
| 209 | + base_style = style.base_style |
| 210 | + |
| 211 | + assert StyleFactory_.call_args_list == StyleFactory_calls |
| 212 | + assert base_style == base_style_ |
| 213 | + |
| 214 | + # fixture -------------------------------------------------------- |
| 215 | + |
| 216 | + @pytest.fixture(params=[ |
| 217 | + ('w:styles/(w:style{w:styleId=Foo},w:style/w:basedOn{w:val=Foo})', |
| 218 | + 1, 0), |
| 219 | + ('w:styles/(w:style{w:styleId=Foo},w:style/w:basedOn{w:val=Bar})', |
| 220 | + 1, -1), |
| 221 | + ('w:styles/w:style', |
| 222 | + 0, -1), |
| 223 | + ]) |
| 224 | + def base_get_fixture(self, request, StyleFactory_): |
| 225 | + styles_cxml, style_idx, base_style_idx = request.param |
| 226 | + styles = element(styles_cxml) |
| 227 | + style = _CharacterStyle(styles[style_idx]) |
| 228 | + if base_style_idx >= 0: |
| 229 | + base_style = styles[base_style_idx] |
| 230 | + StyleFactory_calls = [call(base_style)] |
| 231 | + expected_value = StyleFactory_.return_value |
| 232 | + else: |
| 233 | + StyleFactory_calls = [] |
| 234 | + expected_value = None |
| 235 | + return style, StyleFactory_, StyleFactory_calls, expected_value |
| 236 | + |
| 237 | + # fixture components --------------------------------------------- |
| 238 | + |
| 239 | + @pytest.fixture |
| 240 | + def StyleFactory_(self, request): |
| 241 | + return function_mock(request, 'docx.styles.style.StyleFactory') |
0 commit comments