Files
lintunes/tests/test_round117.py
T

53 lines
2.3 KiB
Python

"""Round 117: automatic buttons ending the second row line up, column by
column, under the buttons ending the first."""
from lintunes.gui import toolbar
from tests.test_round101 import _bar
def _rows(top, bottom):
return [[e if isinstance(e, dict) else {"id": e, "size": "auto"} for e in top],
[e if isinstance(e, dict) else {"id": e, "size": "auto"} for e in bottom]]
def test_the_default_pairs_are_unchanged():
assert toolbar.column_partners(toolbar.default_config()) == {
"seek": "now_playing", "bpm": "dj"}
def test_trailing_buttons_pair_right_to_left():
rows = _rows(["transport", "now_playing", "theme", "dj"],
["library", "view", "seek", "speakers", "bpm"])
assert toolbar.column_partners(rows) == {
"seek": "now_playing", "speakers": "theme", "bpm": "dj"}
def test_exact_widths_and_spacers_end_the_run():
rows = _rows(["now_playing", "theme", "dj"],
["library", "view", "seek",
{"id": "speakers", "size": "exact", "width": 60}, "bpm"])
assert toolbar.column_partners(rows) == {"seek": "now_playing", "bpm": "dj"}
rows = _rows(["now_playing", "theme", "space:1", "dj"],
["library", "view", "seek", "speakers", "bpm"])
assert toolbar.column_partners(rows) == {"seek": "now_playing", "bpm": "dj"}
def test_pairs_never_cross():
# positionally speakers would sit under dj and bpm under theme; bpm's
# own partner (dj) wins and speakers, which would cross it, stays free
rows = _rows(["now_playing", "theme", "dj"],
["library", "view", "seek", "bpm", "speakers"])
partners = toolbar.column_partners(rows)
assert partners["seek"] == "now_playing"
assert list(partners.values()) == sorted(
partners.values(), key=["now_playing", "theme", "dj"].index)
def test_the_window_lines_them_up(qapp, tmp_path):
rows = _rows(["transport", "volume", "now_playing", "theme", "dj"],
["library", "view", "seek", "speakers", "bpm"])
bar, _prefs = _bar(tmp_path, rows)
top, bottom = bar._rects[0], bar._rects[1]
for low, high in (("speakers", "theme"), ("bpm", "dj"), ("seek", "now_playing")):
assert bottom[low].left() == top[high].left(), low
assert bottom[low].right() == top[high].right(), low