Skip to content

Commit 1f808b3

Browse files
committed
test_text: added bool prop test for underline
Added bool prop tests for underline. Moved from `WD_UNDERLINE` conversion to string into `docx\oxml\text.py`
1 parent 84bdbbe commit 1f808b3

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

docx/oxml/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from docx.oxml.shared import (
1010
CT_String, nsdecls, OxmlBaseElement, OxmlElement, oxml_fromstring, qn
1111
)
12-
12+
from docx.enum.text import WD_UNDERLINE
1313

1414
class CT_Br(OxmlBaseElement):
1515
"""
@@ -299,7 +299,7 @@ def add_underline(self, style):
299299
"""
300300
Return a newly added <w:u w:val=style/> child element.
301301
"""
302-
u = CT_String.new('w:u', str(style))
302+
u = CT_String.new('w:u', WD_UNDERLINE.stringDict[style]))
303303
self.insert(0, u)
304304
return u
305305

docx/text.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def underline(self, style):
236236
style = WD_UNDERLINE.NONE
237237
if type(style)==bool:
238238
style = WD_UNDERLINE.SINGLE if style else WD_UNDERLINE.NONE
239-
240-
style = WD_UNDERLINE.stringDict[style]
241239

242240
u = self._r.get_or_add_rPr().underline
243241
if u is None:

tests/oxml/unitdata/text.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def an_emboss():
136136

137137
def an_i():
138138
return CT_OnOffBuilder('w:i')
139-
139+
140+
def an_underline():
141+
return CT_OnOffBuilder('w:u')
140142

141143
def an_iCs():
142144
return CT_OnOffBuilder('w:iCs')

tests/test_text.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
a_b, a_bCs, a_br, a_caps, a_cs, a_dstrike, a_p, a_shadow, a_smallCaps,
2121
a_snapToGrid, a_specVanish, a_strike, a_t, a_vanish, a_webHidden,
2222
an_emboss, an_i, an_iCs, an_imprint, an_oMath, a_noProof, an_outline,
23-
an_r, an_rPr, an_rtl
23+
an_r, an_rPr, an_rtl, an_underline
2424
)
2525
from .unitutil import class_mock, instance_mock
2626

@@ -186,6 +186,7 @@ def add_text_fixture(self, request, run, Text_):
186186
('all_caps', True), ('all_caps', False), ('all_caps', None),
187187
('bold', True), ('bold', False), ('bold', None),
188188
('italic', True), ('italic', False), ('italic', None),
189+
('underline', True), ('underline', False), ('underline', None),
189190
('complex_script', True), ('complex_script', False),
190191
('complex_script', None),
191192
('cs_bold', True), ('cs_bold', False), ('cs_bold', None),
@@ -231,6 +232,7 @@ def bool_prop_get_fixture(self, request):
231232
'spec_vanish': a_specVanish,
232233
'strike': a_strike,
233234
'web_hidden': a_webHidden,
235+
'underline': an_underline,
234236
}[bool_prop_name]
235237
r_bldr = an_r().with_nsdecls()
236238
if expected_state is not None:
@@ -247,6 +249,7 @@ def bool_prop_get_fixture(self, request):
247249
('all_caps', True), ('all_caps', False), ('all_caps', None),
248250
('bold', True), ('bold', False), ('bold', None),
249251
('italic', True), ('italic', False), ('italic', None),
252+
('underline', True), ('underline', False), ('underline', None),
250253
('complex_script', True), ('complex_script', False),
251254
('complex_script', None),
252255
('cs_bold', True), ('cs_bold', False), ('cs_bold', None),
@@ -292,6 +295,7 @@ def bool_prop_set_fixture(self, request):
292295
'spec_vanish': a_specVanish,
293296
'strike': a_strike,
294297
'web_hidden': a_webHidden,
298+
'underline': an_underline,
295299
}[bool_prop_name]
296300
# run --------------------------
297301
r = an_r().with_nsdecls().element

0 commit comments

Comments
 (0)