Skip to content

Commit

Permalink
using Label instead of Widget in unittests to confirm widgets are lai…
Browse files Browse the repository at this point in the history
…d in desired order
  • Loading branch information
gottadiveintopython committed Apr 15, 2024
1 parent 14525bb commit 86c2b79
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions kivy/tests/test_uix_boxlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ def gen_size(cls, *, ori):

@classmethod
def compute_layout(cls, *, ori, n_children):
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
box = BoxLayout(orientation=ori, pos=(0, 0, ), size=(400, 400, ))
for __, size in zip(range(n_children), cls.gen_size(ori=ori)):
for i, size in zip(range(n_children), cls.gen_size(ori=ori)):
# Set the position of the children to a value other than the
# default (0, 0) to ensure that the result is not affected by the
# default position.
box.add_widget(Widget(
size_hint=(None, None), size=size, pos=(8, 8)))
box.add_widget(Label(
text=str(i), size_hint=(None, None), size=size, pos=(8, 8)))
box.do_layout()
return [tuple(c.pos) for c in reversed(box.children)]
return {int(c.text): tuple(c.pos) for c in box.children}

# |
# |---|
Expand All @@ -161,23 +161,23 @@ def compute_layout(cls, *, ori, n_children):
def test_1x1(self):
from kivy.uix.boxlayout import BoxLayout
for ori in BoxLayout.orientation.options:
assert [(0, 0), ] == self.compute_layout(n_children=1, ori=ori)
assert {0: (0, 0), } == self.compute_layout(n_children=1, ori=ori)

# |
# |---|-----|-------|
# | 0 | 1 | 2 |
# |---|-----|-------|---
@pytest.mark.parametrize('ori', ['horizontal', 'lr', ])
def test_3x1_lr(self, ori):
assert [(0, 0), (100, 0), (300, 0), ] == \
assert {0: (0, 0), 1: (100, 0), 2: (300, 0), } == \
self.compute_layout(n_children=3, ori=ori)

# |
# |-------|-----|---|
# | 2 | 1 | 0 |
# |-------|-----|---|---
def test_3x1_rl(self):
assert [(500, 0), (300, 0), (0, 0), ] == \
assert {2: (0, 0), 1: (300, 0), 0: (500, 0), } == \
self.compute_layout(n_children=3, ori='rl')

# |
Expand All @@ -193,7 +193,7 @@ def test_3x1_rl(self):
# |---|---
@pytest.mark.parametrize('ori', ['vertical', 'tb', ])
def test_1x3_tb(self, ori):
assert [(0, 500), (0, 300), (0, 0), ] == \
assert {2: (0, 0), 1: (0, 300), 0: (0, 500), } == \
self.compute_layout(n_children=3, ori=ori)

# |
Expand All @@ -208,5 +208,5 @@ def test_1x3_tb(self, ori):
# | 0 |
# |---|---
def test_1x3_bt(self):
assert [(0, 0), (0, 100), (0, 300), ] == \
assert {0: (0, 0), 1: (0, 100), 2: (0, 300), } == \
self.compute_layout(n_children=3, ori='bt')

0 comments on commit 86c2b79

Please sign in to comment.