mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[widget] Add a test for types of values we handle in style's size
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
|
from contextlib import nullcontext as does_not_raise
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from textual.css.errors import StyleValueError
|
from textual.css.errors import StyleValueError
|
||||||
|
from textual.css.scalar import Scalar, Unit
|
||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"set_val, get_val, style_str", [
|
"set_val, get_val, style_str",
|
||||||
|
[
|
||||||
[True, True, "visible"],
|
[True, True, "visible"],
|
||||||
[False, False, "hidden"],
|
[False, False, "hidden"],
|
||||||
["hidden", False, "hidden"],
|
["hidden", False, "hidden"],
|
||||||
["visible", True, "visible"],
|
["visible", True, "visible"],
|
||||||
])
|
],
|
||||||
|
)
|
||||||
def test_widget_set_visible_true(set_val, get_val, style_str):
|
def test_widget_set_visible_true(set_val, get_val, style_str):
|
||||||
widget = Widget()
|
widget = Widget()
|
||||||
widget.visible = set_val
|
widget.visible = set_val
|
||||||
@@ -26,3 +32,29 @@ def test_widget_set_visible_invalid_string():
|
|||||||
widget.visible = "nope! no widget for me!"
|
widget.visible = "nope! no widget for me!"
|
||||||
|
|
||||||
assert widget.visible
|
assert widget.visible
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"size_input, expectation",
|
||||||
|
[
|
||||||
|
(None, does_not_raise()),
|
||||||
|
(10, does_not_raise()),
|
||||||
|
(10.0, does_not_raise()),
|
||||||
|
(10.2, does_not_raise()),
|
||||||
|
(Scalar(100, Unit.CELLS, Unit.WIDTH), does_not_raise()),
|
||||||
|
(Scalar(10.2, Unit.CELLS, Unit.WIDTH), does_not_raise()),
|
||||||
|
("10", does_not_raise()),
|
||||||
|
# And now for some common types we don't handle...
|
||||||
|
("a", pytest.raises(StyleValueError)),
|
||||||
|
(list(), pytest.raises(StyleValueError)),
|
||||||
|
(tuple(), pytest.raises(StyleValueError)),
|
||||||
|
(dict(), pytest.raises(StyleValueError)),
|
||||||
|
(3.14j, pytest.raises(StyleValueError)),
|
||||||
|
(Decimal("3.14"), pytest.raises(StyleValueError)),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_widget_style_size_can_accept_various_data_types(size_input, expectation):
|
||||||
|
widget = Widget()
|
||||||
|
|
||||||
|
with expectation:
|
||||||
|
widget.styles.width = size_input
|
||||||
|
|||||||
Reference in New Issue
Block a user