From d2824ca074478ea7c66f618b4bd13a58b081649a Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Mon, 9 Oct 2023 11:58:16 -0500 Subject: [PATCH 1/3] mv fn none check to main function, add test --- yt/loaders.py | 17 +++++++++-------- yt/tests/test_load_sample.py | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/yt/loaders.py b/yt/loaders.py index 0e9ff8f2c73..2876db51113 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -1487,14 +1487,6 @@ def _get_sample_data( # broadcast to other processes during parallel execution). import tarfile - if fn is None: - print( - "One can see which sample datasets are available at: https://yt-project.org/data\n" - "or alternatively by running: yt.sample_data.api.get_data_registry_table()", - file=sys.stderr, - ) - return None - from yt.sample_data.api import ( _download_sample_data_file, _get_test_data_dir_path, @@ -1663,6 +1655,15 @@ def load_sample( - Corresponding sample data live at https://yt-project.org/data """ + + if fn is None: + print( + "One can see which sample datasets are available at: https://yt-project.org/data\n" + "or alternatively by running: yt.sample_data.api.get_data_registry_table()", + file=sys.stderr, + ) + return None + loadable_path, load_kwargs = _get_sample_data( fn, progressbar=progressbar, timeout=timeout, **kwargs ) diff --git a/yt/tests/test_load_sample.py b/yt/tests/test_load_sample.py index 18f6b743732..9d4880caa59 100644 --- a/yt/tests/test_load_sample.py +++ b/yt/tests/test_load_sample.py @@ -196,3 +196,7 @@ def test_data_dir_broken(): ) with pytest.warns(UserWarning, match=msg): load_sample("ToroShockTube") + + +def test_filename_none(): + assert load_sample(None) is None From b018e64e2e980f33854cca663691d0ed87380f13 Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Mon, 9 Oct 2023 11:59:30 -0500 Subject: [PATCH 2/3] adjust test --- yt/tests/test_load_sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/tests/test_load_sample.py b/yt/tests/test_load_sample.py index 9d4880caa59..31d7d1a511e 100644 --- a/yt/tests/test_load_sample.py +++ b/yt/tests/test_load_sample.py @@ -199,4 +199,4 @@ def test_data_dir_broken(): def test_filename_none(): - assert load_sample(None) is None + assert load_sample() is None From 7fe4c2da9e63c2c0d67d8de795c15b7e7c200488 Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Mon, 9 Oct 2023 12:05:29 -0500 Subject: [PATCH 3/3] check sys.stderr in new test --- yt/tests/test_load_sample.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yt/tests/test_load_sample.py b/yt/tests/test_load_sample.py index 31d7d1a511e..c5b5189bc46 100644 --- a/yt/tests/test_load_sample.py +++ b/yt/tests/test_load_sample.py @@ -198,5 +198,7 @@ def test_data_dir_broken(): load_sample("ToroShockTube") -def test_filename_none(): +def test_filename_none(capsys): assert load_sample() is None + captured = capsys.readouterr() + assert "yt.sample_data.api.get_data_registry_table" in captured.err