<s> """<STR_LIT>""" <EOL> import re <EOL> from nose . tools import assert_is , assert_equal , assert_raises , assert_true <EOL> from . . support . param import Parameter <EOL> from . . support import constraints as cnstr <EOL> from . . interface . base import Interface <EOL> from . . utils import swallow_outputs <EOL> from . utils import assert_re_in <EOL> class Demo ( Interface ) : <EOL> """<STR_LIT>""" <EOL> _params_ = dict ( <EOL> demoposarg = Parameter ( <EOL> doc = "<STR_LIT>" , <EOL> constraints = cnstr . EnsureInt ( ) , <EOL> nargs = <NUM_LIT:2> ) , <EOL> demooptposarg1 = Parameter ( <EOL> args = ( '<STR_LIT>' , ) , <EOL> doc = "<STR_LIT>" , <EOL> constraints = cnstr . EnsureInt ( ) , <EOL> nargs = '<STR_LIT:?>' ) , <EOL> demooptposarg2 = Parameter ( <EOL> args = ( '<STR_LIT>' , ) , <EOL> doc = "<STR_LIT>" , <EOL> constraints = cnstr . EnsureInt ( ) , <EOL> nargs = '<STR_LIT:?>' ) , <EOL> demoarg = Parameter ( <EOL> doc = "<STR_LIT>" , <EOL> constraints = cnstr . EnsureInt ( ) ) ) <EOL> def __call__ ( self , demoposarg , demooptposarg1 = <NUM_LIT> , demooptposarg2 = <NUM_LIT> , demoarg = <NUM_LIT:100> ) : <EOL> return demoarg <EOL> def test_param ( ) : <EOL> p = Parameter ( ) <EOL> pname = '<STR_LIT>' <EOL> assert_equal ( pname , p . get_autodoc ( '<STR_LIT>' ) ) <EOL> doc = '<STR_LIT>' <EOL> p = Parameter ( doc = doc ) <EOL> assert_equal ( '<STR_LIT>' % ( pname , doc ) , p . get_autodoc ( '<STR_LIT>' ) ) <EOL> p = Parameter ( doc = doc , constraints = cnstr . EnsureInt ( ) | cnstr . EnsureStr ( ) ) <EOL> autodoc = p . get_autodoc ( '<STR_LIT>' ) <EOL> assert_true ( "<STR_LIT>" in autodoc ) <EOL> assert_true ( '<STR_LIT>' in autodoc ) <EOL> assert_true ( '<STR_LIT>' in autodoc ) <EOL> def test_interface ( ) : <EOL> di = Demo ( ) <EOL> import argparse <EOL> parser = argparse . ArgumentParser ( ) <EOL> di . setup_parser ( parser ) <EOL> with swallow_outputs ( ) as cmo : <EOL> assert_equal ( parser . print_help ( ) , None ) <EOL> assert ( cmo . out ) <EOL> assert_equal ( cmo . err , '<STR_LIT>' ) <EOL> args = parser . parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_is ( args . demoarg , <NUM_LIT> ) <EOL> assert_equal ( args . demoposarg , [ <NUM_LIT> , <NUM_LIT:11> ] ) <EOL> assert_equal ( args . demooptposarg1 , <NUM_LIT:1> ) <EOL> assert_equal ( args . demooptposarg2 , <NUM_LIT:2> ) <EOL> with swallow_outputs ( ) as cmo : <EOL> assert_raises ( SystemExit , parser . parse_args , [ '<STR_LIT>' , '<STR_LIT:abc>' ] ) <EOL> assert_re_in ( "<STR_LIT>" , <EOL> cmo . err , re . DOTALL ) <EOL> with swallow_outputs ( ) as cmo : <EOL> assert_raises ( SystemExit , parser . parse_args , [ '<STR_LIT>' ] ) <EOL> assert_re_in ( "<STR_LIT>" , cmo . err , re . DOTALL ) <EOL> with swallow_outputs ( ) as cmo : <EOL> assert_raises ( SystemExit , parser . parse_args , [ '<STR_LIT>' ] ) <EOL> assert_re_in ( "<STR_LIT>" , <EOL> cmo . err , re . DOTALL ) </s>
