Skip to content

Commit

Permalink
add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aerickson committed Dec 4, 2024
1 parent 5e92dc2 commit 206fb31
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions core/tests/widgets/test_container_debug_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
import toga


# test that a container-like widget in normal mode has a default background
def test_box_no_background_in_normal_mode():
"""A Box has no default background."""
# Disable layout debug mode
with MonkeyPatch.context() as mp:
mp.setenv("TOGA_DEBUG_LAYOUT", "0")
box = toga.Box()
# assert that the bg is default
assert hasattr(box.style, "background_color")
assert not box.style.background_color


# test that a non-container-like widget in layout debug mode has a default background
def test_button_debug_background():
"""A Button in layout debug mode has a default background."""
Expand All @@ -16,8 +28,21 @@ def test_button_debug_background():
assert not button.style.background_color


# test that a label in layout debug mode has a default background
def test_label_no_debug_background():
"""A Label in layout debug mode has a default background."""
# Enable layout debug mode
with MonkeyPatch.context() as mp:
mp.setenv("TOGA_DEBUG_LAYOUT", "1")
label = toga.Label("label")
# assert that the bg is default
assert hasattr(label.style, "background_color")
assert not label.style.background_color


# test that a container-like widget in layout debug mode has a non-default background
def test_box_debug_background():
# that matches the expected debug_background_palette
def test_box_debug_backgrounds():
"""A Box in layout debug mode has a non-default background."""
# Enable layout debug mode
with MonkeyPatch.context() as mp:
Expand All @@ -38,13 +63,14 @@ def test_box_debug_background():
)


# test that a container-like widget in normal mode has a default background
def test_box_normal_background():
"""A Box has no default background."""
# test that a scroll container widget in layout debug mode doesn't have
# a default background
def test_scroll_container_debug_background():
"""A container widget has a default background."""
# Disable layout debug mode
with MonkeyPatch.context() as mp:
mp.setenv("TOGA_DEBUG_LAYOUT", "0")
box = toga.Box()
# assert that the bg is default
assert hasattr(box.style, "background_color")
assert not box.style.background_color
mp.setenv("TOGA_DEBUG_LAYOUT", "1")
sc = toga.ScrollContainer()
# assert that the bg is not default
assert hasattr(sc.style, "background_color")
assert sc.style.background_color != color("white")

0 comments on commit 206fb31

Please sign in to comment.