#NEWLINE# def testBasicCase2( self , use_groups = False ) : #NEWLINE# #INDENT# default_config_file = tempfile . NamedTemporaryFile ( mode = 'w' , delete = True ) #NEWLINE# default_config_file . flush ( ) #NEWLINE# p = self . initParser ( default_config_files = [ '/etc/settings.ini' , '/home/jeff/.user_settings' , default_config_file . name ] ) #NEWLINE# p . add_arg ( 'vcf' , nargs = '+' , help = 'Variant file(s)' ) #NEWLINE# if ( not use_groups ) : #NEWLINE# #INDENT# self . add_arg ( '--genome' , help = 'Path to genome file' , required = True ) #NEWLINE# self . add_arg ( '-v' , dest = 'verbose' , action = 'store_true' ) #NEWLINE# self . add_arg ( '-g' , '--my-cfg-file' , required = True , is_config_file = True ) #NEWLINE# self . add_arg ( '-d' , '--dbsnp' , env_var = 'DBSNP_PATH' ) #NEWLINE# self . add_arg ( '-f' , '--format' , choices = [ 'BED' , 'MAF' , 'VCF' , 'WIG' , 'R' ] , dest = 'fmt' , metavar = 'FRMT' , env_var = 'OUTPUT_FORMAT' , default = 'BED' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# g = p . add_argument_group ( title = 'g1' ) #NEWLINE# g . add_arg ( '--genome' , help = 'Path to genome file' , required = True ) #NEWLINE# g . add_arg ( '-v' , dest = 'verbose' , action = 'store_true' ) #NEWLINE# g . add_arg ( '-g' , '--my-cfg-file' , required = True , is_config_file = True ) #NEWLINE# g = p . add_argument_group ( title = 'g2' ) #NEWLINE# g . add_arg ( '-d' , '--dbsnp' , env_var = 'DBSNP_PATH' ) #NEWLINE# g . add_arg ( '-f' , '--format' , choices = [ 'BED' , 'MAF' , 'VCF' , 'WIG' , 'R' ] , dest = 'fmt' , metavar = 'FRMT' , env_var = 'OUTPUT_FORMAT' , default = 'BED' ) #NEWLINE# #UNINDENT# self . assertParseArgsRaises ( ( 'too few arg' if ( sys . version_info < ( 3 , 3 ) ) else 'the following arguments are required: vcf, -g/--my-cfg-file' ) , args = '--genome hg19' ) #NEWLINE# self . assertParseArgsRaises ( 'not found: file.txt' , args = '-g file.txt' ) #NEWLINE# config_file2 = tempfile . NamedTemporaryFile ( mode = 'w' , delete = True ) #NEWLINE# config_file2 . flush ( ) #NEWLINE# ns = self . parse ( args = ( '--genome hg19 -g %s bla.vcf ' % config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . genome , 'hg19' ) #NEWLINE# self . assertEqual ( ns . verbose , False ) #NEWLINE# self . assertEqual ( ns . dbsnp , None ) #NEWLINE# self . assertEqual ( ns . fmt , 'BED' ) #NEWLINE# self . assertListEqual ( ns . vcf , [ 'bla.vcf' ] ) #NEWLINE# self . assertRegex ( self . format_values ( ) , 'Command Line Args:   --genome hg19 -g [^\\s]+ bla.vcf\nDefaults:\n  --format: \\s+ BED\n' ) #NEWLINE# default_config_file . write ( '--format MAF' ) #NEWLINE# default_config_file . flush ( ) #NEWLINE# ns = self . parse ( args = ( '--genome hg19 -g %s f.vcf ' % config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . fmt , 'MAF' ) #NEWLINE# self . assertRegex ( self . format_values ( ) , 'Command Line Args:   --genome hg19 -g [^\\s]+ f.vcf\nConfig File \\([^\\s]+\\):\n  --format: \\s+ MAF\n' ) #NEWLINE# config_file2 . write ( '--format VCF' ) #NEWLINE# config_file2 . flush ( ) #NEWLINE# ns = self . parse ( args = ( '--genome hg19 -g %s f.vcf ' % config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . fmt , 'VCF' ) #NEWLINE# self . assertRegex ( self . format_values ( ) , 'Command Line Args:   --genome hg19 -g [^\\s]+ f.vcf\nConfig File \\([^\\s]+\\):\n  --format: \\s+ VCF\n' ) #NEWLINE# ns = self . parse ( env_vars = { #NEWLINE# #INDENT# 'OUTPUT_FORMAT' : 'R' , #NEWLINE# 'DBSNP_PATH' : '/a/b.vcf' , #NEWLINE# #UNINDENT# } , args = ( '--genome hg19 -g %s f.vcf ' % config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . fmt , 'R' ) #NEWLINE# self . assertEqual ( ns . dbsnp , '/a/b.vcf' ) #NEWLINE# self . assertRegex ( self . format_values ( ) , 'Command Line Args:   --genome hg19 -g [^\\s]+ f.vcf\nEnvironment Variables:\n  DBSNP_PATH: \\s+ /a/b.vcf\n  OUTPUT_FORMAT: \\s+ R\n' ) #NEWLINE# ns = self . parse ( env_vars = { #NEWLINE# #INDENT# 'OUTPUT_FORMAT' : 'R' , #NEWLINE# 'DBSNP_PATH' : '/a/b.vcf' , #NEWLINE# 'ANOTHER_VAR' : 'something' , #NEWLINE# #UNINDENT# } , args = ( '--genome hg19 -g %s --format WIG f.vcf' % config_file2 . name ) ) #NEWLINE# self . assertEqual ( ns . fmt , 'WIG' ) #NEWLINE# self . assertEqual ( ns . dbsnp , '/a/b.vcf' ) #NEWLINE# self . assertRegex ( self . format_values ( ) , 'Command Line Args:   --genome hg19 -g [^\\s]+ --format WIG f.vcf\nEnvironment Variables:\n  DBSNP_PATH: \\s+ /a/b.vcf\n' ) #NEWLINE# if ( not use_groups ) : #NEWLINE# #INDENT# self . assertRegex ( self . format_help ( ) , ( ( 'usage: .* \\[-h\\] --genome GENOME \\[-v\\] -g MY_CFG_FILE \\[-d DBSNP\\]\\s+\\[-f FRMT\\]\\s+vcf \\[vcf ...\\]\n\n' + ( 9 * '(.+\\s+)' ) ) + 'positional arguments:\n  vcf \\s+ Variant file\\(s\\)\n\noptional arguments:\n  -h, --help \\s+ show this help message and exit\n  --genome GENOME \\s+ Path to genome file\n  -v\n  -g MY_CFG_FILE, --my-cfg-file MY_CFG_FILE\n  -d DBSNP, --dbsnp DBSNP\\s+\\[env var: DBSNP_PATH\\]\n  -f FRMT, --format FRMT\\s+\\[env var: OUTPUT_FORMAT\\]\n' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertRegex ( self . format_help ( ) , ( ( 'usage: .* \\[-h\\] --genome GENOME \\[-v\\] -g MY_CFG_FILE \\[-d DBSNP\\]\\s+\\[-f FRMT\\]\\s+vcf \\[vcf ...\\]\n\n' + ( 9 * '.+\\s+' ) ) + 'positional arguments:\n  vcf \\s+ Variant file\\(s\\)\n\noptional arguments:\n  -h, --help \\s+ show this help message and exit\n\ng1:\n  --genome GENOME \\s+ Path to genome file\n  -v\n  -g MY_CFG_FILE, --my-cfg-file MY_CFG_FILE\n\ng2:\n  -d DBSNP, --dbsnp DBSNP\\s+\\[env var: DBSNP_PATH\\]\n  -f FRMT, --format FRMT\\s+\\[env var: OUTPUT_FORMAT\\]\n' ) ) #NEWLINE# #UNINDENT# self . assertParseArgsRaises ( "invalid choice: 'ZZZ'" , args = ( '--genome hg19 -g %s --format ZZZ f.vcf' % config_file2 . name ) ) #NEWLINE# self . assertParseArgsRaises ( 'unrecognized arguments: --bla' , args = ( '--bla --genome hg19 -g %s f.vcf' % config_file2 . name ) ) #NEWLINE# default_config_file . close ( ) #NEWLINE# config_file2 . close ( )