44Step implementations for paragraph-related features
55"""
66
7- from behave import given , then
7+ from behave import given , then , when
88
99from docx import Document
1010from docx .enum .text import WD_TAB_ALIGNMENT , WD_TAB_LEADER
@@ -28,6 +28,7 @@ def given_a_tab_stop_inches_from_paragraph_left_edge(context, in_or_out):
2828 tab_idx = {'out' : 0 , 'in' : 1 }[in_or_out ]
2929 document = Document (test_docx ('tab-stops' ))
3030 paragraph_format = document .paragraphs [2 ].paragraph_format
31+ context .tab_stops = paragraph_format .tab_stops
3132 context .tab_stop = paragraph_format .tab_stops [tab_idx ]
3233
3334
@@ -47,6 +48,25 @@ def given_a_tab_stop_having_leader_leader(context, leader):
4748 context .tab_stop = paragraph_format .tab_stops [tab_idx ]
4849
4950
51+ # when ====================================================
52+
53+ @when ('I assign {member} to tab_stop.alignment' )
54+ def when_I_assign_member_to_tab_stop_alignment (context , member ):
55+ value = getattr (WD_TAB_ALIGNMENT , member )
56+ context .tab_stop .alignment = value
57+
58+
59+ @when ('I assign {member} to tab_stop.leader' )
60+ def when_I_assign_member_to_tab_stop_leader (context , member ):
61+ value = getattr (WD_TAB_LEADER , member )
62+ context .tab_stop .leader = value
63+
64+
65+ @when ('I assign {value} to tab_stop.position' )
66+ def when_I_assign_value_to_tab_stop_value (context , value ):
67+ context .tab_stop .position = int (value )
68+
69+
5070# then =====================================================
5171
5272@then ('I can access a tab stop by index' )
@@ -88,3 +108,10 @@ def then_tab_stop_leader_is_leader(context, leader):
88108def then_tab_stop_position_is_position (context , position ):
89109 tab_stop = context .tab_stop
90110 assert tab_stop .position == int (position )
111+
112+
113+ @then ('the tab stops are sequenced in position order' )
114+ def then_the_tab_stops_are_sequenced_in_position_order (context ):
115+ tab_stops = context .tab_stops
116+ for idx in range (len (tab_stops ) - 1 ):
117+ assert tab_stops [idx ].position < tab_stops [idx + 1 ].position
0 commit comments