77from behave import given , then
88
99from docx import Document
10+ from docx .enum .text import WD_TAB_ALIGNMENT , WD_TAB_LEADER
1011from docx .text .tabstops import TabStop
1112
1213from helpers import test_docx
@@ -22,6 +23,30 @@ def given_a_tab_stops_having_count_tab_stops(context, count):
2223 context .tab_stops = paragraph_format .tab_stops
2324
2425
26+ @given ('a tab stop 0.5 inches {in_or_out} from the paragraph left edge' )
27+ def given_a_tab_stop_inches_from_paragraph_left_edge (context , in_or_out ):
28+ tab_idx = {'out' : 0 , 'in' : 1 }[in_or_out ]
29+ document = Document (test_docx ('tab-stops' ))
30+ paragraph_format = document .paragraphs [2 ].paragraph_format
31+ context .tab_stop = paragraph_format .tab_stops [tab_idx ]
32+
33+
34+ @given ('a tab stop having {alignment} alignment' )
35+ def given_a_tab_stop_having_alignment_alignment (context , alignment ):
36+ tab_idx = {'LEFT' : 0 , 'CENTER' : 1 , 'RIGHT' : 2 }[alignment ]
37+ document = Document (test_docx ('tab-stops' ))
38+ paragraph_format = document .paragraphs [1 ].paragraph_format
39+ context .tab_stop = paragraph_format .tab_stops [tab_idx ]
40+
41+
42+ @given ('a tab stop having {leader} leader' )
43+ def given_a_tab_stop_having_leader_leader (context , leader ):
44+ tab_idx = {'no specified' : 0 , 'a dotted' : 2 }[leader ]
45+ document = Document (test_docx ('tab-stops' ))
46+ paragraph_format = document .paragraphs [1 ].paragraph_format
47+ context .tab_stop = paragraph_format .tab_stops [tab_idx ]
48+
49+
2550# then =====================================================
2651
2752@then ('I can access a tab stop by index' )
@@ -43,3 +68,23 @@ def then_I_can_iterate_the_TabStops_object(context):
4368def then_len_tab_stops_is_count (context , count ):
4469 tab_stops = context .tab_stops
4570 assert len (tab_stops ) == int (count )
71+
72+
73+ @then ('tab_stop.alignment is {alignment}' )
74+ def then_tab_stop_alignment_is_alignment (context , alignment ):
75+ expected_value = getattr (WD_TAB_ALIGNMENT , alignment )
76+ tab_stop = context .tab_stop
77+ assert tab_stop .alignment == expected_value
78+
79+
80+ @then ('tab_stop.leader is {leader}' )
81+ def then_tab_stop_leader_is_leader (context , leader ):
82+ expected_value = getattr (WD_TAB_LEADER , leader )
83+ tab_stop = context .tab_stop
84+ assert tab_stop .leader == expected_value
85+
86+
87+ @then ('tab_stop.position is {position}' )
88+ def then_tab_stop_position_is_position (context , position ):
89+ tab_stop = context .tab_stop
90+ assert tab_stop .position == int (position )
0 commit comments