diff --git a/argopy/tests/test_utils_decorators.py b/argopy/tests/test_utils_decorators.py new file mode 100644 index 00000000..ecba7c73 --- /dev/null +++ b/argopy/tests/test_utils_decorators.py @@ -0,0 +1,69 @@ +import pytest +import warnings + +from argopy.utils.decorators import DocInherit, deprecated + + +def test_DocInherit(): + + class Profile(object): + def load(self): + """Dummy""" + pass + + class Float(Profile): + @DocInherit + def load(self): + pass + + assert Float.load.__doc__ == Profile.load.__doc__ + + +def test_deprecated_no_reason(): + + @deprecated + def dummy_fct(): + """Dummy""" + pass + + with pytest.deprecated_call(): + dummy_fct() + + +def test_deprecated_with_a_reason(): + + @deprecated("Because !") + def dummy_fct(): + """Dummy""" + pass + + with pytest.deprecated_call(match="Because"): + dummy_fct() + + + +def test_deprecated_with_a_reason_and_version(): + + @deprecated("Because !", version='12.0') + def dummy_fct(): + """Dummy""" + pass + + with pytest.deprecated_call(match="Deprecated since version"): + dummy_fct() + + +def test_deprecated_ignore_caller(): + + @deprecated("Because !", ignore_caller='caller_to_be_ignored') + def dummy_fct(): + """Dummy""" + pass + + def caller_to_be_ignored(): + dummy_fct() + pass + + with warnings.catch_warnings(): + # warnings.simplefilter("error") + caller_to_be_ignored() diff --git a/argopy/tests/test_utils_monitors.py b/argopy/tests/test_utils_monitors.py new file mode 100644 index 00000000..2b7b12f3 --- /dev/null +++ b/argopy/tests/test_utils_monitors.py @@ -0,0 +1,29 @@ +import pytest +IPython = pytest.importorskip("IPython", reason="Requires 'IPython'") + +from argopy.utils.monitors import badge, fetch_status, monitor_status +from utils import has_ipywidgets, requires_ipywidgets + + +@pytest.mark.parametrize("insert", [False, True], indirect=False, ids=["insert=%s" % str(i) for i in [False, True]]) +def test_badge(insert): + b = badge(label="label", message="message", color="green", insert=insert) + if not insert: + assert isinstance(b, str) + else: + assert isinstance(b, IPython.core.display.Image) + + +def test_fetch_status(): + fs = fetch_status() + results = fs.fetch() + assert isinstance(results, dict) + assert isinstance(fs.text, str) + assert isinstance(fs.html, str) + + +@requires_ipywidgets +def test_monitor_status(): + ms = monitor_status() + assert ms.runner in ['notebook', 'terminal', 'standard', False] + assert isinstance(ms.content, str) diff --git a/argopy/utils/monitors.py b/argopy/utils/monitors.py index 43b9b586..a78228ed 100644 --- a/argopy/utils/monitors.py +++ b/argopy/utils/monitors.py @@ -51,10 +51,10 @@ def badge(label="label", message="message", color="green", insert=False): class fetch_status: """Fetch and report web API status""" - def __init__(self, **kwargs): - if "stdout" in kwargs or "insert" in kwargs: - warnings.warn("'fetch_status' signature has changed") - pass + # def __init__(self, **kwargs): + # if "stdout" in kwargs or "insert" in kwargs: + # warnings.warn("'fetch_status' signature has changed") + # pass def fetch(self): results = {}