def test_param(self): opt1 = CmdOption(opt_bool) got = opt1.help_doc() assert '-f, --flag' in got[0] assert 'help for opt1' in got[0] assert '--no-flag' in got[1] assert 2 == len(got)
def test_str2boolean(self): opt = CmdOption({'name':'op1', 'default':'', 'type':bool, 'short':'b', 'long': 'bobo'}) assert True == opt.str2boolean('1') assert True == opt.str2boolean('yes') assert True == opt.str2boolean('Yes') assert True == opt.str2boolean('YES') assert True == opt.str2boolean('true') assert True == opt.str2boolean('on') assert False == opt.str2boolean('0') assert False == opt.str2boolean('false') assert False == opt.str2boolean('no') assert False == opt.str2boolean('off') assert False == opt.str2boolean('OFF') pytest.raises(ValueError, opt.str2boolean, '2') pytest.raises(ValueError, opt.str2boolean, None) pytest.raises(ValueError, opt.str2boolean, 'other')
def cmd(self, request): opt_list = (opt_bool, opt_rare, opt_int, opt_no) options = [CmdOption(o) for o in opt_list] cmd = CmdParse(options) return cmd
def test_choices_desc_doc(self): the_opt = CmdOption(opt_choices_desc) doc = the_opt.help_doc()[0] assert 'choices:\n' in doc assert 'yes: signify affirmative' in doc assert 'no: signify negative' in doc
def test_invalid_value(self): opt = CmdOption({'name': 'op1', 'default': '', 'type': int}) pytest.raises(CmdParseError, opt.str2type, 'not a number')
def test_int(self): opt = CmdOption({'name': 'op1', 'default': '', 'type': int}) assert 2 == opt.str2type('2') assert -3 == opt.str2type('-3')
def set_options(self): options = [opt_bool, opt_rare, opt_int, opt_no] return [CmdOption(o) for o in options]
def test_bool(self): opt = CmdOption({'name':'op1', 'default':'', 'type':bool}) assert False == opt.str2type('off') assert True == opt.str2type('on')
def test_no_long(self): opt1 = CmdOption({'name':'op1', 'default':'', 'type':str, 'short':'s'}) assert '-s ARG' == opt1.help_param()
def test_non_bool_param(self): opt1 = CmdOption({'name':'op1', 'default':'', 'type':str, 'short':'s', 'long': 'susu'}) assert '-s ARG, --susu=ARG' == opt1.help_param()
def test_bool_param(self): opt1 = CmdOption({'name':'op1', 'default':'', 'type':bool, 'short':'b', 'long': 'bobo'}) assert '-b, --bobo' == opt1.help_param()
def test_list(self): opt = CmdOption({'name':'op1', 'default':'', 'type':list}) assert ['foo'] == opt.str2type('foo') assert [] == opt.str2type('') assert ['foo', 'bar'] == opt.str2type('foo , bar ')
def test_name_config_env(self): opt1 = CmdOption(opt_rare) got = opt1.help_doc() assert 'config: rare_bool' in got[0] assert 'environ: RARE' in got[0]
def test_non_string_values_are_not_converted(self): opt = CmdOption({'name':'op1', 'default':'', 'type':bool}) assert False == opt.str2type(False) assert True == opt.str2type(True) assert None == opt.str2type(None)
def test_str(self): opt = CmdOption({'name':'op1', 'default':'', 'type':str}) assert 'foo' == opt.str2type('foo') assert 'bar' == opt.str2type('bar')
def test_no_doc_param(self): opt1 = CmdOption(opt_no) assert 0 == len(opt1.help_doc())
def test_int(self): opt = CmdOption({'name':'op1', 'default':'', 'type':int}) assert 2 == opt.str2type('2') assert -3 == opt.str2type('-3')
def test_bool(self): opt = CmdOption({'name': 'op1', 'default': '', 'type': bool}) assert False == opt.str2type('off') assert True == opt.str2type('on')
def test_choices_nodesc_doc(self): the_opt = CmdOption(opt_choices_nodesc) doc = the_opt.help_doc()[0] assert "choices: no, yes" in doc
def test_list(self): opt = CmdOption({'name': 'op1', 'default': '', 'type': list}) assert ['foo'] == opt.str2type('foo') assert [] == opt.str2type('') assert ['foo', 'bar'] == opt.str2type('foo , bar ')
def cmd(self, request): opt_list = (opt_bool, opt_rare, opt_int, opt_no, opt_append, opt_choices_desc, opt_choices_nodesc) options = [CmdOption(o) for o in opt_list] cmd = CmdParse(options) return cmd
def test_non_required_fields(self): opt1 = CmdOption({'name':'op1', 'default':''}) assert '' == opt1.long
def set_options(self): opt_list = (self.my_base_opts + self.my_opts + self.base_options + self._loader.cmd_options + self.cmd_options) return [CmdOption(opt) for opt in opt_list]