#NEWLINE# def testSubParsers( self ) : #NEWLINE# #INDENT# config_file1 = tempfile . NamedTemporaryFile ( mode = 'w' , delete = True ) #NEWLINE# config_file1 . write ( '--i = B' ) #NEWLINE# config_file1 . flush ( ) #NEWLINE# config_file2 = tempfile . NamedTemporaryFile ( mode = 'w' , delete = True ) #NEWLINE# config_file2 . write ( 'p = 10' ) #NEWLINE# config_file2 . flush ( ) #NEWLINE# parser = configargparse . ArgumentParser ( prog = 'myProg' ) #NEWLINE# subparsers = parser . add_subparsers ( title = 'actions' ) #NEWLINE# parent_parser = configargparse . ArgumentParser ( add_help = False ) #NEWLINE# parent_parser . add_argument ( '-p' , '--p' , type = int , required = True , help = 'set db parameter' ) #NEWLINE# create_p = subparsers . add_parser ( 'create' , parents = [ parent_parser ] , help = 'create the orbix environment' ) #NEWLINE# create_p . add_argument ( '--i' , env_var = 'INIT' , choices = [ 'A' , 'B' ] , default = 'A' ) #NEWLINE# create_p . add_argument ( '-config' , is_config_file = True ) #NEWLINE# update_p = subparsers . add_parser ( 'update' , parents = [ parent_parser ] , help = 'update the orbix environment' ) #NEWLINE# update_p . add_argument ( '-config2' , is_config_file = True , required = True ) #NEWLINE# ns = parser . parse_args ( args = ( 'create -p 2 -config ' + config_file1 . name ) ) #NEWLINE# self . assertEqual ( ns . p , 2 ) #NEWLINE# self . assertEqual ( ns . i , 'B' ) #NEWLINE# ns = parser . parse_args ( args = ( 'update -config2 ' + config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . p , 10 ) #NEWLINE# config_file1 . close ( ) #NEWLINE# config_file2 . close ( )