27 Phase 6 tests (tables: 103 kinds / 1008 props / 116 names, up-down defaults, symbol model-only, shadowed VWAP/Arrow names; headless Cairo smoke over all 103 kinds + with live props; ParallelChannel / Pitchfork 0/1/2 anchors; tank level 13.78 -> 80 live-apply; short plot <16px; ProgressBar filled-bar pixels; seeded series invariants; generator model-only comment). Updates the two Phase 1/2 tests that encoded the old assumptions (generic-only Stock/Inst tables; ARCHETYPE == palette archetype for every kind).
138 lines
5.9 KiB
Python
138 lines
5.9 KiB
Python
"""Tests for lightgui.xframe.core: registry, hit-testing, handles."""
|
|
|
|
import unittest
|
|
|
|
from lightgui.xframe import core
|
|
from lightgui.xframe import palette
|
|
|
|
|
|
class RegistryTests(unittest.TestCase):
|
|
def test_all_palette_kinds_resolve(self):
|
|
for entry in palette.PALETTE:
|
|
cls = core.lookup(entry.name)
|
|
self.assertIsNotNone(cls, entry.name)
|
|
if entry.name.startswith("Stock"):
|
|
# Phase 6: Stock kinds draw in stock.StockWidget,
|
|
# whose ARCHETYPE is "Chart" regardless of the
|
|
# palette's per-kind archetype (Indicator etc.).
|
|
from lightgui.xframe import stock as stock_mod
|
|
self.assertIs(cls, stock_mod.StockWidget, entry.name)
|
|
elif entry.name.startswith("Inst"):
|
|
from lightgui.xframe import instruments as inst_mod
|
|
self.assertIs(cls, inst_mod.InstWidget, entry.name)
|
|
else:
|
|
self.assertEqual(cls.ARCHETYPE, entry.archetype)
|
|
|
|
def test_unknown_kind_is_none(self):
|
|
self.assertIsNone(core.lookup("GtkNoSuchWidget"))
|
|
self.assertIsNone(core.create("GtkNoSuchWidget", "X_001"))
|
|
self.assertFalse(core.is_known_kind("GtkNoSuchWidget"))
|
|
|
|
def test_create_uses_registry_default_size(self):
|
|
widget = core.create("GtkButton", "GtkButton_001", 10, 20)
|
|
self.assertEqual((widget.width, widget.height), (150, 36))
|
|
self.assertEqual(widget.archetype, "Button")
|
|
widget = core.create("GtkAboutDialog", "GtkAboutDialog_001")
|
|
self.assertEqual((widget.width, widget.height), (300, 220))
|
|
|
|
def test_create_explicit_size(self):
|
|
widget = core.create("GtkButton", "B", 0, 0, 200, 50)
|
|
self.assertEqual((widget.width, widget.height), (200, 50))
|
|
|
|
def test_archetype_classes_cover_all_archetypes(self):
|
|
archetypes = {e.archetype for e in palette.PALETTE}
|
|
self.assertEqual(archetypes, set(core.ARCHETYPE_CLASSES))
|
|
|
|
|
|
class WidgetStateTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.widget = core.create("GtkButton", "GtkButton_001", 100, 80,
|
|
150, 36)
|
|
|
|
def test_setters_are_state_only(self):
|
|
self.widget.set_bounds(5, 6, 200, 40)
|
|
self.assertEqual((self.widget.x, self.widget.y,
|
|
self.widget.width, self.widget.height),
|
|
(5, 6, 200, 40))
|
|
# Phase 2: set_prop validates against the property table;
|
|
# a Button's caption prop is "label" (proposal SS2.1).
|
|
self.widget.set_prop("label", "Hello")
|
|
self.assertEqual(self.widget.text, "Hello")
|
|
self.assertEqual(self.widget.get_prop("label"), "Hello")
|
|
|
|
def test_set_bounds_clamps(self):
|
|
self.widget.set_bounds(-10, -5, 5, 3)
|
|
self.assertEqual((self.widget.x, self.widget.y), (0, 0))
|
|
self.assertEqual((self.widget.width, self.widget.height),
|
|
(core.MIN_WIDTH, core.MIN_HEIGHT))
|
|
|
|
def test_text_defaults_to_instance_name(self):
|
|
widget = core.create("GtkButton", "GtkButton_001")
|
|
self.assertEqual(widget.text, "GtkButton_001")
|
|
|
|
def test_contains(self):
|
|
self.assertTrue(self.widget.contains(100, 80))
|
|
self.assertTrue(self.widget.contains(250, 116))
|
|
self.assertFalse(self.widget.contains(99, 80))
|
|
self.assertFalse(self.widget.contains(251, 80))
|
|
self.assertFalse(self.widget.contains(100, 117))
|
|
|
|
|
|
class HandleGeometryTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.widget = core.create("GtkButton", "GtkButton_001", 100, 80,
|
|
150, 36)
|
|
self.widget.handles_on = True
|
|
|
|
def test_handle_size_is_13(self):
|
|
self.assertEqual(core.HANDLE_SIZE, 13)
|
|
self.assertEqual(core.HANDLE_HIT_PAD, 8)
|
|
|
|
def test_handle_centres(self):
|
|
# Corners on the widget corners, edges on the midpoints.
|
|
self.assertEqual(self.widget.handle_centre(0), (100, 80)) # NW
|
|
self.assertEqual(self.widget.handle_centre(2), (250, 80)) # NE
|
|
self.assertEqual(self.widget.handle_centre(4), (250, 116)) # SE
|
|
self.assertEqual(self.widget.handle_centre(6), (100, 116)) # SW
|
|
self.assertEqual(self.widget.handle_centre(1), (175, 80)) # N
|
|
self.assertEqual(self.widget.handle_centre(3), (250, 98)) # E
|
|
self.assertEqual(self.widget.handle_centre(5), (175, 116)) # S
|
|
self.assertEqual(self.widget.handle_centre(7), (100, 98)) # W
|
|
|
|
def test_handle_rect_is_13x13_centred(self):
|
|
x, y, w, h = self.widget.handle_rect(0)
|
|
self.assertEqual((w, h), (13, 13))
|
|
self.assertEqual((x, y), (100 - 6, 80 - 6))
|
|
|
|
def test_handle_at_with_pad(self):
|
|
# 8px pad: a point 8px outside the 13px square still grabs.
|
|
self.assertEqual(self.widget.handle_at(100 - 6 - 8, 80), 0)
|
|
self.assertEqual(self.widget.handle_at(100 - 6 - 9, 80), -1)
|
|
self.assertEqual(self.widget.handle_at(250, 98), 3)
|
|
self.assertEqual(self.widget.handle_at(175, 116), 5)
|
|
self.assertEqual(self.widget.handle_at(175, 100), -1)
|
|
|
|
def test_handle_at_off_when_handles_off(self):
|
|
self.widget.handles_on = False
|
|
self.assertEqual(self.widget.handle_at(100, 80), -1)
|
|
|
|
def test_apply_handle_drag_se(self):
|
|
self.widget.apply_handle_drag(4, 10, 5)
|
|
self.assertEqual((self.widget.width, self.widget.height),
|
|
(160, 41))
|
|
|
|
def test_apply_handle_drag_nw_moves_origin(self):
|
|
self.widget.apply_handle_drag(0, 10, 5)
|
|
self.assertEqual((self.widget.x, self.widget.y,
|
|
self.widget.width, self.widget.height),
|
|
(110, 85, 140, 31))
|
|
|
|
def test_apply_handle_drag_clamps_minimum(self):
|
|
self.widget.apply_handle_drag(4, -500, -500)
|
|
self.assertEqual((self.widget.width, self.widget.height),
|
|
(core.MIN_WIDTH, core.MIN_HEIGHT))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|