Skip to content

Commit a2b9db2

Browse files
committed
More tests and a fringe case.
1 parent 3d81f0f commit a2b9db2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/napari_matplotlib/tests/test_util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,17 @@ def test_get_size_from_css(mocker):
2929
"""
3030
mocker.patch("napari.qt.get_current_stylesheet").return_value = test_css
3131
assert from_css_get_size_of("Flibble", (1, 1)) == QSize(123, 456)
32+
33+
34+
def test_fallback_if_missing_dimensions(mocker):
35+
"""Test fallback if given something that doesn't have dimensions"""
36+
test_css = " Flobble { background-color: rgb(0, 97, 163); } "
37+
mocker.patch("napari.qt.get_current_stylesheet").return_value = test_css
38+
assert from_css_get_size_of("Flobble", (1, 1)) == QSize(1, 1)
39+
40+
41+
def test_fallback_if_prelude_not_in_css():
42+
"""Test fallback if given something not in the css"""
43+
assert from_css_get_size_of("AQButtonThatDoesntExist", (1, 1)) == QSize(
44+
1, 1
45+
)

src/napari_matplotlib/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ def from_css_get_size_of(
9393
if _has_id(rule.prelude, qt_element_name):
9494
w = _get_dimension(rule.content, "max-width")
9595
h = _get_dimension(rule.content, "max-height")
96-
return QSize(w, h)
96+
if w and h:
97+
return QSize(w, h)
9798
return QSize(*fallback)

0 commit comments

Comments
 (0)