From df39548777ae7b62b4af55147bcfaf72fcf4d9a5 Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 21 Dec 2023 15:23:19 +0100 Subject: [PATCH] Fix incorrect subparser, missing exception guards (release 2.8.2) (#262) * Fix incorrect subparser, missing exception guards * argument name --- qgispluginci/cli.py | 10 +++++----- qgispluginci/parameters.py | 6 +++++- test/test_release.py | 20 ++++++++++++++------ 3 files changed, 24 insertions(+), 12 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..acdb0705 100644 --- a/test/test_release.py +++ b/test/test_release.py @@ -233,17 +233,25 @@ 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") - args = parser.parse_args(["v1"]) + 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(["package", "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") - args = parser.parse_args([".", "--no-validation"]) + 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(["package", "v1", "--no-validation"]) Parameters.validate_args(args)