<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , unicode_literals <EOL> from behave import given , then , when <EOL> from docx import Document <EOL> from docx . enum . section import WD_ORIENT , WD_SECTION <EOL> from docx . shape import InlineShapes <EOL> from docx . shared import Inches <EOL> from docx . section import Sections <EOL> from docx . styles . styles import Styles <EOL> from docx . table import Table <EOL> from docx . text . paragraph import Paragraph <EOL> from helpers import test_docx , test_file <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_blank_document ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_document_having_builtin_styles ( context ) : <EOL> context . document = Document ( ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_document_having_inline_shapes ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_document_having_sections ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_document_having_styles ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_document_having_three_tables ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> @ given ( '<STR_LIT>' ) <EOL> def given_a_single_section_document_having_portrait_layout ( context ) : <EOL> context . document = Document ( test_docx ( '<STR_LIT>' ) ) <EOL> section = context . document . sections [ - <NUM_LIT:1> ] <EOL> context . original_dimensions = ( section . page_width , section . page_height ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_2x2_table_specifying_only_row_and_col_count ( context ) : <EOL> document = context . document <EOL> document . add_table ( rows = <NUM_LIT:2> , cols = <NUM_LIT:2> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_2x2_table_specifying_style_name ( context , style_name ) : <EOL> document = context . document <EOL> document . add_table ( rows = <NUM_LIT:2> , cols = <NUM_LIT:2> , style = style_name ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_heading_specifying_level ( context , level ) : <EOL> context . document . add_heading ( level = int ( level ) ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_heading_specifying_only_its_text ( context ) : <EOL> document = context . document <EOL> context . heading_text = text = '<STR_LIT>' <EOL> document . add_heading ( text ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_page_break_to_document ( context ) : <EOL> document = context . document <EOL> document . add_page_break ( ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_add_a_paragraph_specifying_its_style_as_a ( context , kind ) : <EOL> document = context . document <EOL> style = context . style = document . styles [ '<STR_LIT>' ] <EOL> style_spec = { <EOL> '<STR_LIT>' : style , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ kind ] <EOL> document . add_paragraph ( style = style_spec ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_paragraph_specifying_text ( context ) : <EOL> document = context . document <EOL> context . paragraph_text = '<STR_LIT>' <EOL> document . add_paragraph ( context . paragraph_text ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_paragraph_without_specifying_text_or_style ( context ) : <EOL> document = context . document <EOL> document . add_paragraph ( ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_picture_specifying_width_and_height ( context ) : <EOL> document = context . document <EOL> context . picture = document . add_picture ( <EOL> test_file ( '<STR_LIT>' ) , <EOL> width = Inches ( <NUM_LIT> ) , height = Inches ( <NUM_LIT> ) <EOL> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_picture_specifying_height ( context ) : <EOL> document = context . document <EOL> context . picture = document . add_picture ( <EOL> test_file ( '<STR_LIT>' ) , height = Inches ( <NUM_LIT> ) <EOL> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_picture_specifying_width ( context ) : <EOL> document = context . document <EOL> context . picture = document . add_picture ( <EOL> test_file ( '<STR_LIT>' ) , width = Inches ( <NUM_LIT> ) <EOL> ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_add_picture_specifying_only_image_file ( context ) : <EOL> document = context . document <EOL> context . picture = document . add_picture ( test_file ( '<STR_LIT>' ) ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_add_an_even_page_section_to_the_document ( context ) : <EOL> context . section = context . document . add_section ( WD_SECTION . EVEN_PAGE ) <EOL> @ when ( '<STR_LIT>' ) <EOL> def when_I_change_the_new_section_layout_to_landscape ( context ) : <EOL> new_height , new_width = context . original_dimensions <EOL> section = context . section <EOL> section . orientation = WD_ORIENT . LANDSCAPE <EOL> section . page_width = new_width <EOL> section . page_height = new_height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_document_inline_shapes_is_an_InlineShapes_object ( context ) : <EOL> document = context . document <EOL> inline_shapes = document . inline_shapes <EOL> assert isinstance ( inline_shapes , InlineShapes ) <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_document_paragraphs_is_a_list_containing_three_paragraphs ( context ) : <EOL> document = context . document <EOL> paragraphs = document . paragraphs <EOL> assert isinstance ( paragraphs , list ) <EOL> assert len ( paragraphs ) == <NUM_LIT:3> <EOL> for paragraph in paragraphs : <EOL> assert isinstance ( paragraph , Paragraph ) <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_document_sections_is_a_Sections_object ( context ) : <EOL> sections = context . document . sections <EOL> msg = '<STR_LIT>' <EOL> assert isinstance ( sections , Sections ) , msg <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_document_styles_is_a_Styles_object ( context ) : <EOL> styles = context . document . styles <EOL> assert isinstance ( styles , Styles ) <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_document_tables_is_a_list_containing_three_tables ( context ) : <EOL> document = context . document <EOL> tables = document . tables <EOL> assert isinstance ( tables , list ) <EOL> assert len ( tables ) == <NUM_LIT:3> <EOL> for table in tables : <EOL> assert isinstance ( table , Table ) <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_document_contains_a_2x2_table ( context ) : <EOL> table = context . document . tables [ - <NUM_LIT:1> ] <EOL> assert isinstance ( table , Table ) <EOL> assert len ( table . rows ) == <NUM_LIT:2> <EOL> assert len ( table . columns ) == <NUM_LIT:2> <EOL> context . table_ = table <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_document_has_two_sections ( context ) : <EOL> assert len ( context . document . sections ) == <NUM_LIT:2> <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_first_section_is_portrait ( context ) : <EOL> first_section = context . document . sections [ <NUM_LIT:0> ] <EOL> expected_width , expected_height = context . original_dimensions <EOL> assert first_section . orientation == WD_ORIENT . PORTRAIT <EOL> assert first_section . page_width == expected_width <EOL> assert first_section . page_height == expected_height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_last_paragraph_contains_only_a_page_break ( context ) : <EOL> document = context . document <EOL> paragraph = document . paragraphs [ - <NUM_LIT:1> ] <EOL> assert len ( paragraph . runs ) == <NUM_LIT:1> <EOL> assert len ( paragraph . runs [ <NUM_LIT:0> ] . _r ) == <NUM_LIT:1> <EOL> assert paragraph . runs [ <NUM_LIT:0> ] . _r [ <NUM_LIT:0> ] . type == '<STR_LIT>' <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_last_p_contains_heading_text ( context ) : <EOL> document = context . document <EOL> text = context . heading_text <EOL> paragraph = document . paragraphs [ - <NUM_LIT:1> ] <EOL> assert paragraph . text == text <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_second_section_is_landscape ( context ) : <EOL> new_section = context . document . sections [ - <NUM_LIT:1> ] <EOL> expected_height , expected_width = context . original_dimensions <EOL> assert new_section . orientation == WD_ORIENT . LANDSCAPE <EOL> assert new_section . page_width == expected_width <EOL> assert new_section . page_height == expected_height <EOL> @ then ( '<STR_LIT>' ) <EOL> def then_the_style_of_the_last_paragraph_is_style ( context , style_name ) : <EOL> document = context . document <EOL> paragraph = document . paragraphs [ - <NUM_LIT:1> ] <EOL> assert paragraph . style . name == style_name , ( <EOL> '<STR_LIT>' % paragraph . style . name <EOL> ) </s>
