Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test Coverage for IPython #1256

Merged
merged 20 commits into from Oct 6, 2020
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Expand Up @@ -12,6 +12,7 @@ Release Notes
* Added DecisionTree estimators to API Reference :pr:`1246`
* Changed class inheritance display to flow vertically :pr:`1248`
* Testing Changes
* Added tests for ``jupyter_check`` to handle IPython :pr:``


**v0.14.1 Sep. 29, 2020**
Expand Down
30 changes: 28 additions & 2 deletions evalml/tests/utils_tests/test_gen_utils.py
@@ -1,5 +1,5 @@
import inspect
from unittest.mock import patch
from unittest.mock import patch, MagicMock

import numpy as np
import pytest
Expand All @@ -13,7 +13,8 @@
get_importable_subclasses,
get_random_seed,
get_random_state,
import_or_raise
import_or_raise,
jupyter_check
)


Expand Down Expand Up @@ -214,3 +215,28 @@ def test_check_random_state_equality():
rs_1.set_state(tuple(['MT19937', np.array([1] * 624), 0, 1, 0.1]))
rs_2.set_state(tuple(['MT19937', np.array([1] * 624), 1, 1, 0.1]))
assert not check_random_state_equality(rs_1, rs_2)


@patch('evalml.utils.gen_utils.import_or_raise')
def test_jupyter_check_errors(mock_import_or_raise):
mock_import_or_raise.side_effect = ImportError
assert not jupyter_check()

mock_import_or_raise.side_effect = Exception
assert not jupyter_check()


@patch('evalml.utils.gen_utils.import_or_raise')
@patch('IPython.core.getipython.get_ipython')
bchen1116 marked this conversation as resolved.
Show resolved Hide resolved
def test_jupyter_check(mock_ipython, mock_import_or_raise):
mock_import_or_raise.return_value = MagicMock()
mock_ipython.return_value = True
mock_import_or_raise.core.getipython.get_ipython().return_value = True
bchen1116 marked this conversation as resolved.
Show resolved Hide resolved
assert jupyter_check()

mock_ipython.return_value = False
mock_import_or_raise.core.getipython.get_ipython().return_value = False
assert not jupyter_check()
mock_import_or_raise.core.getipython.get_ipython().return_value = None
mock_ipython.return_value = None
assert not jupyter_check()
10 changes: 7 additions & 3 deletions evalml/utils/gen_utils.py
Expand Up @@ -233,9 +233,13 @@ def jupyter_check():
Boolean: True if Ipython, False otherwise
"""
try:
get_ipython()
return True
except NameError:
ipy = import_or_raise("IPython")
if (ipy.core.getipython.get_ipython()):
bchen1116 marked this conversation as resolved.
Show resolved Hide resolved
return True
return False
except ImportError:
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for except ImportError if you already have except Exception

except Exception:
return False


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,6 +1,7 @@
-r core-requirements.txt
plotly>=4.2.1
ipywidgets>=7.5
ipython>=7.17.0
xgboost>=0.82
catboost>=0.20
lightgbm>=2.3.1