Skip to content

Commit bb948db

Browse files
author
Steve Canny
committed
style: add Styles.__len__()
1 parent 587a8a3 commit bb948db

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

docx/styles/styles.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ class Styles(ElementProxy):
1919
"""
2020

2121
__slots__ = ()
22+
23+
def __len__(self):
24+
return len(self._element.style_lst)

tests/styles/__init__.py

Whitespace-only changes.

tests/styles/test_styles.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Test suite for the docx.styles module
5+
"""
6+
7+
from __future__ import (
8+
absolute_import, division, print_function, unicode_literals
9+
)
10+
11+
import pytest
12+
13+
from docx.styles.styles import Styles
14+
15+
from ..unitutil.cxml import element
16+
17+
18+
class DescribeStyles(object):
19+
20+
def it_knows_its_length(self, len_fixture):
21+
styles, expected_value = len_fixture
22+
assert len(styles) == expected_value
23+
24+
# fixture --------------------------------------------------------
25+
26+
@pytest.fixture(params=[
27+
('w:styles', 0),
28+
('w:styles/w:style', 1),
29+
('w:styles/(w:style,w:style)', 2),
30+
('w:styles/(w:style,w:style,w:style)', 3),
31+
])
32+
def len_fixture(self, request):
33+
styles_cxml, expected_value = request.param
34+
styles = Styles(element(styles_cxml))
35+
return styles, expected_value

0 commit comments

Comments
 (0)