forked from LBRYCommunity/lbry-sdk
add CLI docopt parsing tests to integration tests
This commit is contained in:
parent
257d025d98
commit
58dd576adc
2 changed files with 52 additions and 1 deletions
|
@ -2715,6 +2715,28 @@ t
|
|||
return d
|
||||
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def jsonrpc_cli_test_command(self, pos_arg, pos_args=[], pos_arg2=None, pos_arg3=None):
|
||||
"""
|
||||
This command is only for testing the CLI argument parsing
|
||||
Usage:
|
||||
cli_test_command (<pos_arg> | --pos_arg=<pos_arg>)
|
||||
[<pos_args>...] [--pos_arg2=<pos_arg2>]
|
||||
[--pos_arg3=<pos_arg3>]
|
||||
|
||||
Options:
|
||||
<pos_arg2>, --pos_arg2=<pos_arg2> : pos arg 2
|
||||
<pos_arg3>, --pos_arg3=<pos_arg3> : pos arg 3
|
||||
|
||||
Returns:
|
||||
pos args
|
||||
"""
|
||||
out = (pos_arg, pos_args, pos_arg2, pos_arg3)
|
||||
response = yield self._render_response(out)
|
||||
defer.returnValue(response)
|
||||
|
||||
|
||||
class _ResolveNameHelper(object):
|
||||
def __init__(self, daemon, name, force_refresh):
|
||||
self.daemon = daemon
|
||||
|
|
|
@ -22,7 +22,7 @@ def lbrynet_cli(commands):
|
|||
cli_cmd=['lbrynet-cli']
|
||||
for cmd in commands:
|
||||
cli_cmd.append(cmd)
|
||||
p = subprocess.Popen(cli_cmd,shell=False,stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(cli_cmd,shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
out,err = p.communicate()
|
||||
return out,err
|
||||
|
||||
|
@ -65,6 +65,35 @@ class TestIntegration(unittest.TestCase):
|
|||
out = json.loads(out)
|
||||
self.assertTrue(out['is_running'])
|
||||
|
||||
|
||||
def test_cli_docopts(self):
|
||||
out,err = lbrynet_cli(['cli_test_command'])
|
||||
self.assertEqual('',out)
|
||||
self.assertTrue('Usage' in err)
|
||||
|
||||
out,err = lbrynet_cli(['cli_test_command','1','--not_a_arg=1'])
|
||||
self.assertEqual('',out)
|
||||
self.assertTrue('Usage' in err)
|
||||
|
||||
out,err = lbrynet_cli(['cli_test_command','1'])
|
||||
out = json.loads(out)
|
||||
self.assertEqual([1,[],None,None], out)
|
||||
|
||||
out,err = lbrynet_cli(['cli_test_command','1','--pos_arg2=1'])
|
||||
out = json.loads(out)
|
||||
self.assertEqual([1,[],1,None], out)
|
||||
|
||||
|
||||
out,err = lbrynet_cli(['cli_test_command','1', '--pos_arg2=2','--pos_arg3=3'])
|
||||
out = json.loads(out)
|
||||
self.assertEqual([1,[],2,3], out)
|
||||
|
||||
out,err = lbrynet_cli(['cli_test_command','1','2','3'])
|
||||
out = json.loads(out)
|
||||
# TODO: variable length arguments don't have guess_type() on them
|
||||
self.assertEqual([1,['2','3'],None,None], out)
|
||||
|
||||
|
||||
def test_status(self):
|
||||
out = lbrynet.status()
|
||||
self.assertTrue(out['is_running'])
|
||||
|
|
Loading…
Reference in a new issue