Beispiel #1
0
 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)
Beispiel #2
0
 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')
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 def test_invalid_value(self):
     opt = CmdOption({'name': 'op1', 'default': '', 'type': int})
     pytest.raises(CmdParseError, opt.str2type, 'not a number')
Beispiel #6
0
 def test_int(self):
     opt = CmdOption({'name': 'op1', 'default': '', 'type': int})
     assert 2 == opt.str2type('2')
     assert -3 == opt.str2type('-3')
Beispiel #7
0
 def set_options(self):
     options = [opt_bool, opt_rare, opt_int, opt_no]
     return [CmdOption(o) for o in options]
Beispiel #8
0
 def test_bool(self):
     opt = CmdOption({'name':'op1', 'default':'', 'type':bool})
     assert False == opt.str2type('off')
     assert True == opt.str2type('on')
Beispiel #9
0
 def test_no_long(self):
     opt1 = CmdOption({'name':'op1', 'default':'', 'type':str,
                       'short':'s'})
     assert '-s ARG' == opt1.help_param()
Beispiel #10
0
 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()
Beispiel #11
0
 def test_bool_param(self):
     opt1 = CmdOption({'name':'op1', 'default':'', 'type':bool,
                       'short':'b', 'long': 'bobo'})
     assert '-b, --bobo' == opt1.help_param()
Beispiel #12
0
 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 ')
Beispiel #13
0
 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]
Beispiel #14
0
 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]
Beispiel #15
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)
Beispiel #16
0
 def test_str(self):
     opt = CmdOption({'name':'op1', 'default':'', 'type':str})
     assert 'foo' == opt.str2type('foo')
     assert 'bar' == opt.str2type('bar')
Beispiel #17
0
 def test_no_doc_param(self):
     opt1 = CmdOption(opt_no)
     assert 0 == len(opt1.help_doc())
Beispiel #18
0
 def test_int(self):
     opt = CmdOption({'name':'op1', 'default':'', 'type':int})
     assert 2 == opt.str2type('2')
     assert -3 == opt.str2type('-3')
Beispiel #19
0
 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
Beispiel #20
0
 def test_bool(self):
     opt = CmdOption({'name': 'op1', 'default': '', 'type': bool})
     assert False == opt.str2type('off')
     assert True == opt.str2type('on')
Beispiel #21
0
 def test_choices_nodesc_doc(self):
     the_opt = CmdOption(opt_choices_nodesc)
     doc = the_opt.help_doc()[0]
     assert "choices: no, yes" in doc
Beispiel #22
0
 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 ')
Beispiel #23
0
 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
Beispiel #24
0
 def test_no_doc_param(self):
     opt1 = CmdOption(opt_no)
     assert 0 == len(opt1.help_doc())
Beispiel #25
0
 def test_non_required_fields(self):
     opt1 = CmdOption({'name':'op1', 'default':''})
     assert '' == opt1.long
Beispiel #26
0
 def test_choices_nodesc_doc(self):
     the_opt = CmdOption(opt_choices_nodesc)
     doc = the_opt.help_doc()[0]
     assert "choices: no, yes" in doc
Beispiel #27
0
 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]