mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Add tests for argparse
This commit is contained in:
parent
7944e0cd98
commit
9b709b7f98
@ -245,8 +245,7 @@ def run_set_replicas(args):
|
||||
except r.ReqlOpFailedError as e:
|
||||
logger.warn(e)
|
||||
|
||||
|
||||
def main():
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Control your BigchainDB node.',
|
||||
parents=[utils.base_parser])
|
||||
@ -325,8 +324,8 @@ def main():
|
||||
'is set, the count is distributed equally to all the '
|
||||
'processes')
|
||||
|
||||
utils.start(parser, globals())
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
def main():
|
||||
utils.start(create_parser(), sys.argv[1:], globals())
|
||||
|
@ -59,7 +59,7 @@ def start_rethinkdb():
|
||||
raise StartupError(line)
|
||||
|
||||
|
||||
def start(parser, scope):
|
||||
def start(parser, argv, scope):
|
||||
"""Utility function to execute a subcommand.
|
||||
|
||||
The function will look up in the ``scope``
|
||||
@ -74,11 +74,11 @@ def start(parser, scope):
|
||||
NotImplementedError: if ``scope`` doesn't contain a function called
|
||||
``run_<parser.args.command>``.
|
||||
"""
|
||||
args = parser.parse_args()
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if not args.command:
|
||||
parser.print_help()
|
||||
return
|
||||
raise SystemExit()
|
||||
|
||||
# look up in the current scope for a function called 'run_<command>'
|
||||
# replacing all the dashes '-' with the lowercase character '_'
|
||||
@ -96,7 +96,7 @@ def start(parser, scope):
|
||||
elif args.multiprocess is None:
|
||||
args.multiprocess = mp.cpu_count()
|
||||
|
||||
func(args)
|
||||
return func(args)
|
||||
|
||||
|
||||
base_parser = argparse.ArgumentParser(add_help=False, prog='bigchaindb')
|
||||
|
@ -62,6 +62,34 @@ def mock_bigchaindb_backup_config(monkeypatch):
|
||||
monkeypatch.setattr('bigchaindb._config', config)
|
||||
|
||||
|
||||
def test_make_sure_we_dont_remove_any_command():
|
||||
# thanks to: http://stackoverflow.com/a/18161115/597097
|
||||
from bigchaindb.commands.bigchain import utils
|
||||
from bigchaindb.commands.bigchain import create_parser
|
||||
parser = create_parser()
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
utils.start(parser, [], {})
|
||||
|
||||
assert parser.parse_args(['configure']).command
|
||||
assert parser.parse_args(['show-config']).command
|
||||
assert parser.parse_args(['export-my-pubkey']).command
|
||||
assert parser.parse_args(['init']).command
|
||||
assert parser.parse_args(['drop']).command
|
||||
assert parser.parse_args(['start']).command
|
||||
assert parser.parse_args(['set-shards', '1']).command
|
||||
assert parser.parse_args(['set-replicas', '1']).command
|
||||
assert parser.parse_args(['load']).command
|
||||
|
||||
|
||||
@patch('bigchaindb.commands.utils.start')
|
||||
def test_main_entrypoint(mock_start):
|
||||
from bigchaindb.commands.bigchain import main
|
||||
main()
|
||||
|
||||
assert mock_start.called
|
||||
|
||||
|
||||
def test_bigchain_run_start(mock_run_configure, mock_processes_start, mock_db_init_with_existing_db):
|
||||
from bigchaindb.commands.bigchain import run_start
|
||||
args = Namespace(start_rethinkdb=False, allow_temp_keypair=False, config=None, yes=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user