Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PH] argparse.ArgumentParser usage updates #518

Merged
merged 4 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 48 additions & 34 deletions tests/TestHarness/TestHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,87 +37,101 @@ class TestHelper(object):
@staticmethod
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
def parse_args(includeArgs, applicationSpecificArgs=AppArgs()):
def createArgumentParser(includeArgs, applicationSpecificArgs=AppArgs()) -> argparse.ArgumentParser:
"""Accepts set of arguments, builds argument parser and returns parse_args() output."""
assert(includeArgs)
assert(isinstance(includeArgs, set))
assert(isinstance(applicationSpecificArgs, AppArgs))

parser = argparse.ArgumentParser(add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-?', action='help', default=argparse.SUPPRESS,
thParser = argparse.ArgumentParser(add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
thGrpTitle = "Test Helper Arguments"
thGrpDescription="Test Helper configuration items used to configure and spin up the regression test framework and blockchain environment."
thGrp = thParser.add_argument_group(title=thGrpTitle, description=thGrpDescription)
thGrp.add_argument('-?', action='help', default=argparse.SUPPRESS,
help=argparse._('show this help message and exit'))

if "-p" in includeArgs:
parser.add_argument("-p", type=int, help="producing nodes count", default=1)
thGrp.add_argument("-p", type=int, help="producing nodes count", default=1)
if "-n" in includeArgs:
parser.add_argument("-n", type=int, help="total nodes", default=0)
thGrp.add_argument("-n", type=int, help="total nodes", default=0)
if "-d" in includeArgs:
parser.add_argument("-d", type=int, help="delay between nodes startup", default=1)
thGrp.add_argument("-d", type=int, help="delay between nodes startup", default=1)
if "--nodes-file" in includeArgs:
parser.add_argument("--nodes-file", type=str, help="File containing nodes info in JSON format.")
thGrp.add_argument("--nodes-file", type=str, help="File containing nodes info in JSON format.")
if "-s" in includeArgs:
parser.add_argument("-s", type=str, help="topology", choices=["mesh"], default="mesh")
thGrp.add_argument("-s", type=str, help="topology", choices=["mesh"], default="mesh")
if "-c" in includeArgs:
parser.add_argument("-c", type=str, help="chain strategy",
thGrp.add_argument("-c", type=str, help="chain strategy",
choices=[Utils.SyncResyncTag, Utils.SyncReplayTag, Utils.SyncNoneTag, Utils.SyncHardReplayTag],
default=Utils.SyncResyncTag)
if "--kill-sig" in includeArgs:
parser.add_argument("--kill-sig", type=str, choices=[Utils.SigKillTag, Utils.SigTermTag], help="kill signal.",
thGrp.add_argument("--kill-sig", type=str, choices=[Utils.SigKillTag, Utils.SigTermTag], help="kill signal.",
default=Utils.SigKillTag)
if "--kill-count" in includeArgs:
parser.add_argument("--kill-count", type=int, help="nodeos instances to kill", default=-1)
thGrp.add_argument("--kill-count", type=int, help="nodeos instances to kill", default=-1)
if "--terminate-at-block" in includeArgs:
parser.add_argument("--terminate-at-block", type=int, help="block to terminate on when replaying", default=0)
thGrp.add_argument("--terminate-at-block", type=int, help="block to terminate on when replaying", default=0)
if "--seed" in includeArgs:
parser.add_argument("--seed", type=int, help="random seed", default=1)
thGrp.add_argument("--seed", type=int, help="random seed", default=1)

if "--host" in includeArgs:
parser.add_argument("-h", "--host", type=str, help="%s host name" % (Utils.EosServerName),
thGrp.add_argument("-h", "--host", type=str, help="%s host name" % (Utils.EosServerName),
default=TestHelper.LOCAL_HOST)
if "--port" in includeArgs:
parser.add_argument("--port", type=int, help="%s host port" % Utils.EosServerName,
thGrp.add_argument("--port", type=int, help="%s host port" % Utils.EosServerName,
default=TestHelper.DEFAULT_PORT)
if "--wallet-host" in includeArgs:
parser.add_argument("--wallet-host", type=str, help="%s host" % Utils.EosWalletName,
thGrp.add_argument("--wallet-host", type=str, help="%s host" % Utils.EosWalletName,
default=TestHelper.LOCAL_HOST)
if "--wallet-port" in includeArgs:
parser.add_argument("--wallet-port", type=int, help="%s port" % Utils.EosWalletName,
thGrp.add_argument("--wallet-port", type=int, help="%s port" % Utils.EosWalletName,
default=TestHelper.DEFAULT_WALLET_PORT)
if "--prod-count" in includeArgs:
parser.add_argument("-c", "--prod-count", type=int, help="Per node producer count", default=1)
thGrp.add_argument("-c", "--prod-count", type=int, help="Per node producer count", default=1)
if "--defproducera_prvt_key" in includeArgs:
parser.add_argument("--defproducera_prvt_key", type=str, help="defproducera private key.")
thGrp.add_argument("--defproducera_prvt_key", type=str, help="defproducera private key.")
if "--defproducerb_prvt_key" in includeArgs:
parser.add_argument("--defproducerb_prvt_key", type=str, help="defproducerb private key.")
thGrp.add_argument("--defproducerb_prvt_key", type=str, help="defproducerb private key.")
if "--dump-error-details" in includeArgs:
parser.add_argument("--dump-error-details",
thGrp.add_argument("--dump-error-details",
help="Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout",
action='store_true')
if "--dont-launch" in includeArgs:
parser.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
thGrp.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
action='store_true')
if "--keep-logs" in includeArgs:
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders, or other test specific log directories, upon test completion",
thGrp.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders, or other test specific log directories, upon test completion",
action='store_true')
if "-v" in includeArgs:
parser.add_argument("-v", help="verbose logging", action='store_true')
thGrp.add_argument("-v", help="verbose logging", action='store_true')
if "--leave-running" in includeArgs:
parser.add_argument("--leave-running", help="Leave cluster running after test finishes", action='store_true')
thGrp.add_argument("--leave-running", help="Leave cluster running after test finishes", action='store_true')
if "--only-bios" in includeArgs:
parser.add_argument("--only-bios", help="Limit testing to bios node.", action='store_true')
thGrp.add_argument("--only-bios", help="Limit testing to bios node.", action='store_true')
if "--clean-run" in includeArgs:
parser.add_argument("--clean-run", help="Kill all nodeos and keosd instances", action='store_true')
thGrp.add_argument("--clean-run", help="Kill all nodeos and keosd instances", action='store_true')
if "--sanity-test" in includeArgs:
parser.add_argument("--sanity-test", help="Validates nodeos and keosd are in path and can be started up.", action='store_true')
thGrp.add_argument("--sanity-test", help="Validates nodeos and keosd are in path and can be started up.", action='store_true')
if "--alternate-version-labels-file" in includeArgs:
parser.add_argument("--alternate-version-labels-file", type=str, help="Provide a file to define the labels that can be used in the test and the path to the version installation associated with that.")
thGrp.add_argument("--alternate-version-labels-file", type=str, help="Provide a file to define the labels that can be used in the test and the path to the version installation associated with that.")

if len(applicationSpecificArgs.args) > 0:
appArgsGrpTitle="Application Specific Arguments"
appArgsGrpdescription="Test Helper configuration items used to configure and spin up the regression test framework and blockchain environment."
appArgsGrp = thParser.add_argument_group(title=appArgsGrpTitle, description=appArgsGrpdescription)
for arg in applicationSpecificArgs.args:
if arg.type is not None:
appArgsGrp.add_argument(arg.flag, type=arg.type, help=arg.help, choices=arg.choices, default=arg.default)
else:
appArgsGrp.add_argument(arg.flag, help=arg.help, action=arg.action)

for arg in applicationSpecificArgs.args:
if arg.type is not None:
parser.add_argument(arg.flag, type=arg.type, help=arg.help, choices=arg.choices, default=arg.default)
else:
parser.add_argument(arg.flag, help=arg.help, action=arg.action)
return thParser

@staticmethod
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
def parse_args(includeArgs, applicationSpecificArgs=AppArgs()):
parser = TestHelper.createArgumentParser(includeArgs=includeArgs, applicationSpecificArgs=applicationSpecificArgs)
args = parser.parse_args()
return args

Expand Down
Loading