Skip to content

Commit

Permalink
Merge branch 'master' into dask-ok
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaze committed Oct 15, 2024
2 parents 07922b2 + ff63703 commit 49fd61e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
69 changes: 69 additions & 0 deletions argopy/tests/test_utils_decorators.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions argopy/tests/test_utils_monitors.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions argopy/utils/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 49fd61e

Please sign in to comment.