Skip to content

Commit 28a8b9d

Browse files
committed
some tests of deprecation
1 parent 5482959 commit 28a8b9d

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

python/ipywidgets/ipywidgets/widgets/tests/test_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import inspect
23
from pathlib import Path
34
from unittest.mock import patch
45

@@ -7,6 +8,9 @@
78
from ipywidgets.widgets.utils import deprecation
89
from ipywidgets.widgets.tests.utils import call_method
910

11+
12+
CALL_PATH = inspect.getfile(call_method)
13+
1014
@patch("ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL", [])
1115
def test_deprecation_direct():
1216
with pytest.warns(DeprecationWarning) as record:
@@ -20,9 +24,9 @@ def test_deprecation_indirect():
2024
with pytest.warns(DeprecationWarning) as record:
2125
call_method(deprecation, "test message")
2226
assert len(record) == 1
23-
assert Path(record[0].filename) == Path(__file__, '..', 'utils.py').resolve()
27+
assert record[0].filename == CALL_PATH
2428

25-
@patch("ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL", [str(Path(__file__, '..', 'utils.py').resolve())])
29+
@patch("ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL", [CALL_PATH])
2630
def test_deprecation_indirect_internal():
2731
# If the line that calls "deprecation" is internal, it is not considered the source:
2832
with pytest.warns(DeprecationWarning) as record:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
from unittest.mock import patch
5+
import pytest
6+
7+
import ipywidgets as widgets
8+
9+
10+
@patch(
11+
"ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL",
12+
['widgets/widget.py', 'widgets/widget_button.py']
13+
)
14+
def test_fa_prefix_deprecation():
15+
with pytest.deprecated_call() as record:
16+
widgets.Button(icon="fa-gear")
17+
assert len(record) == 1
18+
assert record[0].filename == __file__

python/ipywidgets/ipywidgets/widgets/tests/test_widget_string.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
from ..widget_string import Combobox
4+
from ..widget_string import Combobox, Text
5+
from unittest.mock import patch
6+
import pytest
7+
8+
9+
@patch(
10+
"ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL",
11+
['widgets/widget_string.py']
12+
)
13+
def test_on_submit_deprecation():
14+
w = Text()
15+
with pytest.deprecated_call() as record:
16+
w.on_submit(lambda: None)
17+
assert len(record) == 1
18+
assert record[0].filename == __file__
19+
20+
21+
@patch(
22+
"ipywidgets.widgets.utils._IPYWIDGETS_INTERNAL",
23+
['widgets/widget_string.py', 'widgets/widget_description.py']
24+
)
25+
def test_tooltip_deprecation():
26+
with pytest.deprecated_call() as record:
27+
w = Text(description_tooltip="testing")
28+
assert len(record) == 1
29+
assert record[0].filename == __file__
30+
31+
with pytest.deprecated_call() as record:
32+
assert w.description_tooltip == "testing"
33+
assert len(record) == 1
34+
assert record[0].filename == __file__
35+
36+
with pytest.deprecated_call() as record:
37+
w.description_tooltip = "second value"
38+
assert len(record) == 1
39+
assert record[0].filename == __file__
40+
assert w.tooltip == "second value"
541

642

743
def test_combobox_creation_blank():

0 commit comments

Comments
 (0)