| 
									
										
										
										
											2018-06-18 04:47:59 -04:00
										 |  |  | "Test pathbrowser, coverage 95%." | 
					
						
							| 
									
										
										
										
											2017-11-22 19:05:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 04:47:59 -04:00
										 |  |  | from idlelib import pathbrowser | 
					
						
							|  |  |  | import unittest | 
					
						
							|  |  |  | from test.support import requires | 
					
						
							|  |  |  | from tkinter import Tk | 
					
						
							| 
									
										
										
										
											2017-11-22 19:05:25 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | import os.path | 
					
						
							|  |  |  | import pyclbr  # for _modules | 
					
						
							|  |  |  | import sys  # for sys.path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from idlelib.idle_test.mock_idle import Func | 
					
						
							|  |  |  | import idlelib  # for __file__ | 
					
						
							|  |  |  | from idlelib import browser | 
					
						
							|  |  |  | from idlelib.tree import TreeNode | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-27 21:32:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PathBrowserTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:05:25 -05:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def setUpClass(cls): | 
					
						
							|  |  |  |         requires('gui') | 
					
						
							|  |  |  |         cls.root = Tk() | 
					
						
							|  |  |  |         cls.root.withdraw() | 
					
						
							|  |  |  |         cls.pb = pathbrowser.PathBrowser(cls.root, _utest=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def tearDownClass(cls): | 
					
						
							|  |  |  |         cls.pb.close() | 
					
						
							|  |  |  |         cls.root.update_idletasks() | 
					
						
							|  |  |  |         cls.root.destroy() | 
					
						
							|  |  |  |         del cls.root, cls.pb | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_init(self): | 
					
						
							|  |  |  |         pb = self.pb | 
					
						
							|  |  |  |         eq = self.assertEqual | 
					
						
							|  |  |  |         eq(pb.master, self.root) | 
					
						
							|  |  |  |         eq(pyclbr._modules, {}) | 
					
						
							|  |  |  |         self.assertIsInstance(pb.node, TreeNode) | 
					
						
							|  |  |  |         self.assertIsNotNone(browser.file_open) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_settitle(self): | 
					
						
							|  |  |  |         pb = self.pb | 
					
						
							|  |  |  |         self.assertEqual(pb.top.title(), 'Path Browser') | 
					
						
							|  |  |  |         self.assertEqual(pb.top.iconname(), 'Path Browser') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_rootnode(self): | 
					
						
							|  |  |  |         pb = self.pb | 
					
						
							|  |  |  |         rn = pb.rootnode() | 
					
						
							|  |  |  |         self.assertIsInstance(rn, pathbrowser.PathBrowserTreeItem) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_close(self): | 
					
						
							|  |  |  |         pb = self.pb | 
					
						
							|  |  |  |         pb.top.destroy = Func() | 
					
						
							|  |  |  |         pb.node.destroy = Func() | 
					
						
							|  |  |  |         pb.close() | 
					
						
							|  |  |  |         self.assertTrue(pb.top.destroy.called) | 
					
						
							|  |  |  |         self.assertTrue(pb.node.destroy.called) | 
					
						
							|  |  |  |         del pb.top.destroy, pb.node.destroy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DirBrowserTreeItemTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-27 21:32:03 -04:00
										 |  |  |     def test_DirBrowserTreeItem(self): | 
					
						
							|  |  |  |         # Issue16226 - make sure that getting a sublist works | 
					
						
							| 
									
										
										
										
											2016-05-28 13:22:31 -04:00
										 |  |  |         d = pathbrowser.DirBrowserTreeItem('') | 
					
						
							| 
									
										
										
										
											2013-05-27 21:32:03 -04:00
										 |  |  |         d.GetSubList() | 
					
						
							| 
									
										
										
										
											2015-07-20 17:44:59 -04:00
										 |  |  |         self.assertEqual('', d.GetText()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dir = os.path.split(os.path.abspath(idlelib.__file__))[0] | 
					
						
							|  |  |  |         self.assertEqual(d.ispackagedir(dir), True) | 
					
						
							|  |  |  |         self.assertEqual(d.ispackagedir(dir + '/Icons'), False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:05:25 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PathBrowserTreeItemTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 17:44:59 -04:00
										 |  |  |     def test_PathBrowserTreeItem(self): | 
					
						
							| 
									
										
										
										
											2016-05-28 13:22:31 -04:00
										 |  |  |         p = pathbrowser.PathBrowserTreeItem() | 
					
						
							| 
									
										
										
										
											2015-07-20 17:44:59 -04:00
										 |  |  |         self.assertEqual(p.GetText(), 'sys.path') | 
					
						
							|  |  |  |         sub = p.GetSubList() | 
					
						
							|  |  |  |         self.assertEqual(len(sub), len(sys.path)) | 
					
						
							| 
									
										
										
										
											2016-05-28 13:22:31 -04:00
										 |  |  |         self.assertEqual(type(sub[0]), pathbrowser.DirBrowserTreeItem) | 
					
						
							| 
									
										
										
										
											2013-05-27 21:32:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:05:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-27 21:32:03 -04:00
										 |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     unittest.main(verbosity=2, exit=False) |