<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import sys <EOL> from lxml import etree <EOL> from opcdiag . model import Package , PkgItem <EOL> from opcdiag . phys_pkg import PhysPkg <EOL> import pytest <EOL> from mock import call <EOL> from . unitutil import class_mock , instance_mock <EOL> DIRPATH = '<STR_LIT>' <EOL> PACKAGE_PATH = '<STR_LIT>' <EOL> class DescribePackage ( object ) : <EOL> def it_can_construct_from_a_filesystem_package ( <EOL> self , path_ , root_uri_ , uri_ , uri_2_ , blob_ , blob_2_ , PhysPkg_ , <EOL> PkgItem_ , pkg_item_ , pkg_item_2_ , Package_ ) : <EOL> pkg = Package . read ( path_ ) <EOL> expected_PkgItem_calls = [ <EOL> call ( root_uri_ , uri_ , blob_ ) , <EOL> call ( root_uri_ , uri_2_ , blob_2_ ) <EOL> ] <EOL> expected_items = { uri_ : pkg_item_ , <EOL> uri_2_ : pkg_item_2_ } <EOL> PhysPkg_ . read . assert_called_once_with ( path_ ) <EOL> assert PkgItem_ . call_count == <NUM_LIT:2> <EOL> PkgItem_ . assert_has_calls ( expected_PkgItem_calls , any_order = True ) <EOL> Package_ . assert_called_once_with ( expected_items ) <EOL> assert isinstance ( pkg , Package ) <EOL> def it_can_find_one_of_its_items_by_uri_tail ( self , pkg_item_ ) : <EOL> pkg_items_ = { '<STR_LIT>' : pkg_item_ } <EOL> package = Package ( pkg_items_ ) <EOL> pkg_item = package . find_item_by_uri_tail ( '<STR_LIT>' ) <EOL> assert pkg_item == pkg_item_ <EOL> with pytest . raises ( KeyError ) : <EOL> package . find_item_by_uri_tail ( '<STR_LIT>' ) <EOL> def it_can_pretty_format_its_xml_pkg_items ( self , prettify_fixture ) : <EOL> package , pkg_item_ , pkg_item_2_ = prettify_fixture <EOL> package . prettify_xml ( ) <EOL> pkg_item_ . prettify_xml . assert_called_once_with ( ) <EOL> pkg_item_2_ . prettify_xml . assert_called_once_with ( ) <EOL> def it_can_provide_a_list_of_rels_items_in_the_package ( <EOL> self , pkg_item_ , pkg_item_2_ , pkg_item_3_ ) : <EOL> pkg_items = { <EOL> '<STR_LIT>' : pkg_item_ , <EOL> '<STR_LIT>' : pkg_item_2_ , <EOL> '<STR_LIT>' : pkg_item_3_ , <EOL> } <EOL> package = Package ( pkg_items ) <EOL> rels_items = package . rels_items <EOL> assert rels_items == [ pkg_item_3_ , pkg_item_ ] <EOL> def it_can_provide_a_list_of_xml_parts_in_the_package ( <EOL> self , pkg_item_ , pkg_item_2_ , pkg_item_3_ ) : <EOL> pkg_items = { <EOL> '<STR_LIT>' : pkg_item_ , <EOL> '<STR_LIT>' : pkg_item_2_ , <EOL> '<STR_LIT>' : pkg_item_3_ , <EOL> } <EOL> package = Package ( pkg_items ) <EOL> xml_parts = package . xml_parts <EOL> assert xml_parts == [ pkg_item_3_ , pkg_item_ ] <EOL> def it_can_save_itself_to_a_zip ( <EOL> self , pkg_item_dict_ , PhysPkg_ , blob_collection_ ) : <EOL> package = Package ( pkg_item_dict_ ) <EOL> package . save ( PACKAGE_PATH ) <EOL> PhysPkg_ . write_to_zip . assert_called_once_with ( <EOL> blob_collection_ , PACKAGE_PATH ) <EOL> def it_can_save_an_expanded_version_of_itself_to_a_directory ( <EOL> self , pkg_item_dict_ , PhysPkg_ , blob_collection_ ) : <EOL> package = Package ( pkg_item_dict_ ) <EOL> package . save_to_dir ( DIRPATH ) <EOL> PhysPkg_ . write_to_dir . assert_called_once_with ( <EOL> blob_collection_ , DIRPATH ) <EOL> def it_can_change_one_of_its_items_to_another ( <EOL> self , pkg_item_ , pkg_item_2_ ) : <EOL> pkg_items = { '<STR_LIT>' : pkg_item_ } <EOL> package = Package ( pkg_items ) <EOL> pkg_item_2_ . uri = '<STR_LIT>' <EOL> pkg_item_2_ . blob = '<STR_LIT>' <EOL> package . substitute_item ( pkg_item_2_ ) <EOL> assert pkg_item_ . blob == '<STR_LIT>' <EOL> @ pytest . fixture <EOL> def blob_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> @ pytest . fixture <EOL> def blob_2_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> @ pytest . fixture <EOL> def blob_collection_ ( self , request , uri_ , uri_2_ , blob_ , blob_2_ ) : <EOL> return { uri_ : blob_ , uri_2_ : blob_2_ } <EOL> @ pytest . fixture <EOL> def Package_ ( self , request ) : <EOL> Package_ = class_mock ( '<STR_LIT>' , request ) <EOL> return Package_ <EOL> @ pytest . fixture <EOL> def path_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> @ pytest . fixture <EOL> def PhysPkg_ ( self , request , phys_pkg_ ) : <EOL> PhysPkg_ = class_mock ( '<STR_LIT>' , request ) <EOL> PhysPkg_ . read . return_value = phys_pkg_ <EOL> return PhysPkg_ <EOL> @ pytest . fixture <EOL> def phys_pkg_ ( self , request , root_uri_ , uri_ , uri_2_ , blob_ , blob_2_ ) : <EOL> phys_pkg = instance_mock ( PhysPkg , request ) <EOL> phys_pkg . root_uri = root_uri_ <EOL> phys_pkg . __iter__ . return_value = iter ( ( ( uri_ , blob_ ) , <EOL> ( uri_2_ , blob_2_ ) ) ) <EOL> return phys_pkg <EOL> @ pytest . fixture <EOL> def PkgItem_ ( self , request , pkg_item_ , pkg_item_2_ ) : <EOL> PkgItem_ = class_mock ( '<STR_LIT>' , request ) <EOL> PkgItem_ . side_effect = [ pkg_item_ , pkg_item_2_ ] <EOL> return PkgItem_ <EOL> @ pytest . fixture <EOL> def pkg_item_ ( self , request , blob_ ) : <EOL> pkg_item_ = instance_mock ( PkgItem , request ) <EOL> pkg_item_ . blob = blob_ <EOL> pkg_item_ . is_rels_item = True <EOL> pkg_item_ . is_xml_part = True <EOL> return pkg_item_ <EOL> @ pytest . fixture <EOL> def pkg_item_2_ ( self , request , blob_2_ ) : <EOL> pkg_item_2_ = instance_mock ( PkgItem , request ) <EOL> pkg_item_2_ . blob = blob_2_ <EOL> pkg_item_2_ . is_rels_item = False <EOL> pkg_item_2_ . is_xml_part = False <EOL> return pkg_item_2_ <EOL> @ pytest . fixture <EOL> def pkg_item_3_ ( self , request ) : <EOL> pkg_item_3_ = instance_mock ( PkgItem , request ) <EOL> pkg_item_3_ . is_rels_item = True <EOL> pkg_item_3_ . is_xml_part = True <EOL> return pkg_item_3_ <EOL> @ pytest . fixture <EOL> def pkg_item_dict_ ( self , request , uri_ , uri_2_ , pkg_item_ , pkg_item_2_ ) : <EOL> return { uri_ : pkg_item_ , uri_2_ : pkg_item_2_ } <EOL> @ pytest . fixture <EOL> def prettify_fixture ( self , pkg_item_ , pkg_item_2_ ) : <EOL> pkg_items = { <NUM_LIT:1> : pkg_item_ , <NUM_LIT:2> : pkg_item_2_ } <EOL> package = Package ( pkg_items ) <EOL> return package , pkg_item_ , pkg_item_2_ <EOL> @ pytest . fixture <EOL> def root_uri_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> @ pytest . fixture <EOL> def uri_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> @ pytest . fixture <EOL> def uri_2_ ( self , request ) : <EOL> return instance_mock ( str , request ) <EOL> class DescribePkgItem ( object ) : <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , [ <EOL> ( '<STR_LIT>' , True , False , False ) , <EOL> ( '<STR_LIT>' , False , True , False ) , <EOL> ( '<STR_LIT>' , False , False , True ) , <EOL> ( '<STR_LIT>' , False , False , False ) , <EOL> ] ) <EOL> def it_knows_what_kind_of_item_it_is ( <EOL> self , uri , is_ct , is_rels , is_xml_part ) : <EOL> pkg_item = PkgItem ( None , uri , None ) <EOL> assert pkg_item . is_content_types is is_ct <EOL> assert pkg_item . is_rels_item is is_rels <EOL> assert pkg_item . is_xml_part is is_xml_part <EOL> def it_can_produce_an_etree_element_from_its_blob ( self ) : <EOL> blob = '<STR_LIT>' <EOL> pkg_item = PkgItem ( None , None , blob ) <EOL> assert isinstance ( pkg_item . element , etree . _Element ) <EOL> def it_can_calculate_its_effective_path ( self ) : <EOL> pkg_item = PkgItem ( '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> expected_path = ( '<STR_LIT>' if sys . platform . startswith ( '<STR_LIT>' ) <EOL> else '<STR_LIT>' ) <EOL> assert pkg_item . path == expected_path <EOL> def it_can_prettify_its_xml ( self ) : <EOL> blob = '<STR_LIT>' <EOL> pkg_item = PkgItem ( None , '<STR_LIT>' , blob ) <EOL> pkg_item . prettify_xml ( ) <EOL> assert pkg_item . blob == ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) </s>
