addons: Fix arguments parser when running pytest (#3327)

This commit is contained in:
Georgiy Komarov 2021-07-06 23:13:04 +03:00 committed by GitHub
parent 6f389014f1
commit 81eabb5f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 20 deletions

View File

@ -379,13 +379,14 @@ def api01(data):
token = token.next
def get_args():
def get_args_parser():
parser = cppcheckdata.ArgumentParser()
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
return parser.parse_args()
return parser
if __name__ == '__main__':
args = get_args()
parser = get_args_parser()
args = parser.parse_args()
if args.verify:
VERIFY = True

View File

@ -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."""
parser = cppcheckdata.ArgumentParser()
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("-verify", help=argparse.SUPPRESS, action="store_true")
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():
args = get_args()
parser = get_args_parser()
args = parser.parse_args()
settings = MisraSettings(args)
checker = MisraChecker(settings)

View File

@ -18,18 +18,20 @@ def test_arguments_regression():
# Arguments with expected SystemExit
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:
sys.argv.append(arg)
with pytest.raises(SystemExit):
get_args()
parser = get_args_parser()
parser.parse_args()
sys.argv.remove(arg)
for arg in args_ok:
sys.argv.append(arg)
try:
get_args()
parser = get_args_parser()
parser.parse_args()
except SystemExit:
pytest.fail("Unexpected SystemExit with '%s'" % arg)
sys.argv.remove(arg)

View File

@ -29,8 +29,9 @@ def teardown_module(module):
@pytest.fixture(scope="function")
def checker():
from addons.misra import MisraChecker, MisraSettings, get_args
args = get_args()
from addons.misra import MisraChecker, MisraSettings, get_args_parser
parser = get_args_parser()
args = parser.parse_args([])
settings = MisraSettings(args)
return MisraChecker(settings)
@ -135,18 +136,20 @@ def test_arguments_regression():
# Arguments with expected SystemExit
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:
sys.argv.append(arg)
with pytest.raises(SystemExit):
get_args()
parser = get_args_parser()
parser.parse_args()
sys.argv.remove(arg)
for arg in args_ok:
sys.argv.append(arg)
try:
get_args()
parser = get_args_parser()
parser.parse_args()
except SystemExit:
pytest.fail("Unexpected SystemExit with '%s'" % arg)
sys.argv.remove(arg)

View File

@ -113,18 +113,20 @@ def test_arguments_regression():
# Arguments with expected SystemExit
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:
sys.argv.append(arg)
with pytest.raises(SystemExit):
get_args()
parser = get_args_parser()
parser.parse_args()
sys.argv.remove(arg)
for arg in args_ok:
sys.argv.append(arg)
try:
get_args()
parser = get_args_parser()
parser.parse_args()
except SystemExit:
pytest.fail("Unexpected SystemExit with '%s'" % arg)
sys.argv.remove(arg)

View File

@ -226,13 +226,14 @@ def check_y2038_safe(dumpfile, quiet=False):
return y2038safe
def get_args():
def get_args_parser():
parser = cppcheckdata.ArgumentParser()
return parser.parse_args()
return parser
if __name__ == '__main__':
args = get_args()
parser = get_args_parser()
args = parser.parse_args()
exit_code = 0
quiet = not any((args.quiet, args.cli))