<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import pytest <EOL> from pptx . chart . data import ChartData <EOL> from pptx . enum . base import EnumValue <EOL> from pptx . opc . constants import CONTENT_TYPE as CT , RELATIONSHIP_TYPE as RT <EOL> from pptx . opc . packuri import PackURI <EOL> from pptx . opc . package import Part <EOL> from pptx . oxml . parts . slide import CT_Slide <EOL> from pptx . oxml . shapes . groupshape import CT_GroupShape <EOL> from pptx . package import Package <EOL> from pptx . parts . chart import ChartPart <EOL> from pptx . parts . image import Image , ImagePart <EOL> from pptx . parts . slide import BaseSlide , Slide , _SlidePlaceholders <EOL> from pptx . parts . slidelayout import SlideLayout <EOL> from pptx . shapes . placeholder import _BaseSlidePlaceholder <EOL> from pptx . shapes . shapetree import SlideShapeTree <EOL> from . . unitutil . cxml import element <EOL> from . . unitutil . file import absjoin , test_file_dir <EOL> from . . unitutil . mock import ( <EOL> call , class_mock , function_mock , initializer_mock , instance_mock , <EOL> method_mock , property_mock <EOL> ) <EOL> class DescribeBaseSlide ( object ) : <EOL> def it_knows_its_name ( self , name_fixture ) : <EOL> base_slide , expected_value = name_fixture <EOL> assert base_slide . name == expected_value <EOL> def it_can_get_a_related_image_by_rId ( self , get_image_fixture ) : <EOL> slide , rId , image_ = get_image_fixture <EOL> assert slide . get_image ( rId ) is image_ <EOL> def it_can_add_an_image_part ( self , image_part_fixture ) : <EOL> slide , image_file , image_part_ , rId_ = image_part_fixture <EOL> image_part , rId = slide . get_or_add_image_part ( image_file ) <EOL> slide . _package . get_or_add_image_part . assert_called_once_with ( <EOL> image_file <EOL> ) <EOL> slide . relate_to . assert_called_once_with ( image_part_ , RT . IMAGE ) <EOL> assert image_part is image_part_ <EOL> assert rId is rId_ <EOL> def it_provides_access_to_its_spTree_element_to_help ( self , slide ) : <EOL> spTree = slide . spTree <EOL> assert isinstance ( spTree , CT_GroupShape ) <EOL> @ pytest . fixture <EOL> def get_image_fixture ( self , related_parts_prop_ , image_part_ , image_ ) : <EOL> slide = BaseSlide ( None , None , None , None ) <EOL> rId = '<STR_LIT>' <EOL> related_parts_prop_ . return_value = { rId : image_part_ } <EOL> image_part_ . image = image_ <EOL> return slide , rId , image_ <EOL> @ pytest . fixture <EOL> def image_part_fixture ( <EOL> self , partname_ , package_ , image_part_ , relate_to_ ) : <EOL> slide = BaseSlide ( partname_ , None , None , package_ ) <EOL> image_file , rId = '<STR_LIT>' , '<STR_LIT>' <EOL> package_ . get_or_add_image_part . return_value = image_part_ <EOL> relate_to_ . return_value = rId <EOL> return slide , image_file , image_part_ , rId <EOL> @ pytest . fixture <EOL> def name_fixture ( self ) : <EOL> sld_cxml , expected_value = '<STR_LIT>' , '<STR_LIT>' <EOL> sld = element ( sld_cxml ) <EOL> base_slide = BaseSlide ( None , None , sld , None ) <EOL> return base_slide , expected_value <EOL> @ pytest . fixture <EOL> def image_ ( self , request ) : <EOL> return instance_mock ( request , Image ) <EOL> @ pytest . fixture <EOL> def image_part_ ( self , request ) : <EOL> return instance_mock ( request , ImagePart ) <EOL> @ pytest . fixture <EOL> def package_ ( self , request ) : <EOL> return instance_mock ( request , Package ) <EOL> @ pytest . fixture <EOL> def partname_ ( self ) : <EOL> return PackURI ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def relate_to_ ( self , request ) : <EOL> return method_mock ( request , BaseSlide , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def related_parts_prop_ ( self , request ) : <EOL> return property_mock ( request , BaseSlide , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def slide ( self ) : <EOL> sld = element ( '<STR_LIT>' ) <EOL> return BaseSlide ( None , None , sld , None ) <EOL> class DescribeSlide ( object ) : <EOL> def it_can_add_a_chart_part ( self , add_chart_part_fixture ) : <EOL> slide , chart_type_ , chart_data_ = add_chart_part_fixture [ : <NUM_LIT:3> ] <EOL> ChartPart_ , chart_part_ , package_ , rId = add_chart_part_fixture [ <NUM_LIT:3> : ] <EOL> _rId = slide . add_chart_part ( chart_type_ , chart_data_ ) <EOL> ChartPart_ . new . assert_called_once_with ( <EOL> chart_type_ , chart_data_ , package_ <EOL> ) <EOL> slide . relate_to . assert_called_once_with ( slide , chart_part_ , RT . CHART ) <EOL> assert _rId is rId <EOL> def it_provides_access_to_the_shapes_on_the_slide ( self , shapes_fixture ) : <EOL> slide , SlideShapeTree_ , slide_shape_tree_ = shapes_fixture <EOL> shapes = slide . shapes <EOL> SlideShapeTree_ . assert_called_once_with ( slide ) <EOL> assert shapes is slide_shape_tree_ <EOL> def it_provides_access_to_its_placeholders ( self , placeholders_fixture ) : <EOL> slide , _SlidePlaceholders_ , slide_placeholders_ = ( <EOL> placeholders_fixture <EOL> ) <EOL> placeholders = slide . placeholders <EOL> _SlidePlaceholders_ . assert_called_once_with ( <EOL> slide . _element . spTree , slide <EOL> ) <EOL> assert placeholders is slide_placeholders_ <EOL> def it_can_create_a_new_slide ( self , new_fixture ) : <EOL> slide_layout_ , partname_ , package_ = new_fixture [ : <NUM_LIT:3> ] <EOL> Slide_init_ , slide_elm_ , shapes_ , relate_to_ = new_fixture [ <NUM_LIT:3> : ] <EOL> slide = Slide . new ( slide_layout_ , partname_ , package_ ) <EOL> Slide_init_ . assert_called_once_with ( <EOL> partname_ , CT . PML_SLIDE , slide_elm_ , package_ <EOL> ) <EOL> shapes_ . clone_layout_placeholders . assert_called_once_with ( <EOL> slide_layout_ <EOL> ) <EOL> relate_to_ . assert_called_once_with ( <EOL> slide , slide_layout_ , RT . SLIDE_LAYOUT <EOL> ) <EOL> assert isinstance ( slide , Slide ) <EOL> def it_knows_the_slide_layout_it_inherits_from ( self , layout_fixture ) : <EOL> slide , slide_layout_ = layout_fixture <EOL> slide_layout = slide . slide_layout <EOL> slide . part_related_by . assert_called_once_with ( RT . SLIDE_LAYOUT ) <EOL> assert slide_layout is slide_layout_ <EOL> def it_knows_the_minimal_element_xml_for_a_slide ( self , slide ) : <EOL> path = absjoin ( test_file_dir , '<STR_LIT>' ) <EOL> sld = CT_Slide . new ( ) <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> expected_xml = f . read ( ) <EOL> assert sld . xml == expected_xml <EOL> @ pytest . fixture <EOL> def add_chart_part_fixture ( <EOL> self , package_ , chart_type_ , chart_data_ , ChartPart_ , <EOL> chart_part_ , rId , relate_to_ ) : <EOL> slide = Slide ( None , None , None , package_ ) <EOL> return ( <EOL> slide , chart_type_ , chart_data_ , ChartPart_ , chart_part_ , <EOL> package_ , rId <EOL> ) <EOL> @ pytest . fixture <EOL> def layout_fixture ( self , slide_layout_ , part_related_by_ ) : <EOL> slide = Slide ( None , None , None , None ) <EOL> return slide , slide_layout_ <EOL> @ pytest . fixture <EOL> def placeholders_fixture ( self , slide_elm_ , _SlidePlaceholders_ , <EOL> slide_placeholders_ ) : <EOL> slide = Slide ( None , None , slide_elm_ , None ) <EOL> return slide , _SlidePlaceholders_ , slide_placeholders_ <EOL> @ pytest . fixture <EOL> def shapes_fixture ( self , SlideShapeTree_ , slide_shape_tree_ ) : <EOL> slide = Slide ( None , None , None , None ) <EOL> return slide , SlideShapeTree_ , slide_shape_tree_ <EOL> @ pytest . fixture <EOL> def new_fixture ( <EOL> self , slide_layout_ , partname_ , package_ , Slide_init_ , <EOL> CT_Slide_ , slide_elm_ , shapes_prop_ , shapes_ , <EOL> relate_to_ ) : <EOL> return ( <EOL> slide_layout_ , partname_ , package_ , Slide_init_ , slide_elm_ , <EOL> shapes_ , relate_to_ <EOL> ) <EOL> @ pytest . fixture <EOL> def ChartPart_ ( self , request , chart_part_ ) : <EOL> ChartPart_ = class_mock ( request , '<STR_LIT>' ) <EOL> ChartPart_ . new . return_value = chart_part_ <EOL> return ChartPart_ <EOL> @ pytest . fixture <EOL> def chart_data_ ( self , request ) : <EOL> return instance_mock ( request , ChartData ) <EOL> @ pytest . fixture <EOL> def chart_part_ ( self , request ) : <EOL> return instance_mock ( request , ChartPart ) <EOL> @ pytest . fixture <EOL> def chart_type_ ( self , request ) : <EOL> return instance_mock ( request , EnumValue ) <EOL> @ pytest . fixture <EOL> def CT_Slide_ ( self , request , slide_elm_ ) : <EOL> CT_Slide_ = class_mock ( request , '<STR_LIT>' ) <EOL> CT_Slide_ . new . return_value = slide_elm_ <EOL> return CT_Slide_ <EOL> @ pytest . fixture <EOL> def package_ ( self , request ) : <EOL> return instance_mock ( request , Package ) <EOL> @ pytest . fixture <EOL> def part_related_by_ ( self , request , slide_layout_ ) : <EOL> return method_mock ( <EOL> request , Slide , '<STR_LIT>' , <EOL> return_value = slide_layout_ <EOL> ) <EOL> @ pytest . fixture <EOL> def partname_ ( self , request ) : <EOL> return instance_mock ( request , PackURI ) <EOL> @ pytest . fixture <EOL> def relate_to_ ( self , request , rId ) : <EOL> return method_mock ( <EOL> request , Part , '<STR_LIT>' , autospec = True , return_value = rId <EOL> ) <EOL> @ pytest . fixture <EOL> def rId ( self ) : <EOL> return '<STR_LIT>' <EOL> @ pytest . fixture <EOL> def shapes_ ( self , request ) : <EOL> return instance_mock ( request , SlideShapeTree ) <EOL> @ pytest . fixture <EOL> def shapes_prop_ ( self , request , shapes_ ) : <EOL> return property_mock ( request , Slide , '<STR_LIT>' , return_value = shapes_ ) <EOL> @ pytest . fixture <EOL> def slide ( self ) : <EOL> return Slide ( None , None , None , None ) <EOL> @ pytest . fixture <EOL> def _SlidePlaceholders_ ( self , request , slide_placeholders_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = slide_placeholders_ <EOL> ) <EOL> @ pytest . fixture <EOL> def SlideShapeTree_ ( self , request , slide_shape_tree_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = slide_shape_tree_ <EOL> ) <EOL> @ pytest . fixture <EOL> def slide_elm_ ( self , request ) : <EOL> return instance_mock ( request , CT_Slide ) <EOL> @ pytest . fixture <EOL> def Slide_init_ ( self , request ) : <EOL> return initializer_mock ( request , Slide ) <EOL> @ pytest . fixture <EOL> def slide_layout_ ( self , request ) : <EOL> return instance_mock ( request , SlideLayout ) <EOL> @ pytest . fixture <EOL> def slide_placeholders_ ( self , request ) : <EOL> return instance_mock ( request , _SlidePlaceholders ) <EOL> @ pytest . fixture <EOL> def slide_shape_tree_ ( self , request ) : <EOL> return instance_mock ( request , SlideShapeTree ) <EOL> class Describe_SlidePlaceholders ( object ) : <EOL> def it_can_get_a_placeholder_by_idx ( self , getitem_fixture ) : <EOL> placeholders , idx , SlideShapeFactory_ = getitem_fixture [ : <NUM_LIT:3> ] <EOL> shape_elm , placeholder_ = getitem_fixture [ <NUM_LIT:3> : ] <EOL> placeholder = placeholders [ idx ] <EOL> SlideShapeFactory_ . assert_called_once_with ( shape_elm , placeholders ) <EOL> assert placeholder is placeholder_ <EOL> def it_can_iterate_over_its_placeholders ( self , iter_fixture ) : <EOL> placeholders , SlideShapeFactory_ = iter_fixture [ : <NUM_LIT:2> ] <EOL> expected_calls , expected_values = iter_fixture [ <NUM_LIT:2> : ] <EOL> ps = [ p for p in placeholders ] <EOL> assert SlideShapeFactory_ . call_args_list == expected_calls <EOL> assert ps == expected_values <EOL> def it_knows_how_many_placeholders_it_contains ( self , len_fixture ) : <EOL> placeholders , expected_value = len_fixture <EOL> assert len ( placeholders ) == expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <EOL> <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:1> ) , <EOL> ] ) <EOL> def getitem_fixture ( self , request , SlideShapeFactory_ , placeholder_ ) : <EOL> spTree_cxml , idx , offset = request . param <EOL> spTree = element ( spTree_cxml ) <EOL> placeholders = _SlidePlaceholders ( spTree , None ) <EOL> shape_elm = spTree [ offset ] <EOL> SlideShapeFactory_ . return_value = placeholder_ <EOL> return placeholders , idx , SlideShapeFactory_ , shape_elm , placeholder_ <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ) ) , <EOL> ] ) <EOL> def iter_fixture ( self , request , SlideShapeFactory_ , placeholder_ ) : <EOL> spTree_cxml , sequence = request . param <EOL> spTree = element ( spTree_cxml ) <EOL> placeholders = _SlidePlaceholders ( spTree , None ) <EOL> SlideShapeFactory_ . return_value = placeholder_ <EOL> calls = [ call ( spTree [ i ] , placeholders ) for i in sequence ] <EOL> values = [ placeholder_ ] * len ( sequence ) <EOL> return placeholders , SlideShapeFactory_ , calls , values <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <NUM_LIT:3> ) , <EOL> ] ) <EOL> def len_fixture ( self , request ) : <EOL> spTree_cxml , length = request . param <EOL> placeholders = _SlidePlaceholders ( element ( spTree_cxml ) , None ) <EOL> return placeholders , length <EOL> @ pytest . fixture <EOL> def placeholder_ ( self , request ) : <EOL> return instance_mock ( request , _BaseSlidePlaceholder ) <EOL> @ pytest . fixture <EOL> def SlideShapeFactory_ ( self , request , placeholder_ ) : <EOL> return function_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = placeholder_ <EOL> ) </s>
