Skip to content

Commit faf2dee

Browse files
author
Steve Canny
committed
style: add LatentStyles.__iter__()
1 parent 3912043 commit faf2dee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

docx/styles/latent.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class LatentStyles(ElementProxy):
2020

2121
__slots__ = ()
2222

23+
def __iter__(self):
24+
return (_LatentStyle(ls) for ls in self._element.lsdException_lst)
25+
2326
def __len__(self):
2427
return len(self._element.lsdException_lst)
2528

tests/styles/test_latent.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import pytest
1212

13-
from docx.styles.latent import LatentStyles
13+
from docx.styles.latent import _LatentStyle, LatentStyles
1414

1515
from ..unitutil.cxml import element
1616

@@ -21,8 +21,25 @@ def it_knows_how_many_latent_styles_it_contains(self, len_fixture):
2121
latent_styles, expected_value = len_fixture
2222
assert len(latent_styles) == expected_value
2323

24+
def it_can_iterate_over_its_latent_styles(self, iter_fixture):
25+
latent_styles, expected_count = iter_fixture
26+
lst = [ls for ls in latent_styles]
27+
assert len(lst) == expected_count
28+
for latent_style in lst:
29+
assert isinstance(latent_style, _LatentStyle)
30+
2431
# fixture --------------------------------------------------------
2532

33+
@pytest.fixture(params=[
34+
('w:latentStyles', 0),
35+
('w:latentStyles/w:lsdException', 1),
36+
('w:latentStyles/(w:lsdException,w:lsdException)', 2),
37+
])
38+
def iter_fixture(self, request):
39+
latentStyles_cxml, count = request.param
40+
latent_styles = LatentStyles(element(latentStyles_cxml))
41+
return latent_styles, count
42+
2643
@pytest.fixture(params=[
2744
('w:latentStyles', 0),
2845
('w:latentStyles/w:lsdException', 1),

0 commit comments

Comments
 (0)