<s> """<STR_LIT>""" <EOL> import argparse <EOL> from opcdiag . cli import ( <EOL> BrowseCommand , Command , CommandController , DiffCommand , DiffItemCommand , <EOL> ExtractCommand , RepackageCommand , SubstituteCommand , main <EOL> ) <EOL> from opcdiag . controller import OpcController <EOL> import pytest <EOL> from mock import ANY , Mock <EOL> from . unitutil import class_mock , instance_mock , loose_mock , relpath <EOL> ARG_DIRPATH = '<STR_LIT>' <EOL> ARG_PKG_PATH = '<STR_LIT>' <EOL> ARG_PKG_2_PATH = '<STR_LIT>' <EOL> ARG_FILENAME = '<STR_LIT>' <EOL> ARG_NEW_PACKAGE = '<STR_LIT>' <EOL> ARG_SRC_PKG_PATH = '<STR_LIT>' <EOL> ARG_TGT_PKG_PATH = '<STR_LIT>' <EOL> ARG_RESULT_PKG_PATH = '<STR_LIT>' <EOL> CMD_WORD_BROWSE = '<STR_LIT>' <EOL> CMD_WORD_DIFF = '<STR_LIT>' <EOL> CMD_WORD_DIFF_ITEM = '<STR_LIT>' <EOL> CMD_WORD_EXTRACT = '<STR_LIT>' <EOL> CMD_WORD_REPACKAGE = '<STR_LIT>' <EOL> CMD_WORD_SUBSTITUTE = '<STR_LIT>' <EOL> MINI_DIR_PKG_PATH = relpath ( '<STR_LIT>' ) <EOL> MINI_ZIP_PKG_PATH = relpath ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def app_controller_ ( request ) : <EOL> return instance_mock ( OpcController , request ) <EOL> @ pytest . fixture <EOL> def args_ ( request , command_ ) : <EOL> args_ = loose_mock ( request ) <EOL> args_ . command = command_ <EOL> return args_ <EOL> @ pytest . fixture <EOL> def argv_ ( request ) : <EOL> return instance_mock ( list , request ) <EOL> @ pytest . fixture <EOL> def browse_argv_ ( ) : <EOL> return [ CMD_WORD_BROWSE , ARG_PKG_PATH , ARG_FILENAME ] <EOL> @ pytest . fixture <EOL> def CommandController_ ( request , command_controller_ ) : <EOL> CommandController_ = class_mock ( '<STR_LIT>' , request ) <EOL> CommandController_ . return_value = command_controller_ <EOL> CommandController_ . new . return_value = command_controller_ <EOL> return CommandController_ <EOL> @ pytest . fixture <EOL> def Command_ ( request , command_cls_ , parser_ ) : <EOL> Command_ = class_mock ( '<STR_LIT>' , request , autospec = False ) <EOL> Command_ . __subclasses__ = Mock ( return_value = [ command_cls_ ] ) <EOL> Command_ . parser . return_value = parser_ <EOL> return Command_ <EOL> @ pytest . fixture <EOL> def command_ ( request ) : <EOL> return instance_mock ( Command , request ) <EOL> @ pytest . fixture <EOL> def command_cls_ ( request , command_ , command_parser_ ) : <EOL> command_cls_ = loose_mock ( request ) <EOL> command_cls_ . return_value = command_ <EOL> command_cls_ . add_command_parser_to . return_value = command_parser_ <EOL> return command_cls_ <EOL> @ pytest . fixture <EOL> def command_controller_ ( request ) : <EOL> return instance_mock ( CommandController , request ) <EOL> @ pytest . fixture <EOL> def command_parser_ ( request ) : <EOL> command_parser_ = instance_mock ( argparse . ArgumentParser , request ) <EOL> return command_parser_ <EOL> @ pytest . fixture <EOL> def diff_argv_ ( ) : <EOL> return [ CMD_WORD_DIFF , ARG_PKG_PATH , ARG_PKG_2_PATH ] <EOL> @ pytest . fixture <EOL> def diff_item_argv_ ( ) : <EOL> return [ CMD_WORD_DIFF_ITEM , ARG_PKG_PATH , ARG_PKG_2_PATH , ARG_FILENAME ] <EOL> @ pytest . fixture <EOL> def extract_argv_ ( ) : <EOL> return [ CMD_WORD_EXTRACT , ARG_PKG_PATH , ARG_DIRPATH ] <EOL> @ pytest . fixture <EOL> def OpcController_ ( request , app_controller_ ) : <EOL> OpcController_ = class_mock ( '<STR_LIT>' , request ) <EOL> OpcController_ . return_value = app_controller_ <EOL> return OpcController_ <EOL> @ pytest . fixture <EOL> def parser ( ) : <EOL> return argparse . ArgumentParser ( ) <EOL> @ pytest . fixture <EOL> def parser_ ( request , args_ ) : <EOL> parser_ = instance_mock ( argparse . ArgumentParser , request ) <EOL> parser_ . parse_args . return_value = args_ <EOL> return parser_ <EOL> @ pytest . fixture <EOL> def repackage_argv_ ( ) : <EOL> return [ CMD_WORD_REPACKAGE , ARG_DIRPATH , ARG_NEW_PACKAGE ] <EOL> @ pytest . fixture <EOL> def subparsers ( parser ) : <EOL> return parser . add_subparsers ( ) <EOL> @ pytest . fixture <EOL> def substitute_argv_ ( ) : <EOL> return [ CMD_WORD_SUBSTITUTE , ARG_FILENAME , ARG_SRC_PKG_PATH , <EOL> ARG_TGT_PKG_PATH , ARG_RESULT_PKG_PATH ] <EOL> class DescribeMain ( object ) : <EOL> def it_should_execute_the_command_in_argv ( <EOL> self , argv_ , CommandController_ , command_controller_ ) : <EOL> main ( argv_ ) <EOL> CommandController_ . new . assert_called_once_with ( ) <EOL> command_controller_ . execute . assert_called_once_with ( argv_ ) <EOL> class DescribeCommand ( object ) : <EOL> def it_can_configure_the_command_line_parser ( <EOL> self , Command_ , command_cls_ , command_ , command_parser_ ) : <EOL> parser = Command . parser ( ) <EOL> command_cls_ . add_command_parser_to . assert_called_once_with ( ANY ) <EOL> command_cls_ . assert_called_once_with ( command_parser_ ) <EOL> command_parser_ . set_defaults . assert_called_once_with ( command = command_ ) <EOL> assert isinstance ( parser , argparse . ArgumentParser ) <EOL> def it_should_raise_if_validate_not_implemented_on_subclass ( self ) : <EOL> command = Command ( None ) <EOL> with pytest . raises ( NotImplementedError ) : <EOL> command . validate ( None ) <EOL> def it_should_raise_if_execute_not_implemented_on_subclass ( self ) : <EOL> command = Command ( None ) <EOL> with pytest . raises ( NotImplementedError ) : <EOL> command . execute ( None , None ) <EOL> class DescribeCommandController ( object ) : <EOL> def it_can_be_constructed_with_its_factory_method ( <EOL> self , Command_ , CommandController_ , command_controller_ , parser_ , <EOL> OpcController_ , app_controller_ ) : <EOL> command_controller = CommandController . new ( ) <EOL> Command_ . parser . assert_called_once_with ( ) <EOL> OpcController_ . assert_called_once_with ( ) <EOL> CommandController_ . assert_called_once_with ( parser_ , app_controller_ ) <EOL> assert command_controller is command_controller_ <EOL> def it_can_execute_a_command_in_argv_form ( <EOL> self , parser_ , app_controller_ , argv_ , args_ , command_ ) : <EOL> command_controller = CommandController ( parser_ , app_controller_ ) <EOL> argv_ . __len__ . return_value = <NUM_LIT:2> <EOL> command_controller . execute ( argv_ ) <EOL> command_ . validate . assert_called_once_with ( args_ ) <EOL> command_ . execute . assert_called_once_with ( args_ , app_controller_ ) <EOL> class DescribeBrowseCommand ( object ) : <EOL> def it_should_add_a_browse_command_parser ( <EOL> self , browse_argv_ , parser , subparsers ) : <EOL> subparser = BrowseCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( browse_argv_ ) <EOL> assert args . pkg_path == ARG_PKG_PATH <EOL> assert args . filename == ARG_FILENAME <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> def it_should_trigger_parser_error_if_pkg_path_does_not_exist ( <EOL> self , args_ , parser_ ) : <EOL> args_ . pkg_path = '<STR_LIT>' <EOL> browse_command = BrowseCommand ( parser_ ) <EOL> browse_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> def it_can_dispatch_browse_command_to_app ( self , args_ , app_controller_ ) : <EOL> browse_command = BrowseCommand ( None ) <EOL> browse_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . browse . assert_called_once_with ( args_ . pkg_path , <EOL> args_ . filename ) <EOL> class DescribeDiffCommand ( object ) : <EOL> def it_should_add_a_diff_command_parser ( <EOL> self , subparsers , parser , diff_argv_ ) : <EOL> subparser = DiffCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( diff_argv_ ) <EOL> assert args . pkg_1_path == ARG_PKG_PATH <EOL> assert args . pkg_2_path == ARG_PKG_2_PATH <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , [ <EOL> ( '<STR_LIT>' , MINI_ZIP_PKG_PATH , '<STR_LIT>' ) , <EOL> ( MINI_ZIP_PKG_PATH , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def it_should_trigger_parser_error_if_pkg_path_does_not_exist ( <EOL> self , pkg_1_path , pkg_2_path , err_frag , args_ , parser_ ) : <EOL> args_ . pkg_1_path = pkg_1_path <EOL> args_ . pkg_2_path = pkg_2_path <EOL> diff_command = DiffCommand ( parser_ ) <EOL> diff_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> assert err_frag in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> def it_can_dispatch_a_diff_command_to_the_app ( <EOL> self , args_ , app_controller_ ) : <EOL> diff_command = DiffCommand ( None ) <EOL> diff_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . diff_pkg . assert_called_once_with ( <EOL> args_ . pkg_1_path , args_ . pkg_2_path ) <EOL> class DescribeDiffItemCommand ( object ) : <EOL> def it_should_add_a_diff_item_command_parser ( <EOL> self , diff_item_argv_ , parser , subparsers ) : <EOL> subparser = DiffItemCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( diff_item_argv_ ) <EOL> assert args . pkg_1_path == ARG_PKG_PATH <EOL> assert args . pkg_2_path == ARG_PKG_2_PATH <EOL> assert args . filename == ARG_FILENAME <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , [ <EOL> ( '<STR_LIT>' , MINI_ZIP_PKG_PATH , '<STR_LIT>' ) , <EOL> ( MINI_ZIP_PKG_PATH , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def it_should_trigger_parser_error_if_pkg_path_does_not_exist ( <EOL> self , pkg_1_path , pkg_2_path , err_frag , args_ , parser_ ) : <EOL> args_ . pkg_1_path = pkg_1_path <EOL> args_ . pkg_2_path = pkg_2_path <EOL> diff_item_command = DiffItemCommand ( parser_ ) <EOL> diff_item_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> assert err_frag in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> def it_can_dispatch_diff_item_command_to_app ( self , args_ , app_controller_ ) : <EOL> diff_item_command = DiffItemCommand ( None ) <EOL> diff_item_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . diff_item . assert_called_once_with ( <EOL> args_ . pkg_1_path , args_ . pkg_2_path , args_ . filename ) <EOL> class DescribeExtractCommand ( object ) : <EOL> def it_should_add_a_extract_command_parser ( <EOL> self , extract_argv_ , parser , subparsers ) : <EOL> subparser = ExtractCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( extract_argv_ ) <EOL> assert args . pkg_path == ARG_PKG_PATH <EOL> assert args . dirpath == ARG_DIRPATH <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> def it_should_trigger_parser_error_if_pkg_path_does_not_exist ( <EOL> self , args_ , parser_ ) : <EOL> args_ . pkg_path = '<STR_LIT>' <EOL> extract_command = ExtractCommand ( parser_ ) <EOL> extract_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> assert '<STR_LIT>' in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> def it_can_dispatch_an_extract_command_to_the_app ( <EOL> self , args_ , app_controller_ ) : <EOL> extract_command = ExtractCommand ( None ) <EOL> extract_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . extract_package . assert_called_once_with ( <EOL> args_ . pkg_path , args_ . dirpath ) <EOL> class DescribeRepackageCommand ( object ) : <EOL> def it_should_add_a_repackage_command_parser ( <EOL> self , repackage_argv_ , parser , subparsers ) : <EOL> subparser = RepackageCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( repackage_argv_ ) <EOL> assert args . dirpath == ARG_DIRPATH <EOL> assert args . new_package == ARG_NEW_PACKAGE <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> def it_should_trigger_parser_error_if_dirpath_not_a_directory ( <EOL> self , args_ , parser_ ) : <EOL> args_ . dirpath = '<STR_LIT>' <EOL> repackage_command = RepackageCommand ( parser_ ) <EOL> repackage_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> assert '<STR_LIT>' in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> assert '<STR_LIT>' in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> def it_can_dispatch_a_repackage_command_to_the_app ( <EOL> self , args_ , app_controller_ ) : <EOL> repackage_command = RepackageCommand ( None ) <EOL> repackage_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . repackage . assert_called_once_with ( <EOL> args_ . dirpath , args_ . new_package ) <EOL> class DescribeSubstituteCommand ( object ) : <EOL> def it_should_add_a_substitute_command_parser ( <EOL> self , substitute_argv_ , parser , subparsers ) : <EOL> subparser = SubstituteCommand . add_command_parser_to ( subparsers ) <EOL> args = parser . parse_args ( substitute_argv_ ) <EOL> assert args . filename == ARG_FILENAME <EOL> assert args . src_pkg_path == ARG_SRC_PKG_PATH <EOL> assert args . tgt_pkg_path == ARG_TGT_PKG_PATH <EOL> assert args . result_pkg_path == ARG_RESULT_PKG_PATH <EOL> assert isinstance ( subparser , argparse . ArgumentParser ) <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , [ <EOL> ( '<STR_LIT>' , MINI_ZIP_PKG_PATH , '<STR_LIT>' ) , <EOL> ( MINI_ZIP_PKG_PATH , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def it_should_trigger_parser_error_if_pkg_path_does_not_exist ( <EOL> self , src_pkg_path , tgt_pkg_path , err_frag , args_ , parser_ ) : <EOL> args_ . src_pkg_path = src_pkg_path <EOL> args_ . tgt_pkg_path = tgt_pkg_path <EOL> substitute_command = SubstituteCommand ( parser_ ) <EOL> substitute_command . validate ( args_ ) <EOL> parser_ . error . assert_called_once_with ( ANY ) <EOL> assert err_frag in parser_ . error . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> def it_can_dispatch_a_substitute_command_to_the_app ( <EOL> self , args_ , app_controller_ ) : <EOL> substitute_command = SubstituteCommand ( None ) <EOL> substitute_command . execute ( args_ , app_controller_ ) <EOL> app_controller_ . substitute . assert_called_once_with ( <EOL> args_ . filename , args_ . src_pkg_path , args_ . tgt_pkg_path , <EOL> args_ . result_pkg_path ) </s>
