File utils1 (#1)
Tests / test_and_lint (push) Successful in 7s

Reviewed-on: #1
Co-authored-by: Mathias Scheider <mathias2784@web.de>
This commit was merged in pull request #1.
This commit is contained in:
2026-10-01 19:13:45 +00:00
committed by mathias2784
parent 59faa596d5
commit 9d13c6ec14
12 changed files with 452 additions and 15 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Make the test suite runnable on machines without Tk system libraries.
``utils.filedialogs`` imports tkinter at module level, and the CI runner
lacks the Tk shared libraries (``import tkinter`` fails on a missing
``libtk8.6.so``). Since pytest imports every test module at collection
time — including the deselected ``test_filedialogs_live.py`` — a minimal
stub is registered in ``sys.modules`` here, before any test module is
imported, whenever tkinter is not importable.
The hermetic tests in ``test_filedialogs.py`` mock every tkinter
touchpoint anyway, so the stub is never actually used.
"""
import sys
import types
try:
import tkinter # noqa: F401
except ImportError:
_tk_stub = types.ModuleType("tkinter")
_filedialog_stub = types.ModuleType("tkinter.filedialog")
def _tk_unavailable(*args, **kwargs):
raise AssertionError("real tkinter was called without a display")
_tk_stub.Tk = _tk_unavailable
_tk_stub.filedialog = _filedialog_stub
_filedialog_stub.askdirectory = _tk_unavailable
_filedialog_stub.askopenfilename = _tk_unavailable
sys.modules["tkinter"] = _tk_stub
sys.modules["tkinter.filedialog"] = _filedialog_stub