#NEWLINE# def testConstructor_WriteOutConfigFileArgs2( self ) : #NEWLINE# #INDENT# cfg_f = tempfile . NamedTemporaryFile ( mode = 'w+' , delete = True ) #NEWLINE# self . initParser ( args_for_writing_out_config_file = [ '-w' ] , write_out_config_file_arg_help_message = 'write config' ) #NEWLINE# self . add_arg ( '-not-config-file-settable' ) #NEWLINE# self . add_arg ( '-a' , '--arg1' , type = int , env_var = 'ARG1' ) #NEWLINE# self . add_arg ( '-b' , '--arg2' , type = int , default = 3 ) #NEWLINE# self . add_arg ( '-c' , '--arg3' ) #NEWLINE# self . add_arg ( '-d' , '--arg4' ) #NEWLINE# self . add_arg ( '-e' , '--arg5' ) #NEWLINE# self . add_arg ( '--config-file-settable-flag' , action = 'store_true' , env_var = 'FLAG_ARG' ) #NEWLINE# self . add_arg ( '-l' , '--config-file-settable-list' , action = 'append' ) #NEWLINE# command_line_args = ( '-w %s ' % cfg_f . name ) #NEWLINE# command_line_args += '-l a -l b -l c -l d ' #NEWLINE# self . assertFalse ( self . parser . _exit_method_called ) #NEWLINE# ns = self . parse ( command_line_args , env_vars = { #NEWLINE# #INDENT# 'ARG1' : '10' , #NEWLINE# 'FLAG_ARG' : 'true' , #NEWLINE# 'SOME_OTHER_ENV_VAR' : '2' , #NEWLINE# #UNINDENT# } , config_file_contents = 'arg3 = bla3\narg4 = bla4' ) #NEWLINE# self . assertTrue ( self . parser . _exit_method_called ) #NEWLINE# cfg_f . seek ( 0 ) #NEWLINE# expected_config_file_contents = 'config-file-settable-list = [a, b, c, d]\n' #NEWLINE# expected_config_file_contents += 'arg1 = 10\n' #NEWLINE# expected_config_file_contents += 'config-file-settable-flag = True\n' #NEWLINE# expected_config_file_contents += 'arg3 = bla3\n' #NEWLINE# expected_config_file_contents += 'arg4 = bla4\n' #NEWLINE# expected_config_file_contents += 'arg2 = 3\n' #NEWLINE# self . assertEqual ( cfg_f . read ( ) . strip ( ) , expected_config_file_contents . strip ( ) ) #NEWLINE# self . assertRaisesRegex ( ValueError , "Couldn't open / for writing:" , self . parse , args = ( command_line_args + ' -w /' ) )