From 78f8a9b946ec7aaaee4d9e12994c37f209a9f75c Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Wed, 15 Jan 2025 08:26:54 -0600 Subject: [PATCH] add check_tk_version() to support, to avoid tests on too new a version of Tk --- Lib/test/support/__init__.py | 13 +++++++++++++ Lib/test/test_tkinter/__init__.py | 11 +++++++++++ Lib/test/test_ttk/__init__.py | 9 +++++++++ Lib/test/test_ttk_textonly.py | 4 +++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index ee9520a8838625..33745517465bfe 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2992,3 +2992,16 @@ def is_libssl_fips_mode(): except ImportError: return False # more of a maybe, unless we add this to the _ssl module. return get_fips_mode() != 0 + + +def check_tk_version(): + from .import_helper import import_module + import_module('_tkinter') + import tkinter + tcl = tkinter.Tcl() + major, minor, micro = tcl.call("info", "patchlevel").split(".") + version = f"{int(major):02d}{int(minor):02d}{int(micro):02d}" + # update max version number as necessary + if version > "080699": + raise unittest.SkipTest(f"Tk version {major}.{minor}.{micro}" + " not supported") diff --git a/Lib/test/test_tkinter/__init__.py b/Lib/test/test_tkinter/__init__.py index aa196c12c804ac..dcaeed3a260699 100644 --- a/Lib/test/test_tkinter/__init__.py +++ b/Lib/test/test_tkinter/__init__.py @@ -6,6 +6,7 @@ import_helper, load_package_tests, requires, + check_tk_version, ) @@ -19,6 +20,16 @@ # Skip test if tk cannot be initialized. requires('gui') +# Skip test if tk version is too new. +check_tk_version() + + +import tkinter +tcl = tkinter.Tcl() +major, minor, micro = tcl.call("info", "patchlevel").split(".") +version = f"{int(major):02d}{int(minor):02d}{int(micro):02d}" +if version > "080699": + raise unittest.SkipTest(f"Tk version {major}.{minor}.{micro} not supported") def load_tests(*args): return load_package_tests(os.path.dirname(__file__), *args) diff --git a/Lib/test/test_ttk/__init__.py b/Lib/test/test_ttk/__init__.py index 7ee7ffbd6d7408..f208958d319b88 100644 --- a/Lib/test/test_ttk/__init__.py +++ b/Lib/test/test_ttk/__init__.py @@ -13,12 +13,21 @@ # Skip test if tk cannot be initialized. support.requires('gui') +# Skip test if tk version is too new. +support.check_tk_version() import tkinter from _tkinter import TclError from tkinter import ttk +tcl = tkinter.Tcl() +major, minor, micro = tcl.call("info", "patchlevel").split(".") +version = f"{int(major):02d}{int(minor):02d}{int(micro):02d}" +if version > "080699": + raise unittest.SkipTest(f"Tk version {major}.{minor}.{micro} not supported") + + def setUpModule(): root = None try: diff --git a/Lib/test/test_ttk_textonly.py b/Lib/test/test_ttk_textonly.py index e6525c4d6c6982..39910fb12d02ba 100644 --- a/Lib/test/test_ttk_textonly.py +++ b/Lib/test/test_ttk_textonly.py @@ -1,8 +1,10 @@ -from test.support import import_helper +from test.support import import_helper, check_tk_version # Skip this test if _tkinter does not exist. import_helper.import_module('_tkinter') +check_tk_version() + import unittest from tkinter import ttk