@@ -205,24 +205,57 @@ def test_config_show(
205205 cfg_default : Config ,
206206) -> None :
207207 """Test esmvaltool config show command."""
208- with arguments ("esmvaltool" , "config" , "show" , "--filter=None " ):
208+ with arguments ("esmvaltool" , "config" , "show" , "--filter=" ):
209209 run ()
210210 stdout = capsys .readouterr ().out
211- expected_header = "Current configuration\n "
211+ expected_header = "Current configuration: \n "
212212 assert expected_header in stdout
213213 cfg_txt = stdout .split (expected_header )[1 ]
214214 cfg = yaml .safe_load (cfg_txt )
215215 reference = yaml .safe_load (yaml .safe_dump (dict (cfg_default ))) # type: ignore[call-overload]
216216 assert cfg == reference
217217
218218
219+ def test_config_show_single_project (
220+ capsys : pytest .CaptureFixture ,
221+ cfg_default : Config ,
222+ ) -> None :
223+ """Test esmvaltool config show command for a single project."""
224+ with arguments ("esmvaltool" , "config" , "show" , "--project=CMIP7" ):
225+ run ()
226+ stdout = capsys .readouterr ().out
227+ expected_header = "Current configuration for project 'CMIP7', excluding the keys 'extra_facets':\n "
228+ assert expected_header in stdout
229+ cfg_txt = stdout .split (expected_header )[1 ]
230+ cfg = yaml .safe_load (cfg_txt )
231+ assert "projects" in cfg
232+ assert "CMIP7" in cfg ["projects" ]
233+ assert "CMIP6" not in cfg ["projects" ]
234+
235+
236+ def test_config_show_filter (
237+ capsys : pytest .CaptureFixture ,
238+ cfg_default : Config ,
239+ ) -> None :
240+ """Test esmvaltool config show command for a single project."""
241+ with arguments ("esmvaltool" , "config" , "show" , "--filter=projects" ):
242+ run ()
243+ stdout = capsys .readouterr ().out
244+ expected_header = "Current configuration, excluding the keys 'projects':\n "
245+ assert expected_header in stdout
246+ cfg_txt = stdout .split (expected_header )[1 ]
247+ cfg = yaml .safe_load (cfg_txt )
248+ assert cfg
249+ assert "projects" not in cfg
250+
251+
219252def test_config_show_brief_by_default (capsys : pytest .CaptureFixture ) -> None :
220253 """Test that the `esmvaltool config show` command produces readable results."""
221254 with arguments ("esmvaltool" , "config" , "show" ):
222255 run ()
223256 stdout = capsys .readouterr ().out
224257 expected_header = (
225- "Current configuration, excluding the keys 'extra_facets'\n "
258+ "Current configuration, excluding the keys 'extra_facets': \n "
226259 )
227260 assert expected_header in stdout
228261 # Check that the configuration that is listed by default is sufficiently
0 commit comments