Skip to content

Commit dfaf382

Browse files
committed
fix(rich text): Make the tests less sensitive to env changes
Different Tk theme / fontconfig mapping: Tk reports whatever font the current theme gives it. On Linux that often is a logical family like "sans" which fontconfig resolves to a real family (Helvetica, DejaVu Sans, etc.). On another environment (pip vs uv) the system/theme/fontconfig mapping differs, so get_widget_font_family_and_size can return "sans-serif" or "Helvetica". Different display/DPI and unit conventions: Tk reports font "size" as either points (positive) or pixels (negative). Many Linux themes specify pixel sizes (e.g. -12 means 12 pixels). On Windows the theme often uses point sizes (e.g. 9). With a typical DPI (96) 12 px ≈ 9 pt, so the two numbers are consistent in physical size but different numerically and signed. Different runtime environments used by pip and uv: they may run tests under different user/system fonts, different themes, headless vs desktop, or different X11/Wayland/backends — all of which change the default Tk font.
1 parent 879f7e7 commit dfaf382

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/test_frontend_tkinter_rich_text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def tearDown(self) -> None:
7777
def test_get_widget_font_family_and_size(self) -> None:
7878
label = ttk.Label(self.root, text="Test")
7979
family, size = get_widget_font_family_and_size(label)
80-
expected_family = "Segoe UI" if platform_system() == "Windows" else "sans-serif"
81-
expected_size = 9 if platform_system() == "Windows" else 10
80+
expected_family = ["Segoe UI"] if platform_system() == "Windows" else ["Helvetica", "sans-serif"]
81+
expected_size = [9] if platform_system() == "Windows" else [-12, 10]
8282
assert isinstance(family, str)
8383
assert isinstance(size, int)
84-
assert family == expected_family
85-
assert size == expected_size
84+
assert family in expected_family
85+
assert size in expected_size
8686

8787

8888
if __name__ == "__main__":

0 commit comments

Comments
 (0)