88 absolute_import , division , print_function , unicode_literals
99)
1010
11- from docx .enum .text import WD_BREAK
11+ from docx .enum .text import WD_BREAK , WD_UNDERLINE
1212from docx .oxml .text import CT_P , CT_R
1313from docx .text import Paragraph , Run
1414
1818
1919from .oxml .unitdata .text import (
2020 a_b , a_bCs , a_br , a_caps , a_cs , a_dstrike , a_p , a_shadow , a_smallCaps ,
21- a_snapToGrid , a_specVanish , a_strike , a_t , a_vanish , a_webHidden ,
21+ a_snapToGrid , a_specVanish , a_strike , a_t , a_u , a_vanish , a_webHidden ,
2222 an_emboss , an_i , an_iCs , an_imprint , an_oMath , a_noProof , an_outline ,
2323 an_r , an_rPr , an_rStyle , an_rtl
2424)
@@ -152,6 +152,10 @@ def it_can_change_its_character_style(self, style_set_fixture):
152152 run .style = style
153153 assert run ._r .xml == expected_xml
154154
155+ def it_knows_its_underline_type (self , underline_get_fixture ):
156+ run , expected_value = underline_get_fixture
157+ assert run .underline == expected_value
158+
155159 def it_can_add_text (self , add_text_fixture ):
156160 run , text_str , expected_xml , Text_ = add_text_fixture
157161 _text = run .add_text (text_str )
@@ -354,6 +358,18 @@ def text_prop_fixture(self, Text_):
354358 run = Run (r )
355359 return run , 'foobar'
356360
361+ @pytest .fixture (params = [
362+ (None , None ),
363+ ('single' , True ),
364+ ('none' , False ),
365+ ('double' , WD_UNDERLINE .DOUBLE ),
366+ ])
367+ def underline_get_fixture (self , request ):
368+ underline_type , expected_prop_value = request .param
369+ r = self .r_bldr_with_underline (underline_type ).element
370+ run = Run (r )
371+ return run , expected_prop_value
372+
357373 # fixture components ---------------------------------------------
358374
359375 @pytest .fixture
@@ -368,6 +384,13 @@ def r_bldr_with_style(self, style):
368384 r_bldr = an_r ().with_nsdecls ().with_child (rPr_bldr )
369385 return r_bldr
370386
387+ def r_bldr_with_underline (self , underline_type ):
388+ rPr_bldr = an_rPr ()
389+ if underline_type is not None :
390+ rPr_bldr .with_child (a_u ().with_val (underline_type ))
391+ r_bldr = an_r ().with_nsdecls ().with_child (rPr_bldr )
392+ return r_bldr
393+
371394 @pytest .fixture
372395 def Text_ (self , request ):
373396 return class_mock (request , 'docx.text.Text' )
0 commit comments