<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , unicode_literals <EOL> import pytest <EOL> from docx . image . image import Image <EOL> from docx . opc . packuri import PackURI <EOL> from docx . package import ImageParts , Package <EOL> from docx . parts . image import ImagePart <EOL> from . unitutil . file import docx_path <EOL> from . unitutil . mock import class_mock , instance_mock , method_mock <EOL> class DescribePackage ( object ) : <EOL> def it_gathers_package_image_parts_after_unmarshalling ( self ) : <EOL> package = Package . open ( docx_path ( '<STR_LIT>' ) ) <EOL> image_parts = package . image_parts <EOL> assert len ( image_parts ) == <NUM_LIT:3> <EOL> for image_part in image_parts : <EOL> assert isinstance ( image_part , ImagePart ) <EOL> class DescribeImageParts ( object ) : <EOL> def it_can_get_a_matching_image_part ( self , get_image_part_fixture ) : <EOL> image_parts , image_descriptor , image_part_ = get_image_part_fixture <EOL> image_part = image_parts . get_or_add_image_part ( image_descriptor ) <EOL> assert image_part is image_part_ <EOL> def it_can_add_a_new_image_part ( self , add_image_part_fixture ) : <EOL> image_parts , image_descriptor , image_ , image_part_ = ( <EOL> add_image_part_fixture <EOL> ) <EOL> image_part = image_parts . get_or_add_image_part ( image_descriptor ) <EOL> image_parts . _add_image_part . assert_called_once_with ( image_ ) <EOL> assert image_part is image_part_ <EOL> def it_knows_the_next_available_image_partname ( <EOL> self , next_partname_fixture ) : <EOL> image_parts , ext , expected_partname = next_partname_fixture <EOL> assert image_parts . _next_image_partname ( ext ) == expected_partname <EOL> def it_can_really_add_a_new_image_part ( <EOL> self , really_add_image_part_fixture ) : <EOL> image_parts , image_ , ImagePart_ , partname_ , image_part_ = ( <EOL> really_add_image_part_fixture <EOL> ) <EOL> image_part = image_parts . _add_image_part ( image_ ) <EOL> ImagePart_ . from_image . assert_called_once_with ( image_ , partname_ ) <EOL> assert image_part in image_parts <EOL> assert image_part is image_part_ <EOL> @ pytest . fixture <EOL> def _add_image_part_ ( self , request , new_image_part_ ) : <EOL> return method_mock ( <EOL> request , ImageParts , '<STR_LIT>' , <EOL> return_value = new_image_part_ <EOL> ) <EOL> @ pytest . fixture <EOL> def add_image_part_fixture ( <EOL> self , Image_ , _add_image_part_ , image_descriptor_ , image_ , <EOL> new_image_part_ , ) : <EOL> image_parts = ImageParts ( ) <EOL> return image_parts , image_descriptor_ , image_ , new_image_part_ <EOL> @ pytest . fixture <EOL> def get_image_part_fixture ( self , Image_ , image_part_ , image_descriptor_ ) : <EOL> image_parts = ImageParts ( ) <EOL> image_parts . append ( image_part_ ) <EOL> return image_parts , image_descriptor_ , image_part_ <EOL> @ pytest . fixture <EOL> def Image_ ( self , request , image_ ) : <EOL> Image_ = class_mock ( request , '<STR_LIT>' ) <EOL> Image_ . from_file . return_value = image_ <EOL> return Image_ <EOL> @ pytest . fixture <EOL> def image_ ( self , request , sha1 ) : <EOL> image_ = instance_mock ( request , Image ) <EOL> image_ . sha1 = sha1 <EOL> return image_ <EOL> @ pytest . fixture <EOL> def image_descriptor_ ( self , request ) : <EOL> return instance_mock ( request , str ) <EOL> @ pytest . fixture <EOL> def ImagePart_ ( self , request , image_part_ ) : <EOL> ImagePart_ = class_mock ( request , '<STR_LIT>' ) <EOL> ImagePart_ . from_image . return_value = image_part_ <EOL> return ImagePart_ <EOL> @ pytest . fixture <EOL> def image_part_ ( self , request , sha1 ) : <EOL> image_part_ = instance_mock ( request , ImagePart ) <EOL> image_part_ . sha1 = sha1 <EOL> return image_part_ <EOL> def _image_part_with_partname_ ( self , request , n ) : <EOL> partname = self . _image_partname ( n ) <EOL> return instance_mock ( request , ImagePart , partname = partname ) <EOL> def _image_partname ( self , n ) : <EOL> return PackURI ( '<STR_LIT>' % n ) <EOL> @ pytest . fixture <EOL> def new_image_part_ ( self , request ) : <EOL> return instance_mock ( request , ImagePart ) <EOL> @ pytest . fixture <EOL> def _next_image_partname_ ( self , request ) : <EOL> return method_mock ( request , ImageParts , '<STR_LIT>' ) <EOL> @ pytest . fixture ( params = [ ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , <NUM_LIT:1> ) , ( ( <NUM_LIT:1> , <NUM_LIT:3> ) , <NUM_LIT:2> ) , ( ( <NUM_LIT:1> , <NUM_LIT:2> ) , <NUM_LIT:3> ) ] ) <EOL> def next_partname_fixture ( self , request ) : <EOL> existing_partname_numbers , expected_partname_number = request . param <EOL> image_parts = ImageParts ( ) <EOL> for n in existing_partname_numbers : <EOL> image_part_ = self . _image_part_with_partname_ ( request , n ) <EOL> image_parts . append ( image_part_ ) <EOL> ext = '<STR_LIT>' <EOL> expected_image_partname = self . _image_partname ( <EOL> expected_partname_number <EOL> ) <EOL> return image_parts , ext , expected_image_partname <EOL> @ pytest . fixture <EOL> def partname_ ( self , request ) : <EOL> return instance_mock ( request , PackURI ) <EOL> @ pytest . fixture <EOL> def really_add_image_part_fixture ( <EOL> self , _next_image_partname_ , partname_ , image_ , ImagePart_ , <EOL> image_part_ ) : <EOL> image_parts = ImageParts ( ) <EOL> _next_image_partname_ . return_value = partname_ <EOL> return image_parts , image_ , ImagePart_ , partname_ , image_part_ <EOL> @ pytest . fixture <EOL> def sha1 ( self ) : <EOL> return '<STR_LIT>' </s>
