<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import hashlib <EOL> from behave import given , when , then <EOL> from pptx import Presentation <EOL> from pptx . chart . data import ChartData <EOL> from pptx . enum . chart import XL_CHART_TYPE <EOL> from pptx . enum . shapes import MSO_SHAPE_TYPE , PP_PLACEHOLDER <EOL> from pptx . shapes . base import _PlaceholderFormat <EOL> from helpers import saved_pptx_path , test_file , test_pptx , test_text <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_bullet_body_placeholder ( context ) : <EOL> context . prs = Presentation ( ) <EOL> slide_layout = context . prs . slide_layouts [ <NUM_LIT:1> ] <EOL> context . sld = context . prs . slides . add_slide ( slide_layout ) <EOL> context . body = context . sld . shapes . placeholders [ <NUM_LIT:1> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_known_placeholder_shape ( context , placeholder_type ) : <EOL> context . execute_steps ( <EOL> '<STR_LIT>' % placeholder_type <EOL> ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_layout_placeholder_with_directly_set_pos_and_size ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . placeholder = prs . slide_layouts [ <NUM_LIT:0> ] . placeholders [ <NUM_LIT:1> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_layout_placeholder_with_no_direct_pos_or_size_settings ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . placeholder = prs . slide_layouts [ <NUM_LIT:0> ] . placeholders [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_master_placeholder ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . master_placeholder = prs . slide_master . placeholders [ <NUM_LIT:1> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_slide_placeholder_with_directly_set_pos_and_size ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . placeholder = prs . slides [ <NUM_LIT:0> ] . placeholders [ <NUM_LIT:10> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_slide_placeholder_with_no_direct_pos_or_size_settings ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . placeholder = prs . slides [ <NUM_LIT:0> ] . placeholders [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_slide_with_an_unpopulated_type_placeholder ( context , type_ ) : <EOL> slide_idx = [ <EOL> '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT:text>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] . index ( type_ ) <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . shape = prs . slides [ slide_idx ] . shapes [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_slide_with_a_type_ph_with_content ( context , type_ , content ) : <EOL> slide_idx = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT:text>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] . index ( type_ ) <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . shape = prs . slides [ slide_idx ] . shapes [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_an_unpopulated_placeholder_shape ( context , placeholder_type ) : <EOL> slide_idx = [ <EOL> '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT:text>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] . index ( placeholder_type ) <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . shape = prs . slides [ slide_idx ] . shapes [ <NUM_LIT:0> ] <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_call_placeholder_insert_chart ( context ) : <EOL> chart_data = ChartData ( ) <EOL> chart_data . categories = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> chart_data . add_series ( '<STR_LIT>' , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> placeholder = context . shape <EOL> context . placeholder = placeholder . insert_chart ( <EOL> XL_CHART_TYPE . PIE , chart_data <EOL> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_call_placeholder_insert_picture ( context , filename ) : <EOL> placeholder = context . shape <EOL> path = test_file ( filename ) <EOL> with open ( path , '<STR_LIT:rb>' ) as f : <EOL> context . image_sha1 = hashlib . sha1 ( f . read ( ) ) . hexdigest ( ) <EOL> context . placeholder = placeholder . insert_picture ( path ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_call_placeholder_insert_table ( context ) : <EOL> placeholder = context . shape <EOL> context . placeholder = placeholder . insert_table ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_indent_the_first_paragraph ( context ) : <EOL> context . body . text_frame . paragraphs [ <NUM_LIT:0> ] . level = <NUM_LIT:1> <EOL> @ when ( "<STR_LIT>" ) <EOL> def step_when_set_slide_title_text ( context ) : <EOL> context . slide . shapes . title . text = test_text <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_I_can_get_the_placeholder_dimensions ( context ) : <EOL> placeholder = context . master_placeholder <EOL> assert placeholder . width == <NUM_LIT> , '<STR_LIT>' % placeholder . width <EOL> assert placeholder . height == <NUM_LIT> , '<STR_LIT>' % placeholder . height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_I_can_get_the_placeholder_position ( context ) : <EOL> placeholder = context . master_placeholder <EOL> assert placeholder . left == <NUM_LIT> , '<STR_LIT>' % placeholder . left <EOL> assert placeholder . top == <NUM_LIT> , '<STR_LIT>' % placeholder . top <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_I_get_direct_settings_when_query_pos_and_size ( context ) : <EOL> placeholder = context . placeholder <EOL> assert placeholder . left == <NUM_LIT> , '<STR_LIT>' % placeholder . left <EOL> assert placeholder . top == <NUM_LIT> , '<STR_LIT>' % placeholder . top <EOL> assert placeholder . width == <NUM_LIT> , '<STR_LIT>' % placeholder . width <EOL> assert placeholder . height == <NUM_LIT> , '<STR_LIT>' % placeholder . height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_I_get_inherited_settings_when_I_query_position_and_size ( context ) : <EOL> placeholder = context . placeholder <EOL> assert placeholder . left == <NUM_LIT> , '<STR_LIT>' % placeholder . left <EOL> assert placeholder . top == <NUM_LIT> , '<STR_LIT>' % placeholder . top <EOL> assert placeholder . width == <NUM_LIT> , '<STR_LIT>' % placeholder . width <EOL> assert placeholder . height == <NUM_LIT> , '<STR_LIT>' % placeholder . height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_placeholder_format_idx_is_value ( context , value ) : <EOL> expected_value = int ( value ) <EOL> placeholder_format = context . shape . placeholder_format <EOL> assert placeholder_format . idx == expected_value <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_placeholder_format_type_is_value ( context , value ) : <EOL> expected_value = getattr ( PP_PLACEHOLDER , value . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> ] ) <EOL> placeholder_format = context . shape . placeholder_format <EOL> assert placeholder_format . type == expected_value <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_shape_placeholder_format_is_its_PlaceholderFormat_object ( context ) : <EOL> shape = context . shape <EOL> placeholder_format = shape . placeholder_format <EOL> assert isinstance ( placeholder_format , _PlaceholderFormat ) <EOL> assert placeholder_format . element is shape . element . ph <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_shape_shape_type_is_PLACEHOLDER ( context ) : <EOL> shape = context . shape <EOL> assert shape . shape_type == MSO_SHAPE_TYPE . PLACEHOLDER <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_slide_shapes_0_is_a_cls_proxy_for_that_placeholder ( context , cls ) : <EOL> placeholder = context . shape <EOL> clsname = placeholder . __class__ . __name__ <EOL> assert clsname == cls , '<STR_LIT>' % clsname <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_chart_is_a_pie_chart ( context ) : <EOL> chart = context . chart <EOL> assert chart . chart_type == XL_CHART_TYPE . PIE <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_return_value_is_a_PlaceholderType_object ( context , type ) : <EOL> expected_type_name = '<STR_LIT>' % type <EOL> placeholder_type_name = context . placeholder . __class__ . __name__ <EOL> assert placeholder_type_name == expected_type_name <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_paragraph_is_indented ( context ) : <EOL> prs = Presentation ( saved_pptx_path ) <EOL> sld = prs . slides [ <NUM_LIT:0> ] <EOL> body = sld . shapes . placeholders [ <NUM_LIT:1> ] <EOL> p = body . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> assert p . level == <NUM_LIT:1> <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_placeholder_contains_the_chart ( context ) : <EOL> placeholder_graphic_frame = context . placeholder <EOL> assert placeholder_graphic_frame . has_chart <EOL> context . chart = placeholder_graphic_frame . chart <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_placeholder_contains_the_image ( context ) : <EOL> placeholder_picture = context . placeholder <EOL> assert placeholder_picture . image . sha1 == context . image_sha1 <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_placeholder_contains_the_table ( context ) : <EOL> placeholder_graphic_frame = context . placeholder <EOL> assert placeholder_graphic_frame . has_table <EOL> context . table_ = placeholder_graphic_frame . table <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_placeholders_position_and_size_are_inherited ( context ) : <EOL> placeholder = context . shape <EOL> expected_values = ( <EOL> ( '<STR_LIT:left>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT:width>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ) <EOL> for prop_name , expected_value in expected_values : <EOL> value = getattr ( placeholder , prop_name ) <EOL> assert value == expected_value , '<STR_LIT>' % value <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_sides_crop_is_value ( context , sides , value ) : <EOL> side_prop_names = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } [ sides ] <EOL> expected_value = float ( value ) <EOL> placeholder_picture = context . placeholder <EOL> for prop_name in side_prop_names : <EOL> value = getattr ( placeholder_picture , prop_name ) <EOL> difference = abs ( expected_value - value ) <EOL> assert difference < <NUM_LIT> , '<STR_LIT>' % ( value , prop_name ) <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_table_has_2_rows_and_3_columns ( context ) : <EOL> table = context . table_ <EOL> assert len ( table . rows ) == <NUM_LIT:2> <EOL> assert len ( table . columns ) == <NUM_LIT:3> <EOL> @ then ( '<STR_LIT>' ) <EOL> def step_then_text_appears_in_title_placeholder ( context ) : <EOL> prs = Presentation ( saved_pptx_path ) <EOL> title_shape = prs . slides [ <NUM_LIT:0> ] . shapes . title <EOL> title_text = title_shape . text_frame . paragraphs [ <NUM_LIT:0> ] . runs [ <NUM_LIT:0> ] . text <EOL> assert title_text == test_text </s>
