From cacd8fbbe88ffbfe02a9511474a7a3f1fef54500 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Tue, 31 Jan 2023 11:42:48 -0500 Subject: [PATCH] Add test --- gradio/utils.py | 4 +++- test/test_utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gradio/utils.py b/gradio/utils.py index 76c1a65fe0e97..9ac48152e9946 100644 --- a/gradio/utils.py +++ b/gradio/utils.py @@ -190,7 +190,9 @@ def colab_check() -> bool: def kaggle_check() -> bool: - return bool(os.environ.get('KAGGLE_KERNEL_RUN_TYPE') or os.environ.get('GFOOTBALL_DATA_DIR')) + return bool( + os.environ.get("KAGGLE_KERNEL_RUN_TYPE") or os.environ.get("GFOOTBALL_DATA_DIR") + ) def ipython_check() -> bool: diff --git a/test/test_utils.py b/test/test_utils.py index 9b4de02672ee0..cdbe453a5ca6d 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -29,6 +29,7 @@ format_ner_list, get_local_ip_address, ipython_check, + kaggle_check, launch_analytics, readme_to_html, sanitize_list_for_csv, @@ -103,6 +104,31 @@ def test_readme_to_html_doesnt_crash_on_connection_error(self, mock_get): def test_readme_to_html_correct_parse(self): readme_to_html("https://github.com/gradio-app/gradio/blob/master/README.md") + def test_kaggle_check_false(self): + assert not kaggle_check() + + def test_kaggle_check_true_when_run_type_set(self): + with mock.patch.dict( + os.environ, {"KAGGLE_KERNEL_RUN_TYPE": "Interactive"}, clear=True + ): + assert kaggle_check() + + def test_kaggle_check_true_when_both_set(self): + with mock.patch.dict( + os.environ, + {"KAGGLE_KERNEL_RUN_TYPE": "Interactive", "GFOOTBALL_DATA_DIR": "./"}, + clear=True, + ): + assert kaggle_check() + + def test_kaggle_check_false_when_neither_set(self): + with mock.patch.dict( + os.environ, + {"KAGGLE_KERNEL_RUN_TYPE": "", "GFOOTBALL_DATA_DIR": ""}, + clear=True, + ): + assert not kaggle_check() + class TestIPAddress: @pytest.mark.flaky