addons: Fix arguments parser when running pytest (#3327)
This commit is contained in:
parent
6f389014f1
commit
81eabb5f61
|
@ -379,13 +379,14 @@ def api01(data):
|
||||||
token = token.next
|
token = token.next
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args_parser():
|
||||||
parser = cppcheckdata.ArgumentParser()
|
parser = cppcheckdata.ArgumentParser()
|
||||||
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
|
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
|
||||||
return parser.parse_args()
|
return parser
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = get_args()
|
parser = get_args_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.verify:
|
if args.verify:
|
||||||
VERIFY = True
|
VERIFY = True
|
||||||
|
|
|
@ -3377,7 +3377,7 @@ and 20.13, run:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args_parser():
|
||||||
"""Generates list of command-line arguments acceptable by misra.py script."""
|
"""Generates list of command-line arguments acceptable by misra.py script."""
|
||||||
parser = cppcheckdata.ArgumentParser()
|
parser = cppcheckdata.ArgumentParser()
|
||||||
parser.add_argument("--rule-texts", type=str, help=RULE_TEXTS_HELP)
|
parser.add_argument("--rule-texts", type=str, help=RULE_TEXTS_HELP)
|
||||||
|
@ -3391,11 +3391,12 @@ def get_args():
|
||||||
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
|
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
|
||||||
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
|
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
|
||||||
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
|
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
|
||||||
return parser.parse_args()
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_args()
|
parser = get_args_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
settings = MisraSettings(args)
|
settings = MisraSettings(args)
|
||||||
checker = MisraChecker(settings)
|
checker = MisraChecker(settings)
|
||||||
|
|
||||||
|
|
|
@ -18,18 +18,20 @@ def test_arguments_regression():
|
||||||
# Arguments with expected SystemExit
|
# Arguments with expected SystemExit
|
||||||
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
||||||
|
|
||||||
from addons.cert import get_args
|
from addons.cert import get_args_parser
|
||||||
|
|
||||||
for arg in args_exit:
|
for arg in args_exit:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
||||||
for arg in args_ok:
|
for arg in args_ok:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
try:
|
try:
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
|
@ -29,8 +29,9 @@ def teardown_module(module):
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def checker():
|
def checker():
|
||||||
from addons.misra import MisraChecker, MisraSettings, get_args
|
from addons.misra import MisraChecker, MisraSettings, get_args_parser
|
||||||
args = get_args()
|
parser = get_args_parser()
|
||||||
|
args = parser.parse_args([])
|
||||||
settings = MisraSettings(args)
|
settings = MisraSettings(args)
|
||||||
return MisraChecker(settings)
|
return MisraChecker(settings)
|
||||||
|
|
||||||
|
@ -135,18 +136,20 @@ def test_arguments_regression():
|
||||||
# Arguments with expected SystemExit
|
# Arguments with expected SystemExit
|
||||||
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
||||||
|
|
||||||
from addons.misra import get_args
|
from addons.misra import get_args_parser
|
||||||
|
|
||||||
for arg in args_exit:
|
for arg in args_exit:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
||||||
for arg in args_ok:
|
for arg in args_ok:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
try:
|
try:
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
|
@ -113,18 +113,20 @@ def test_arguments_regression():
|
||||||
# Arguments with expected SystemExit
|
# Arguments with expected SystemExit
|
||||||
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
args_exit = ["--non-exists", "--non-exists-param=42", "-h", "--help"]
|
||||||
|
|
||||||
from addons.y2038 import get_args
|
from addons.y2038 import get_args_parser
|
||||||
|
|
||||||
for arg in args_exit:
|
for arg in args_exit:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
||||||
for arg in args_ok:
|
for arg in args_ok:
|
||||||
sys.argv.append(arg)
|
sys.argv.append(arg)
|
||||||
try:
|
try:
|
||||||
get_args()
|
parser = get_args_parser()
|
||||||
|
parser.parse_args()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
pytest.fail("Unexpected SystemExit with '%s'" % arg)
|
||||||
sys.argv.remove(arg)
|
sys.argv.remove(arg)
|
||||||
|
|
|
@ -226,13 +226,14 @@ def check_y2038_safe(dumpfile, quiet=False):
|
||||||
return y2038safe
|
return y2038safe
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args_parser():
|
||||||
parser = cppcheckdata.ArgumentParser()
|
parser = cppcheckdata.ArgumentParser()
|
||||||
return parser.parse_args()
|
return parser
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = get_args()
|
parser = get_args_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
quiet = not any((args.quiet, args.cli))
|
quiet = not any((args.quiet, args.cli))
|
||||||
|
|
Loading…
Reference in New Issue