File: test_styles.py

package info (click to toggle)
python-docx 1.1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,904 kB
  • sloc: xml: 25,311; python: 23,028; makefile: 176
file content (43 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Test suite for the docx.oxml.styles module."""

import pytest

from docx.enum.style import WD_STYLE_TYPE

from ..unitutil.cxml import element, xml


class DescribeCT_Styles:
    def it_can_add_a_style_of_type(self, add_fixture):
        styles, name, style_type, builtin, expected_xml = add_fixture
        style = styles.add_style_of_type(name, style_type, builtin)
        assert styles.xml == expected_xml
        assert style is styles[-1]

    # fixtures -------------------------------------------------------

    @pytest.fixture(
        params=[
            (
                "w:styles",
                "Foo Bar",
                WD_STYLE_TYPE.LIST,
                False,
                "w:styles/w:style{w:type=numbering,w:customStyle=1,w:styleId=FooBar"
                "}/w:name{w:val=Foo Bar}",
            ),
            (
                "w:styles",
                "heading 1",
                WD_STYLE_TYPE.PARAGRAPH,
                True,
                "w:styles/w:style{w:type=paragraph,w:styleId=Heading1}/w:name{w:val"
                "=heading 1}",
            ),
        ]
    )
    def add_fixture(self, request):
        styles_cxml, name, style_type, builtin, expected_cxml = request.param
        styles = element(styles_cxml)
        expected_xml = xml(expected_cxml)
        return styles, name, style_type, builtin, expected_xml