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_tkinter/test_font.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_tkinter/test_font.py')
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_font.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/Lib/tkinter/test/test_tkinter/test_font.py b/Lib/tkinter/test/test_tkinter/test_font.py index 6d1eea4..3f71209 100644 --- a/Lib/tkinter/test/test_tkinter/test_font.py +++ b/Lib/tkinter/test/test_tkinter/test_font.py @@ -2,7 +2,7 @@ import unittest import tkinter from tkinter import font from test.support import requires, run_unittest, gc_collect, ALWAYS_EQ -from tkinter.test.support import AbstractTkTest +from tkinter.test.support import AbstractTkTest, AbstractDefaultRootTest requires('gui') @@ -107,7 +107,37 @@ class FontTest(AbstractTkTest, unittest.TestCase): ) -tests_gui = (FontTest, ) +class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): + + def test_families(self): + self.assertRaises(RuntimeError, font.families) + root = tkinter.Tk() + families = font.families() + self.assertIsInstance(families, tuple) + self.assertTrue(families) + for family in families: + self.assertIsInstance(family, str) + self.assertTrue(family) + root.destroy() + tkinter.NoDefaultRoot() + self.assertRaises(RuntimeError, font.families) + + def test_names(self): + self.assertRaises(RuntimeError, font.names) + root = tkinter.Tk() + names = font.names() + self.assertIsInstance(names, tuple) + self.assertTrue(names) + for name in names: + self.assertIsInstance(name, str) + self.assertTrue(name) + self.assertIn(fontname, names) + root.destroy() + tkinter.NoDefaultRoot() + self.assertRaises(RuntimeError, font.names) + + +tests_gui = (FontTest, DefaultRootTest) if __name__ == "__main__": run_unittest(*tests_gui) |