Coverage for idle_test/test_tree.py: 9%

39 statements  

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

1"Test tree. coverage 56%." 

2 

3from idlelib import tree 

4import unittest 

5from test.support import requires 

6requires('gui') 

7from tkinter import Tk, EventType, SCROLL 

8 

9 

10class TreeTest(unittest.TestCase): 

11 

12 @classmethod 

13 def setUpClass(cls): 

14 cls.root = Tk() 

15 cls.root.withdraw() 

16 

17 @classmethod 

18 def tearDownClass(cls): 

19 cls.root.destroy() 

20 del cls.root 

21 

22 def test_init(self): 

23 # Start with code slightly adapted from htest. 

24 sc = tree.ScrolledCanvas( 

25 self.root, bg="white", highlightthickness=0, takefocus=1) 

26 sc.frame.pack(expand=1, fill="both", side='left') 

27 item = tree.FileTreeItem(tree.ICONDIR) 

28 node = tree.TreeNode(sc.canvas, None, item) 

29 node.expand() 

30 

31 

32class TestScrollEvent(unittest.TestCase): 

33 

34 def test_wheel_event(self): 

35 # Fake widget class containing `yview` only. 

36 class _Widget: 

37 def __init__(widget, *expected): 

38 widget.expected = expected 

39 def yview(widget, *args): 

40 self.assertTupleEqual(widget.expected, args) 

41 # Fake event class 

42 class _Event: 

43 pass 

44 # (type, delta, num, amount) 

45 tests = ((EventType.MouseWheel, 120, -1, -5), 

46 (EventType.MouseWheel, -120, -1, 5), 

47 (EventType.ButtonPress, -1, 4, -5), 

48 (EventType.ButtonPress, -1, 5, 5)) 

49 

50 event = _Event() 

51 for ty, delta, num, amount in tests: 

52 event.type = ty 

53 event.delta = delta 

54 event.num = num 

55 res = tree.wheel_event(event, _Widget(SCROLL, amount, "units")) 

56 self.assertEqual(res, "break") 

57 

58 

59if __name__ == '__main__': 

60 unittest.main(verbosity=2)