Coverage for idle_test/test_pathbrowser.py: 60%

64 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-11 13:22 -0700

1"Test pathbrowser, coverage 95%." 

2 

3from idlelib import pathbrowser 

4import unittest 

5from test.support import requires 

6from tkinter import Tk 

7 

8import os.path 

9import pyclbr # for _modules 

10import sys # for sys.path 

11 

12from idlelib.idle_test.mock_idle import Func 

13import idlelib # for __file__ 

14from idlelib import browser 

15from idlelib.tree import TreeNode 

16 

17 

18class PathBrowserTest(unittest.TestCase): 

19 

20 @classmethod 

21 def setUpClass(cls): 

22 requires('gui') 

23 cls.root = Tk() 

24 cls.root.withdraw() 

25 cls.pb = pathbrowser.PathBrowser(cls.root, _utest=True) 

26 

27 @classmethod 

28 def tearDownClass(cls): 

29 cls.pb.close() 

30 cls.root.update_idletasks() 

31 cls.root.destroy() 

32 del cls.root, cls.pb 

33 

34 def test_init(self): 

35 pb = self.pb 

36 eq = self.assertEqual 

37 eq(pb.master, self.root) 

38 eq(pyclbr._modules, {}) 

39 self.assertIsInstance(pb.node, TreeNode) 

40 self.assertIsNotNone(browser.file_open) 

41 

42 def test_settitle(self): 

43 pb = self.pb 

44 self.assertEqual(pb.top.title(), 'Path Browser') 

45 self.assertEqual(pb.top.iconname(), 'Path Browser') 

46 

47 def test_rootnode(self): 

48 pb = self.pb 

49 rn = pb.rootnode() 

50 self.assertIsInstance(rn, pathbrowser.PathBrowserTreeItem) 

51 

52 def test_close(self): 

53 pb = self.pb 

54 pb.top.destroy = Func() 

55 pb.node.destroy = Func() 

56 pb.close() 

57 self.assertTrue(pb.top.destroy.called) 

58 self.assertTrue(pb.node.destroy.called) 

59 del pb.top.destroy, pb.node.destroy 

60 

61 

62class DirBrowserTreeItemTest(unittest.TestCase): 

63 

64 def test_DirBrowserTreeItem(self): 

65 # Issue16226 - make sure that getting a sublist works 

66 d = pathbrowser.DirBrowserTreeItem('') 1b

67 d.GetSubList() 1b

68 self.assertEqual('', d.GetText()) 1b

69 

70 dir = os.path.split(os.path.abspath(idlelib.__file__))[0] 1b

71 self.assertEqual(d.ispackagedir(dir), True) 1b

72 self.assertEqual(d.ispackagedir(dir + '/Icons'), False) 1b

73 

74 

75class PathBrowserTreeItemTest(unittest.TestCase): 

76 

77 def test_PathBrowserTreeItem(self): 

78 p = pathbrowser.PathBrowserTreeItem() 1c

79 self.assertEqual(p.GetText(), 'sys.path') 1c

80 sub = p.GetSubList() 1c

81 self.assertEqual(len(sub), len(sys.path)) 1c

82 self.assertEqual(type(sub[0]), pathbrowser.DirBrowserTreeItem) 1c

83 

84 

85if __name__ == '__main__': 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true

86 unittest.main(verbosity=2, exit=False)