<s> import py <EOL> from py . __ . test import parseopt <EOL> class TestParser : <EOL> def test_init ( self , capsys ) : <EOL> parser = parseopt . Parser ( usage = "<STR_LIT>" ) <EOL> py . test . raises ( SystemExit , '<STR_LIT>' ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert out . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> def test_group_add_and_get ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> group = parser . addgroup ( "<STR_LIT:hello>" , description = "<STR_LIT>" ) <EOL> assert group . name == "<STR_LIT:hello>" <EOL> assert group . description == "<STR_LIT>" <EOL> py . test . raises ( ValueError , parser . addgroup , "<STR_LIT:hello>" ) <EOL> group2 = parser . getgroup ( "<STR_LIT:hello>" ) <EOL> assert group2 is group <EOL> def test_getgroup_addsgroup ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> group = parser . getgroup ( "<STR_LIT:hello>" , description = "<STR_LIT>" ) <EOL> assert group . name == "<STR_LIT:hello>" <EOL> assert group . description == "<STR_LIT>" <EOL> group2 = parser . getgroup ( "<STR_LIT:hello>" ) <EOL> assert group2 is group <EOL> def test_group_addoption ( self ) : <EOL> group = parseopt . OptionGroup ( "<STR_LIT:hello>" ) <EOL> group . addoption ( "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> assert len ( group . options ) == <NUM_LIT:1> <EOL> assert isinstance ( group . options [ <NUM_LIT:0> ] , py . compat . optparse . Option ) <EOL> def test_group_shortopt_lowercase ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> group = parser . addgroup ( "<STR_LIT:hello>" ) <EOL> py . test . raises ( ValueError , """<STR_LIT>""" ) <EOL> assert len ( group . options ) == <NUM_LIT:0> <EOL> group . _addoption ( "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> assert len ( group . options ) == <NUM_LIT:1> <EOL> def test_parser_addoption ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> group = parser . getgroup ( "<STR_LIT>" ) <EOL> assert len ( group . options ) == <NUM_LIT:0> <EOL> group . addoption ( "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> assert len ( group . options ) == <NUM_LIT:1> <EOL> def test_parse ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT:hello>" , action = "<STR_LIT:store>" ) <EOL> option , args = parser . parse ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert option . hello == "<STR_LIT>" <EOL> assert not args <EOL> def test_parse ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> option , args = parser . parse ( [ py . path . local ( ) ] ) <EOL> assert args [ <NUM_LIT:0> ] == py . path . local ( ) <EOL> def test_parse_will_set_default ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT:hello>" , default = "<STR_LIT:x>" , action = "<STR_LIT:store>" ) <EOL> option , args = parser . parse ( [ ] ) <EOL> assert option . hello == "<STR_LIT:x>" <EOL> del option . hello <EOL> args = parser . parse_setoption ( [ ] , option ) <EOL> assert option . hello == "<STR_LIT:x>" <EOL> def test_parse_setoption ( self ) : <EOL> parser = parseopt . Parser ( ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT:hello>" , action = "<STR_LIT:store>" ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT>" , default = <NUM_LIT> ) <EOL> class A : pass <EOL> option = A ( ) <EOL> args = parser . parse_setoption ( [ '<STR_LIT>' , '<STR_LIT>' ] , option ) <EOL> assert option . hello == "<STR_LIT>" <EOL> assert option . world == <NUM_LIT> <EOL> assert not args <EOL> def test_parse_defaultgetter ( self ) : <EOL> def defaultget ( option ) : <EOL> if option . type == "<STR_LIT:int>" : <EOL> option . default = <NUM_LIT> <EOL> elif option . type == "<STR_LIT:string>" : <EOL> option . default = "<STR_LIT>" <EOL> parser = parseopt . Parser ( processopt = defaultget ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , action = "<STR_LIT:store>" ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT:hello>" , type = "<STR_LIT:string>" , action = "<STR_LIT:store>" ) <EOL> parser . addoption ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> option , args = parser . parse ( [ ] ) <EOL> assert option . hello == "<STR_LIT>" <EOL> assert option . this == <NUM_LIT> </s>
