forked from matplotlib/napari-matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
54 lines (43 loc) · 1.75 KB
/
test_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from qtpy.QtCore import QSize
from napari_matplotlib.util import Interval, from_napari_css_get_size_of
def test_interval():
interval = Interval(4, 9)
for i in range(4, 10):
assert i in interval
assert 3 not in interval
assert 10 not in interval
with pytest.raises(ValueError, match="must be an integer"):
"string" in interval # type: ignore
def test_get_size_from_css(mocker):
"""Test getting the max-width and max-height from something in css"""
# some weird (but valid) css to check we can skip things correctly
test_css = """
Flibble {
padding: 0 0 1px 2px;
color: rgb(3, 4, 555);
min-width : 0;
max-width : 123px;
min-height : 0%;
max-height : 456px;
}
"""
mocker.patch("napari.qt.get_current_stylesheet").return_value = test_css
assert from_napari_css_get_size_of("Flibble", fallback=(1, 2)) == QSize(
123, 456
)
def test_fallback_if_missing_dimensions(mocker):
"""Test fallback if given something that doesn't have dimensions"""
test_css = " Flobble { background-color: rgb(0, 97, 163); } "
mocker.patch("napari.qt.get_current_stylesheet").return_value = test_css
with pytest.warns(RuntimeWarning, match="Unable to find DimensionToken"):
assert from_napari_css_get_size_of(
"Flobble", fallback=(1, 2)
) == QSize(1, 2)
def test_fallback_if_prelude_not_in_css():
"""Test fallback if given something not in the css"""
doesntexist = "AQButtonThatDoesntExist"
with pytest.warns(RuntimeWarning, match=f"Unable to find {doesntexist}"):
assert from_napari_css_get_size_of(
doesntexist, fallback=(1, 2)
) == QSize(1, 2)