2026-02-11 00:02:35 -08:00
|
|
|
import tkinter as tk
|
|
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
import pytest
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
from tarot.tarot_api import Tarot
|
2026-02-11 00:02:35 -08:00
|
|
|
from tarot.ui import CubeDisplay
|
|
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
|
|
|
|
|
def test_canvas_structure():
|
|
|
|
|
# Mock Tk root
|
|
|
|
|
class MockRoot:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.bindings = {}
|
2026-02-11 00:02:35 -08:00
|
|
|
|
|
|
|
|
def bind(self, key, callback):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def title(self, _):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def update_idletasks(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def winfo_reqwidth(self):
|
|
|
|
|
return 800
|
|
|
|
|
|
|
|
|
|
def winfo_reqheight(self):
|
|
|
|
|
return 600
|
|
|
|
|
|
|
|
|
|
def winfo_screenwidth(self):
|
|
|
|
|
return 1920
|
|
|
|
|
|
|
|
|
|
def winfo_screenheight(self):
|
|
|
|
|
return 1080
|
|
|
|
|
|
|
|
|
|
def geometry(self, _):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def mainloop(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def focus_force(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
# Mock Frame
|
|
|
|
|
class MockFrame:
|
|
|
|
|
def __init__(self, master=None, **kwargs):
|
|
|
|
|
self.children = []
|
|
|
|
|
self.master = master
|
2026-02-11 00:02:35 -08:00
|
|
|
|
|
|
|
|
def pack(self, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def place(self, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def winfo_children(self):
|
|
|
|
|
return self.children
|
|
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def update_idletasks(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def winfo_reqwidth(self):
|
|
|
|
|
return 100
|
|
|
|
|
|
|
|
|
|
def winfo_reqheight(self):
|
|
|
|
|
return 100
|
|
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
# Mock Canvas
|
|
|
|
|
class MockCanvas:
|
|
|
|
|
def __init__(self, master=None, **kwargs):
|
|
|
|
|
self.master = master
|
2026-02-11 00:02:35 -08:00
|
|
|
|
|
|
|
|
def pack(self, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def bind(self, event, callback):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def create_window(self, coords, **kwargs):
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
def config(self, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def bbox(self, tag):
|
|
|
|
|
return (0, 0, 100, 100)
|
|
|
|
|
|
|
|
|
|
def winfo_width(self):
|
|
|
|
|
return 800
|
|
|
|
|
|
|
|
|
|
def winfo_height(self):
|
|
|
|
|
return 600
|
|
|
|
|
|
|
|
|
|
def coords(self, item, x, y):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def scan_mark(self, x, y):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def scan_dragto(self, x, y, gain=1):
|
|
|
|
|
pass
|
2025-12-05 03:41:16 -08:00
|
|
|
|
|
|
|
|
# Monkey patch tk
|
|
|
|
|
original_tk = tk.Tk
|
|
|
|
|
original_frame = tk.ttk.Frame
|
|
|
|
|
original_canvas = tk.Canvas
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
try:
|
|
|
|
|
tk.Tk = MockRoot
|
|
|
|
|
tk.ttk.Frame = MockFrame
|
|
|
|
|
tk.Canvas = MockCanvas
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
cube = Tarot.cube
|
|
|
|
|
display = CubeDisplay(cube)
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
# Trigger show to build UI
|
|
|
|
|
# We can't fully run show() because of mainloop, but we can instantiate parts
|
|
|
|
|
# Actually, show() creates the root.
|
|
|
|
|
# Let's just verify the structure by inspecting the code or trusting the manual test.
|
|
|
|
|
# But we can test the pan methods directly.
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
display.canvas = MockCanvas()
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
# Test pan methods
|
|
|
|
|
class MockEvent:
|
|
|
|
|
x = 10
|
|
|
|
|
y = 20
|
|
|
|
|
x_root = 110
|
|
|
|
|
y_root = 120
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
display._start_pan(MockEvent())
|
|
|
|
|
display._pan(MockEvent())
|
2026-02-11 00:02:35 -08:00
|
|
|
|
2025-12-05 03:41:16 -08:00
|
|
|
finally:
|
|
|
|
|
tk.Tk = original_tk
|
|
|
|
|
tk.ttk.Frame = original_frame
|
|
|
|
|
tk.Canvas = original_canvas
|