Skip to content

Commit dc8295b

Browse files
author
Steve Canny
committed
text: add Paragraph.runs
1 parent 65d6d13 commit dc8295b

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

docx/text.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def add_run(self):
2727
r = self._p.add_r()
2828
return Run(r)
2929

30+
@property
31+
def runs(self):
32+
"""
33+
Sequence of |Run| instances corresponding to the <w:r> elements in
34+
this paragraph.
35+
"""
36+
return tuple([Run(r) for r in self._p.r_elms])
37+
3038

3139
class Run(object):
3240
"""

tests/test_text.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import pytest
1616

17-
from mock import create_autospec, Mock
17+
from mock import call, create_autospec, Mock
1818

1919
from .unitutil import class_mock
2020

@@ -25,6 +25,19 @@ class DescribeParagraph(object):
2525
def Run_(self, request):
2626
return class_mock('docx.text.Run', request)
2727

28+
def it_has_a_sequence_of_the_runs_it_contains(self, Run_):
29+
p_elm = Mock(name='p_elm')
30+
r1, r2 = (Mock(name='r1'), Mock(name='r2'))
31+
R1, R2 = (Mock(name='Run1'), Mock(name='Run2'))
32+
p_elm.r_elms = [r1, r2]
33+
p = Paragraph(p_elm)
34+
Run_.side_effect = [R1, R2]
35+
# exercise ---------------------
36+
runs = p.runs
37+
# verify -----------------------
38+
assert Run_.mock_calls == [call(r1), call(r2)]
39+
assert runs == (R1, R2)
40+
2841
def it_can_add_a_run_to_itself(self, Run_):
2942
# mockery ----------------------
3043
p_elm = create_autospec(CT_P)

0 commit comments

Comments
 (0)