<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import os <EOL> from behave import given , when , then <EOL> from pptx import Presentation <EOL> from pptx . enum . text import PP_ALIGN <EOL> from pptx . util import Emu , Inches <EOL> from helpers import saved_pptx_path , test_pptx <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_paragraph ( context ) : <EOL> context . prs = Presentation ( ) <EOL> blank_slide_layout = context . prs . slide_layouts [ <NUM_LIT:6> ] <EOL> slide = context . prs . slides . add_slide ( blank_slide_layout ) <EOL> length = Inches ( <NUM_LIT> ) <EOL> textbox = slide . shapes . add_textbox ( length , length , length , length ) <EOL> context . paragraph = textbox . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_paragraph_containing_text ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . paragraph = prs . slides [ <NUM_LIT:0> ] . shapes [ <NUM_LIT:0> ] . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_paragraph_having_line_spacing_of_setting ( context , setting ) : <EOL> paragraph_idx = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> } [ setting ] <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> text_frame = prs . slides [ <NUM_LIT:2> ] . shapes [ <NUM_LIT:0> ] . text_frame <EOL> context . paragraph = text_frame . paragraphs [ paragraph_idx ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_paragraph_having_space_before_after_of_setting ( <EOL> context , before_after , setting ) : <EOL> slide_idx = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } [ before_after ] <EOL> paragraph_idx = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } [ setting ] <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> text_frame = prs . slides [ slide_idx ] . shapes [ <NUM_LIT:0> ] . text_frame <EOL> context . paragraph = text_frame . paragraphs [ paragraph_idx ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_run ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . run = prs . slides [ <NUM_LIT:0> ] . shapes [ <NUM_LIT:0> ] . text_frame . paragraphs [ <NUM_LIT:0> ] . runs [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_run_containing_text ( context ) : <EOL> prs = Presentation ( test_pptx ( '<STR_LIT>' ) ) <EOL> context . run = prs . slides [ <NUM_LIT:0> ] . shapes [ <NUM_LIT:0> ] . text_frame . paragraphs [ <NUM_LIT:0> ] . runs [ <NUM_LIT:0> ] <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_text_run ( context ) : <EOL> prs = Presentation ( ) <EOL> blank_slide_layout = prs . slide_layouts [ <NUM_LIT:6> ] <EOL> slide = prs . slides . add_slide ( blank_slide_layout ) <EOL> textbox = slide . shapes . add_textbox ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p = textbox . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> context . r = p . add_run ( ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_text_run_in_a_table_cell ( context ) : <EOL> prs = Presentation ( ) <EOL> blank_slide_layout = prs . slide_layouts [ <NUM_LIT:6> ] <EOL> slide = prs . slides . add_slide ( blank_slide_layout ) <EOL> table = slide . shapes . add_table ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) . table <EOL> cell = table . cell ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p = cell . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> context . r = p . add_run ( ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_text_run_having_a_hyperlink ( context ) : <EOL> prs = Presentation ( ) <EOL> blank_slide_layout = prs . slide_layouts [ <NUM_LIT:6> ] <EOL> slide = prs . slides . add_slide ( blank_slide_layout ) <EOL> textbox = slide . shapes . add_textbox ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p = textbox . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> r = p . add_run ( ) <EOL> r . hyperlink . address = '<STR_LIT>' <EOL> context . r = r <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_assign_a_string_to_paragraph_text ( context ) : <EOL> context . paragraph . text = '<STR_LIT>' <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_assign_a_string_to_run_text ( context ) : <EOL> context . run . text = '<STR_LIT>' <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_assign_typeface_name_to_font ( context ) : <EOL> context . font . name = '<STR_LIT>' <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_assign_value_to_paragraph_line_spacing ( context , value_str ) : <EOL> value = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : Emu ( <NUM_LIT> ) , <EOL> '<STR_LIT>' : Emu ( <NUM_LIT> ) , <EOL> '<STR_LIT:None>' : None , <EOL> } [ value_str ] <EOL> paragraph = context . paragraph <EOL> paragraph . line_spacing = value <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_assign_value_to_paragraph_space_before_after ( <EOL> context , value_str , before_after ) : <EOL> value = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:None>' : None , <EOL> } [ value_str ] <EOL> attr_name = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ before_after ] <EOL> paragraph = context . paragraph <EOL> setattr ( paragraph , attr_name , value ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_reload_presentation ( context ) : <EOL> if os . path . isfile ( saved_pptx_path ) : <EOL> os . remove ( saved_pptx_path ) <EOL> context . prs . save ( saved_pptx_path ) <EOL> context . prs = Presentation ( saved_pptx_path ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_set_margin_to_value ( context , side , inches ) : <EOL> emu = Inches ( float ( inches ) ) <EOL> if side == '<STR_LIT:left>' : <EOL> context . text_frame . margin_left = emu <EOL> elif side == '<STR_LIT>' : <EOL> context . text_frame . margin_top = emu <EOL> elif side == '<STR_LIT:right>' : <EOL> context . text_frame . margin_right = emu <EOL> elif side == '<STR_LIT>' : <EOL> context . text_frame . margin_bottom = emu <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_indent_first_paragraph ( context ) : <EOL> context . paragraph . level = <NUM_LIT:1> <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_set_hyperlink_address ( context ) : <EOL> context . run_text = '<STR_LIT>' <EOL> context . address = '<STR_LIT>' <EOL> r = context . r <EOL> r . text = context . run_text <EOL> hlink = r . hyperlink <EOL> hlink . address = context . address <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_set_hyperlink_address_to_None ( context ) : <EOL> context . r . hyperlink . address = None <EOL> @ when ( "<STR_LIT>" ) <EOL> def when_set_paragraph_alignment_to_centered ( context ) : <EOL> context . paragraph . alignment = PP_ALIGN . CENTER <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_line_spacing_is_value ( context , value_str ) : <EOL> value = { <EOL> '<STR_LIT:None>' : None , <EOL> '<STR_LIT:1.0>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } [ value_str ] <EOL> paragraph = context . paragraph <EOL> assert paragraph . line_spacing == value <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_line_spacing_pt_result ( context , result ) : <EOL> value , exception = { <EOL> '<STR_LIT>' : ( None , AttributeError ) , <EOL> '<STR_LIT>' : ( <NUM_LIT> , None ) , <EOL> '<STR_LIT>' : ( <NUM_LIT> , None ) , <EOL> } [ result ] <EOL> line_spacing = context . paragraph . line_spacing <EOL> if value is not None : <EOL> assert line_spacing . pt == value <EOL> if exception is not None : <EOL> try : <EOL> line_spacing . pt <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> except exception : <EOL> pass <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_space_before_is_value ( context , before_after , value_str ) : <EOL> attr_name = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ before_after ] <EOL> value = None if value_str == '<STR_LIT:None>' else int ( value_str ) <EOL> paragraph = context . paragraph <EOL> assert getattr ( paragraph , attr_name ) == value <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_space_before_pt_is_value ( context , before_after , result ) : <EOL> attr_name = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ before_after ] <EOL> value , exception = { <EOL> '<STR_LIT>' : ( None , AttributeError ) , <EOL> '<STR_LIT>' : ( <NUM_LIT> , None ) , <EOL> } [ result ] <EOL> space_before_after = getattr ( context . paragraph , attr_name ) <EOL> if value is not None : <EOL> assert space_before_after . pt == value <EOL> if exception is not None : <EOL> try : <EOL> space_before_after . pt <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> except exception : <EOL> pass <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_text_is_the_text_in_the_paragraph ( context ) : <EOL> paragraph = context . paragraph <EOL> assert paragraph . text == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_text_matches_the_assigned_string ( context ) : <EOL> paragraph = context . paragraph <EOL> assert paragraph . text == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_run_text_is_the_text_in_the_run ( context ) : <EOL> run = context . run <EOL> assert run . text == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_run_text_matches_the_assigned_string ( context ) : <EOL> run = context . run <EOL> assert run . text == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_font_name_matches_typeface_I_set ( context ) : <EOL> assert context . font . name == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_is_aligned_centered ( context ) : <EOL> p = context . prs . slides [ <NUM_LIT:0> ] . shapes [ <NUM_LIT:0> ] . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> assert p . alignment == PP_ALIGN . CENTER <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_paragraph_indented_to_second_level ( context ) : <EOL> p = context . prs . slides [ <NUM_LIT:0> ] . shapes [ <NUM_LIT:0> ] . text_frame . paragraphs [ <NUM_LIT:0> ] <EOL> assert p . level == <NUM_LIT:1> <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_text_of_run_is_hyperlink ( context ) : <EOL> r = context . r <EOL> hlink = r . hyperlink <EOL> assert r . text == context . run_text <EOL> assert hlink . address == context . address <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_text_run_is_not_a_hyperlink ( context ) : <EOL> hlink = context . r . hyperlink <EOL> assert hlink . address is None </s>
