From 88e5de4963b56aae1ab96ba57694fcd753f9f95c Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Fri, 16 Jun 2023 15:31:50 +0200 Subject: [PATCH] Properly dump `json_formatter` with `--show-config` option --- reframe/core/config.py | 3 ++- reframe/frontend/cli.py | 2 +- reframe/utility/jsonext.py | 3 +++ unittests/test_utility.py | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/reframe/core/config.py b/reframe/core/config.py index 9163808b83..3f5881ec9b 100644 --- a/reframe/core/config.py +++ b/reframe/core/config.py @@ -17,6 +17,7 @@ import reframe import reframe.core.settings as settings import reframe.utility as util +import reframe.utility.jsonext as jsonext from reframe.core.environments import normalize_module_list from reframe.core.exceptions import ConfigError, ReframeFatalError from reframe.core.logging import getlogger @@ -225,7 +226,7 @@ def __repr__(self): f'sources={self._sources!r})') def __str__(self): - return json.dumps(self._pick_config(), indent=2) + return jsonext.dumps(self._pick_config(), indent=2) # Delegate everything to either the original config or to the reduced one # if a system is selected diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 1bb2dc8017..ae135b1405 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -831,7 +831,7 @@ def restrict_logging(): f'no such configuration parameter found: {config_param}' ) else: - printer.info(json.dumps(value, indent=2)) + printer.info(jsonext.dumps(value, indent=2)) sys.exit(0) diff --git a/reframe/utility/jsonext.py b/reframe/utility/jsonext.py index ec04e84ca5..7c6cc575c9 100644 --- a/reframe/utility/jsonext.py +++ b/reframe/utility/jsonext.py @@ -66,6 +66,9 @@ def encode(obj, **kwargs): if inspect.istraceback(obj): return traceback.format_tb(obj) + if inspect.isfunction(obj): + return f'py::{obj.__qualname__}' + newobj = encode_dict(obj) if newobj is not None: return newobj diff --git a/unittests/test_utility.py b/unittests/test_utility.py index 8665a5c861..b89236cea8 100644 --- a/unittests/test_utility.py +++ b/unittests/test_utility.py @@ -1585,6 +1585,12 @@ def test_jsonext_dumps(): ) assert '{"(1, 2, 3)": 1}' == jsonext.dumps({(1, 2, 3): 1}) + def foo(): + pass + + assert ('{"fn": "py::test_jsonext_dumps..foo"}' == + jsonext.dumps({'fn': foo})) + # Classes to test JSON deserialization