diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-12-19 10:17:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 10:17:08 (GMT) |
commit | 3d569fd6dccf9f582bafaca04d3535094cae393e (patch) | |
tree | 2468e1823c476391b2abecc79d093e0cbeb96b0c /Lib/tkinter/test/test_ttk/test_extensions.py | |
parent | 1e27b57dbc8c1b758e37a531487813aef2d111ca (diff) | |
download | cpython-3d569fd6dccf9f582bafaca04d3535094cae393e.zip cpython-3d569fd6dccf9f582bafaca04d3535094cae393e.tar.gz cpython-3d569fd6dccf9f582bafaca04d3535094cae393e.tar.bz2 |
bpo-42630: Improve error reporting in Tkinter for absent default root (GH-23781)
* Tkinter functions and constructors which need a default root window
raise now RuntimeError with descriptive message instead of obscure
AttributeError or NameError if it is not created yet or cannot
be created automatically.
* Add tests for all functions which use default root window.
* Fix import in the pynche script.
Diffstat (limited to 'Lib/tkinter/test/test_ttk/test_extensions.py')
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_extensions.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/Lib/tkinter/test/test_ttk/test_extensions.py b/Lib/tkinter/test/test_ttk/test_extensions.py index 6937ba1..1a70e0b 100644 --- a/Lib/tkinter/test/test_ttk/test_extensions.py +++ b/Lib/tkinter/test/test_ttk/test_extensions.py @@ -2,8 +2,8 @@ import sys import unittest import tkinter from tkinter import ttk -from test.support import requires, run_unittest, swap_attr -from tkinter.test.support import AbstractTkTest, destroy_default_root +from test.support import requires, run_unittest +from tkinter.test.support import AbstractTkTest, AbstractDefaultRootTest requires('gui') @@ -46,20 +46,6 @@ class LabeledScaleTest(AbstractTkTest, unittest.TestCase): if hasattr(sys, 'last_type'): self.assertNotEqual(sys.last_type, tkinter.TclError) - - def test_initialization_no_master(self): - # no master passing - with swap_attr(tkinter, '_default_root', None), \ - swap_attr(tkinter, '_support_default_root', True): - try: - x = ttk.LabeledScale() - self.assertIsNotNone(tkinter._default_root) - self.assertEqual(x.master, tkinter._default_root) - self.assertEqual(x.tk, tkinter._default_root.tk) - x.destroy() - finally: - destroy_default_root() - def test_initialization(self): # master passing master = tkinter.Frame(self.root) @@ -311,7 +297,13 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase): optmenu2.destroy() -tests_gui = (LabeledScaleTest, OptionMenuTest) +class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): + + def test_labeledscale(self): + self._test_widget(ttk.LabeledScale) + + +tests_gui = (LabeledScaleTest, OptionMenuTest, DefaultRootTest) if __name__ == "__main__": run_unittest(*tests_gui) |