99from behave import given , then , when
1010
1111from pptx import Presentation
12- from pptx .enum .dml import MSO_FILL
12+ from pptx .enum .dml import MSO_FILL , MSO_PATTERN
1313
1414from helpers import test_pptx
1515
@@ -22,20 +22,57 @@ def given_a_FillFormat_object_as_fill(context):
2222 context .fill = fill
2323
2424
25+ @given ('a FillFormat object as fill having {pattern} fill' )
26+ def given_a_FillFormat_object_as_fill_having_pattern (context , pattern ):
27+ shape_idx = {
28+ 'no pattern' : 0 ,
29+ 'MSO_PATTERN.DIVOT' : 1 ,
30+ 'MSO_PATTERN.WAVE' : 2 ,
31+ }[pattern ]
32+ slide = Presentation (test_pptx ('dml-fill' )).slides [1 ]
33+ fill = slide .shapes [shape_idx ].fill
34+ context .fill = fill
35+
36+
2537# when =====================================================
2638
39+ @when ("I assign {value} to fill.pattern" )
40+ def when_I_assign_value_to_fill_pattern (context , value ):
41+ pattern = {
42+ 'None' : None ,
43+ 'MSO_PATTERN.CROSS' : MSO_PATTERN .CROSS ,
44+ 'MSO_PATTERN.DIVOT' : MSO_PATTERN .DIVOT ,
45+ 'MSO_PATTERN.WAVE' : MSO_PATTERN .WAVE ,
46+ }[value ]
47+ context .fill .pattern = pattern
48+
49+
2750@when ("I call fill.background()" )
2851def when_I_call_fill_background (context ):
2952 context .fill .background ()
3053
3154
55+ @when ("I call fill.patterned()" )
56+ def when_I_call_fill_patterned (context ):
57+ context .fill .patterned ()
58+
59+
3260@when ("I call fill.solid()" )
3361def when_I_call_fill_solid (context ):
3462 context .fill .solid ()
3563
3664
3765# then =====================================================
3866
67+ @then ('fill.back_color is a ColorFormat object' )
68+ def then_fill_back_color_is_a_ColorFormat_object (context ):
69+ class_name = context .fill .back_color .__class__ .__name__
70+ expected_value = 'ColorFormat'
71+ assert class_name == expected_value , (
72+ 'expected \' %s\' , got \' %s\' ' % (expected_value , class_name )
73+ )
74+
75+
3976@then ('fill.fore_color is a ColorFormat object' )
4077def then_fill_fore_color_is_a_ColorFormat_object (context ):
4178 class_name = context .fill .fore_color .__class__ .__name__
@@ -45,6 +82,20 @@ def then_fill_fore_color_is_a_ColorFormat_object(context):
4582 )
4683
4784
85+ @then ('fill.pattern is {value}' )
86+ def then_fill_pattern_is_value (context , value ):
87+ fill_pattern = context .fill .pattern
88+ expected_value = {
89+ 'None' : None ,
90+ 'MSO_PATTERN.CROSS' : MSO_PATTERN .CROSS ,
91+ 'MSO_PATTERN.DIVOT' : MSO_PATTERN .DIVOT ,
92+ 'MSO_PATTERN.WAVE' : MSO_PATTERN .WAVE ,
93+ }[value ]
94+ assert fill_pattern == expected_value , (
95+ 'expected fill pattern %s, got %s' % (expected_value , fill_pattern )
96+ )
97+
98+
4899@then ('fill.type is MSO_FILL.{member_name}' )
49100def then_fill_type_is_MSO_FILL_member_name (context , member_name ):
50101 fill_type = context .fill .type
0 commit comments