#NEWLINE# def testConfigOrEnvValueErrors( self ) : #NEWLINE# #INDENT# self . initParser ( ) #NEWLINE# self . add_arg ( '--height' , env_var = 'HEIGHT' , required = True ) #NEWLINE# self . add_arg ( '--do-it' , dest = 'x' , env_var = 'FLAG1' , action = 'store_true' ) #NEWLINE# self . add_arg ( '--dont-do-it' , dest = 'x' , env_var = 'FLAG2' , action = 'store_false' ) #NEWLINE# ns = self . parse ( '' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'tall' , #NEWLINE# 'FLAG1' : 'yes' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . height , 'tall' ) #NEWLINE# self . assertEqual ( ns . x , True ) #NEWLINE# ns = self . parse ( '' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'tall' , #NEWLINE# 'FLAG2' : 'no' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . x , False ) #NEWLINE# self . initParser ( ) #NEWLINE# self . add_arg ( '-v' , '--verbose' , env_var = 'VERBOSE' , action = 'store_true' ) #NEWLINE# self . assertParseArgsRaises ( "Unexpected value for VERBOSE: 'bla'. Expecting 'true', 'false', 'yes', or 'no'" , env_vars = { #NEWLINE# #INDENT# 'VERBOSE' : 'bla' , #NEWLINE# #UNINDENT# } ) #NEWLINE# ns = self . parse ( '' , config_file_contents = 'verbose=true' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'true' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . verbose , True ) #NEWLINE# ns = self . parse ( '' , config_file_contents = 'verbose' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'true' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . verbose , True ) #NEWLINE# ns = self . parse ( '' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'true' , #NEWLINE# 'VERBOSE' : 'true' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . verbose , True ) #NEWLINE# ns = self . parse ( '' , config_file_contents = '--verbose' , env_vars = { #NEWLINE# #INDENT# 'HEIGHT' : 'true' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( self . verbose , True ) #NEWLINE# self . initParser ( ) #NEWLINE# self . add_arg ( '-f' , '--file' , env_var = 'FILES' , action = 'append' , type = int ) #NEWLINE# ns = self . parse ( '' , env_vars = { #NEWLINE# #INDENT# 'file' : '[1,2,3]' , #NEWLINE# 'VERBOSE' : 'true' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ns . file , None )