3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

test-runner: fix --help and unknown options

If --help or unknown options were supplied to test-runner python
would thrown a maximum recusion depth exception. This was due to
the way ArgumentParser was subclassed.

To fix this call ArgumentParser.__init__() rather than using the
super() method. And do this also for the RunnerCoreArgParse
subclass as well. In addition the namespace argument was removed
from parse_args since its not used, and instead supplied directly
to the parents parse_args method.
This commit is contained in:
James Prestwood 2022-04-05 11:30:11 -07:00 committed by Denis Kenzior
parent 01efa0171d
commit 96e8c0a3ab

View File

@ -82,7 +82,7 @@ class RunnerNamespace(Namespace):
#
class RunnerCoreArgParse(ArgumentParser):
def __init__(self, *args, **kwargs):
super().__init__(self, *args, **kwargs)
ArgumentParser.__init__(self, *args, **kwargs)
self.add_argument('--start', '-s',
help='Custom init process in virtual environment',
@ -144,23 +144,23 @@ class RunnerCoreArgParse(ArgumentParser):
dest='valgrind')
# Overwrite to use a custom namespace class and parse from env
def parse_args(self, *args, namespace=RunnerNamespace()):
def parse_args(self, *args):
if len(sys.argv) > 1:
return super().parse_args(*args, namespace=namespace)
return super().parse_args(*args, namespace=RunnerNamespace())
options = []
for k, v in os.environ.items():
options.append('--' + k)
options.append(v)
return self.parse_known_args(args=options, namespace=namespace)[0]
return self.parse_known_args(args=options, namespace=RunnerNamespace())[0]
#
# Arguments only needed outside the test environment
#
class RunnerArgParse(RunnerCoreArgParse):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
RunnerCoreArgParse.__init__(self, *args, **kwargs)
self.add_argument('--runner', '-r',
metavar='<runner type>',