From c2b5b751029e51a3055bda92912921715e94e1e4 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Thu, 21 Dec 2023 12:07:01 +0100 Subject: [PATCH] Fix incorrect subparser, missing exception guards --- qgispluginci/cli.py | 10 +++++----- qgispluginci/parameters.py | 6 +++++- test/test_release.py | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/qgispluginci/cli.py b/qgispluginci/cli.py index c115239f..26c0b423 100755 --- a/qgispluginci/cli.py +++ b/qgispluginci/cli.py @@ -71,6 +71,11 @@ def cli(): action="append", help="An additional asset path to add. Can be specified multiple times.", ) + package_parser.add_argument( + "--no-validation", + action="store_true", + help="Turn off validation of `release version`", + ) # changelog changelog_parser = subparsers.add_parser( @@ -88,11 +93,6 @@ def cli(): release_parser.add_argument( "release_version", help="The version to be released (x.y.z)." ) - release_parser.add_argument( - "--no-validation", - action="store_true", - help="Turn off validation of `release version`", - ) release_parser.add_argument( "--release-tag", help="The release tag, if different from the version (e.g. vx.y.z).", diff --git a/qgispluginci/parameters.py b/qgispluginci/parameters.py index a1b2c9e4..0ac68abf 100644 --- a/qgispluginci/parameters.py +++ b/qgispluginci/parameters.py @@ -146,7 +146,11 @@ def explore_config() -> Dict[str, Any]: if path_to_file.is_file(): try: return load_config(path_to_file, path_to_file.name) - except ConfigurationNotFound: + except ( + ConfigurationNotFound, + configparser.NoSectionError, + KeyError, + ): pass raise configuration_not_found diff --git a/test/test_release.py b/test/test_release.py index 805ba8d8..d9a2cb77 100644 --- a/test/test_release.py +++ b/test/test_release.py @@ -233,16 +233,24 @@ def test_release_version_valid_invalid(self): def test_release_version_validation_on(self): parser = argparse.ArgumentParser() - parser.add_argument("release_version") - parser.add_argument("--no-validation", action="store_true") + subparsers = parser.add_subparsers( + title="commands", description="qgis-plugin-ci command", dest="command" + ) + sub_parser = subparsers.add_parser("package") + sub_parser.add_argument("release_version") + sub_parser.add_argument("--no-validation", action="store_true") args = parser.parse_args(["v1"]) with self.assertRaises(ValueError): Parameters.validate_args(args) def test_release_version_validation_off(self): parser = argparse.ArgumentParser() - parser.add_argument("release_version") - parser.add_argument("--no-validation", action="store_true") + subparsers = parser.add_subparsers( + title="commands", description="qgis-plugin-ci command", dest="command" + ) + sub_parser = subparsers.add_parser("package") + sub_parser.add_argument("release_version") + sub_parser.add_argument("--no-validation", action="store_true") args = parser.parse_args([".", "--no-validation"]) Parameters.validate_args(args)