mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.9] bpo-42630: Improve error reporting in Tkinter for absent default root (GH-23781) (GH-23853)
* 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.
(cherry picked from commit 3d569fd6dc)
			
			
This commit is contained in:
		
							parent
							
								
									d458d8dab0
								
							
						
					
					
						commit
						87e7a14ee3
					
				
					 19 changed files with 316 additions and 87 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
| 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') | ||||
| 
 | ||||
|  | @ -101,7 +101,38 @@ def test_names(self): | |||
|             self.assertTrue(name) | ||||
|         self.assertIn(fontname, names) | ||||
| 
 | ||||
| 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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka