From cbd4637ca18a27b2e04f485e0530d0f54e00cb84 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 19 Jan 2023 11:44:31 +0800 Subject: [PATCH 1/2] pygmt.config: Correctly resettig to default values that contain whitespaces --- pygmt/src/config.py | 2 +- pygmt/tests/test_config.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/src/config.py b/pygmt/src/config.py index 0fcf181891c..0bedf9fe091 100644 --- a/pygmt/src/config.py +++ b/pygmt/src/config.py @@ -207,7 +207,7 @@ def __enter__(self): def __exit__(self, exc_type, exc_value, traceback): # revert to initial values arg_str = " ".join( - [f"{key}={value}" for key, value in self.old_defaults.items()] + [f'{key}="{value}"' for key, value in self.old_defaults.items()] ) with Session() as lib: lib.call_module(module="set", args=arg_str) diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py index a1e591e8220..5b307fb8c50 100644 --- a/pygmt/tests/test_config.py +++ b/pygmt/tests/test_config.py @@ -72,8 +72,13 @@ def test_config_format_date_map(): Note the space in 'o dd', this acts as a regression test for https://github.com/GenericMappingTools/pygmt/issues/247. + + Setting FORMAT_DATE_MAP="yyyy mm dd" as a regression test for + https://github.com/GenericMappingTools/pygmt/issues/2298. """ fig = Figure() + # Set the FORMAT_DATE_MAP to "yyyy mm dd" that contains whitespaces. + config(FORMAT_DATE_MAP="yyyy mm dd") with config(FORMAT_DATE_MAP="o dd"): fig.basemap( region=["1969-7-21T", "1969-7-23T", 0, 1], From b10503b3ca4ebe5891eb4a84c598ab4e20ee954d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 19 Jan 2023 17:25:03 +0800 Subject: [PATCH 2/2] Update pygmt/tests/test_config.py --- pygmt/tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py index 5b307fb8c50..fbaddd323e4 100644 --- a/pygmt/tests/test_config.py +++ b/pygmt/tests/test_config.py @@ -77,7 +77,7 @@ def test_config_format_date_map(): https://github.com/GenericMappingTools/pygmt/issues/2298. """ fig = Figure() - # Set the FORMAT_DATE_MAP to "yyyy mm dd" that contains whitespaces. + # Set FORMAT_DATE_MAP to "yyyy mm dd" which contains whitespaces. config(FORMAT_DATE_MAP="yyyy mm dd") with config(FORMAT_DATE_MAP="o dd"): fig.basemap(