Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed Jan 31, 2023
1 parent 7bd425a commit cacd8fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
format_ner_list,
get_local_ip_address,
ipython_check,
kaggle_check,
launch_analytics,
readme_to_html,
sanitize_list_for_csv,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cacd8fb

Please sign in to comment.