diff --git a/docs/query.md b/docs/query.md index 8fda91e..dcdbcc0 100644 --- a/docs/query.md +++ b/docs/query.md @@ -1,6 +1,6 @@ Query ===== -Query support is provided through [JMESPath](http://jmespath.org). +Query support is provided through [JMESPath](http://jmespath.site/main). This allows filter and project of command output. diff --git a/docs/testing.md b/docs/testing.md index 61337fc..c52f0e0 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -71,7 +71,7 @@ class TestMyScenarios(ScenarioTest): ``` Note: -1. What is JMESPath? [JMESPath is a query language for JSON](http://jmespath.org/) +1. What is JMESPath? [JMESPath is a query language for JSON](http://jmespath.site/main/) 2. If a command is return value in JSON, multiple JMESPath based check can be added to the checks list to validate the result. 3. In addition to the `JMESPatchCheck`, there are other checks list `NoneCheck` which validate the output is `None`. The check mechanism is extensible. Any callable accept `ExecutionResult` can act as a check. diff --git a/knack/output.py b/knack/output.py index cb71eff..881a41a 100644 --- a/knack/output.py +++ b/knack/output.py @@ -67,7 +67,8 @@ def format_table(obj): if obj.table_transformer and not obj.is_query_active: if isinstance(obj.table_transformer, str): from jmespath import compile as compile_jmes, Options - result = compile_jmes(obj.table_transformer).search(result, Options(OrderedDict)) + options = Options(dict_cls=OrderedDict, enable_legacy_literals=True) + result = compile_jmes(obj.table_transformer, options).search(result, options) else: result = obj.table_transformer(result) result_list = result if isinstance(result, list) else [result] diff --git a/knack/query.py b/knack/query.py index 3515804..89bfe6b 100644 --- a/knack/query.py +++ b/knack/query.py @@ -19,9 +19,10 @@ def jmespath_type(raw_query): In addition though, JMESPath can raise a KeyError. ValueErrors are caught by argparse so argument errors can be generated. """ + from jmespath import Options from jmespath import compile as compile_jmespath try: - return compile_jmespath(raw_query) + return compile_jmespath(raw_query, Options(enable_legacy_literals=True)) except KeyError as ex: # Raise a ValueError which argparse can handle raise ValueError from ex @@ -30,7 +31,7 @@ def jmespath_type(raw_query): def on_global_arguments(_, **kwargs): arg_group = kwargs.get('arg_group') arg_group.add_argument('--query', dest='_jmespath_query', metavar='JMESPATH', - help='JMESPath query string. See http://jmespath.org/ for more' + help='JMESPath query string. See http://jmespath.site/main/ for more' ' information and examples.', type=CLIQuery.jmespath_type) @@ -43,7 +44,9 @@ def handle_query_parameter(cli_ctx, **kwargs): def filter_output(cli_ctx, **kwargs): from jmespath import Options kwargs['event_data']['result'] = query_expression.search( - kwargs['event_data']['result'], Options(collections.OrderedDict)) + kwargs['event_data']['result'], Options( + dict_cls=collections.OrderedDict, + enable_legacy_literals=True)) cli_ctx.unregister_event(EVENT_INVOKER_FILTER_RESULT, filter_output) cli_ctx.register_event(EVENT_INVOKER_FILTER_RESULT, filter_output) cli_ctx.invocation.data['query_active'] = True diff --git a/knack/testsdk/checkers.py b/knack/testsdk/checkers.py index a97e983..5edf859 100644 --- a/knack/testsdk/checkers.py +++ b/knack/testsdk/checkers.py @@ -16,7 +16,9 @@ def __init__(self, query, expected_result): def __call__(self, execution_result): json_value = execution_result.get_output_in_json() actual_result = jmespath.search(self._query, json_value, - jmespath.Options(collections.OrderedDict)) + jmespath.Options( + dict_cls=collections.OrderedDict, + enable_legacy_literals=True)) if not actual_result == self._expected_result: if actual_result: raise JMESPathCheckAssertionError(self._query, self._expected_result, actual_result, @@ -32,7 +34,9 @@ def __init__(self, query): def __call__(self, execution_result): json_value = execution_result.get_output_in_json() actual_result = jmespath.search(self._query, json_value, - jmespath.Options(collections.OrderedDict)) + jmespath.Options( + dict_cls=collections.OrderedDict, + enable_legacy_literals=True)) if not actual_result: raise JMESPathCheckAssertionError(self._query, 'some value', actual_result, execution_result.output) @@ -46,7 +50,9 @@ def __init__(self, query, expected_result): def __call__(self, execution_result): json_value = execution_result.get_output_in_json() actual_result = jmespath.search(self._query, json_value, - jmespath.Options(collections.OrderedDict)) + jmespath.Options( + dict_cls=collections.OrderedDict, + enable_legacy_literals=True)) if not actual_result > self._expected_result: expected_result_format = "> {}".format(self._expected_result) diff --git a/requirements.txt b/requirements.txt index 2a9ddfe..b1fcbf2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ argcomplete==1.12.2 flake8==4.0.1 -jmespath==0.10.0 +jmespath-community==1.1.0 Pygments==2.8.1 pylint==2.11.1 pytest==6.2.5 diff --git a/setup.py b/setup.py index 43bdece..46e1aeb 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ DEPENDENCIES = [ 'argcomplete', - 'jmespath', + 'jmespath-community', 'pygments', 'pyyaml', 'tabulate' diff --git a/tests/test_help.py b/tests/test_help.py index c115b2d..2c51fcf 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -20,6 +20,9 @@ def example_handler(arg1, arg2=None, arg3=None): class TestHelpArgumentGroupRegistry(unittest.TestCase): + + unittest.TestCase.maxDiff = None + def test_help_argument_group_registry(self): groups = [ 'Z Arguments', @@ -279,8 +282,8 @@ def test_help_full_documentations(self): --only-show-errors : Only show errors, suppressing warnings. --output -o : Output format. Allowed values: json, jsonc, none, table, tsv, yaml, yamlc. Default: json. - --query : JMESPath query string. See http://jmespath.org/ for more information and - examples. + --query : JMESPath query string. See http://jmespath.site/main/ for more + information and examples. --verbose : Increase logging verbosity. Use --debug for full debug logs. Examples @@ -314,8 +317,8 @@ def test_help_with_param_specified(self): --only-show-errors : Only show errors, suppressing warnings. --output -o : Output format. Allowed values: json, jsonc, none, table, tsv, yaml, yamlc. Default: json. - --query : JMESPath query string. See http://jmespath.org/ for more information and - examples. + --query : JMESPath query string. See http://jmespath.site/main/ for more information + and examples. --verbose : Increase logging verbosity. Use --debug for full debug logs. """ @@ -431,8 +434,8 @@ def register_globals(_, **kwargs): --only-show-errors : Only show errors, suppressing warnings. --output -o : Output format. Allowed values: json, jsonc, none, table, tsv, yaml, yamlc. Default: json. - --query : JMESPath query string. See http://jmespath.org/ for more information and - examples. + --query : JMESPath query string. See http://jmespath.site/main/ for more information + and examples. --verbose : Increase logging verbosity. Use --debug for full debug logs. """