Skip to content

Commit f9cacf3

Browse files
author
Steve Canny
committed
style: add LatentStyles.load_count getter
1 parent c6ee527 commit f9cacf3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

docx/oxml/styles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CT_LatentStyles(BaseOxmlElement):
3838
"""
3939
lsdException = ZeroOrMore('w:lsdException', successors=())
4040

41+
count = OptionalAttribute('w:count', ST_DecimalNumber)
4142
defUIPriority = OptionalAttribute('w:defUIPriority', ST_DecimalNumber)
4243

4344
def get_by_name(self, name):

docx/styles/latent.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ def default_priority(self):
4444
"""
4545
return self._element.defUIPriority
4646

47+
@property
48+
def load_count(self):
49+
"""
50+
Integer specifying the number of built-in styles to initialize to the
51+
defaults specified in this |LatentStyles| object. |None| if there is
52+
no setting in the XML (very uncommon). The default Word 2011 template
53+
sets this value to 276, accounting for the built-in styles in Word
54+
2010.
55+
"""
56+
return self._element.count
57+
4758

4859
class _LatentStyle(ElementProxy):
4960
"""

tests/styles/test_latent.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,21 @@ def it_knows_its_default_priority(self, priority_get_fixture):
4343
latent_styles, expected_value = priority_get_fixture
4444
assert latent_styles.default_priority == expected_value
4545

46+
def it_knows_its_load_count(self, count_get_fixture):
47+
latent_styles, expected_value = count_get_fixture
48+
assert latent_styles.load_count == expected_value
49+
4650
# fixture --------------------------------------------------------
4751

52+
@pytest.fixture(params=[
53+
('w:latentStyles', None),
54+
('w:latentStyles{w:count=42}', 42),
55+
])
56+
def count_get_fixture(self, request):
57+
latentStyles_cxml, expected_value = request.param
58+
latent_styles = LatentStyles(element(latentStyles_cxml))
59+
return latent_styles, expected_value
60+
4861
@pytest.fixture(params=[
4962
('w:lsdException{w:name=Ab},w:lsdException,w:lsdException', 'Ab', 0),
5063
('w:lsdException,w:lsdException{w:name=Cd},w:lsdException', 'Cd', 1),

0 commit comments

Comments
 (0)