This commit is contained in:
nose
2025-12-05 03:41:16 -08:00
parent 79d4f1a09e
commit e3747555bf
22 changed files with 3669 additions and 388 deletions

View File

@@ -0,0 +1,60 @@
import pytest
from tarot.ui import CubeDisplay
from tarot.tarot_api import Tarot
import tkinter as tk
def test_recursive_binding():
# Mock Tk root and widgets
class MockWidget:
def __init__(self):
self.children = []
self.bindings = {}
def bind(self, key, callback):
self.bindings[key] = callback
def winfo_children(self):
return self.children
def add_child(self, child):
self.children.append(child)
# Monkey patch tk
original_tk = tk.Tk
original_frame = tk.ttk.Frame
try:
# We don't need to mock everything, just enough to test _bind_recursive
cube = Tarot.cube
# We can instantiate CubeDisplay without showing it
display = CubeDisplay(cube)
# Create a mock widget tree
parent = MockWidget()
child1 = MockWidget()
child2 = MockWidget()
grandchild = MockWidget()
parent.add_child(child1)
parent.add_child(child2)
child1.add_child(grandchild)
# Run recursive binding
display._bind_recursive(parent)
# Verify bindings
assert "<ButtonPress-1>" in parent.bindings
assert "<B1-Motion>" in parent.bindings
assert "<ButtonPress-1>" in child1.bindings
assert "<B1-Motion>" in child1.bindings
assert "<ButtonPress-1>" in child2.bindings
assert "<B1-Motion>" in child2.bindings
assert "<ButtonPress-1>" in grandchild.bindings
assert "<B1-Motion>" in grandchild.bindings
finally:
pass