| 1 | import Tkinter |
| 2 | import Test |
| 3 | import Pmw |
| 4 | |
| 5 | Test.initialise() |
| 6 | |
| 7 | if Tkinter.TkVersion >= 8.4: |
| 8 | expected1 = 'TclError: bad relief "bogus": must be ' |
| 9 | else: |
| 10 | expected1 = 'TclError: bad relief type "bogus": must be ' |
| 11 | |
| 12 | c = Pmw.RadioSelect |
| 13 | |
| 14 | kw_1 = {'labelpos' : 'nw', 'label_text' : 'Radio Select:'} |
| 15 | tests_1 = ( |
| 16 | (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}), |
| 17 | (Test.num_options, (), 8), |
| 18 | (c.index, Pmw.END, 'ValueError: RadioSelect has no buttons'), |
| 19 | (c.add, ('Fruit',), Tkinter.Button), |
| 20 | (c.add, ('Vegetables',), Tkinter.Button), |
| 21 | (c.add, ('CornFlakes',), {'text': 'Cereals'}, Tkinter.Button), |
| 22 | (c.add, ('Legumes',), Tkinter.Button), |
| 23 | (c.add, ('Legumes',), 'ValueError: button "Legumes" already exists'), |
| 24 | (c.index, 0, 0), |
| 25 | (c.index, Pmw.END, 3), |
| 26 | (c.index, 'Vegetables', 1), |
| 27 | (c.index, 'Fruit', 0), |
| 28 | (c.index, 12, 'ValueError: index "12" is out of range'), |
| 29 | (c.index, 'bogus', 'ValueError: bad index "bogus": ' + \ |
| 30 | 'must be a name, a number or Pmw.END'), |
| 31 | ('hull_background', 'yellow'), |
| 32 | ('hull_show', 'X', 'TclError: unknown option "-show"'), |
| 33 | ('frame_relief', 'raised'), |
| 34 | ('frame_borderwidth', 4), |
| 35 | ('frame_borderwidth', 2), |
| 36 | ('command', Test.callback1), |
| 37 | (c.invoke, 'Vegetables', 'Vegetables'), |
| 38 | ('hull_cursor', 'gumby'), |
| 39 | ('Button_state', 'disabled'), |
| 40 | ('Button_background', 'Green'), |
| 41 | ('Button_cursor', 'watch'), |
| 42 | ('Button_background', 'grey85'), |
| 43 | ('label_foreground', 'Green'), |
| 44 | ('label_foreground', 'Black'), |
| 45 | ('label_highlightcolor', 'Red'), |
| 46 | ('Fruit_background', 'red'), |
| 47 | ('Vegetables_background', 'green'), |
| 48 | ('CornFlakes_background', 'yellow'), |
| 49 | ('Legumes_background', 'brown'), |
| 50 | ('Legumes_foreground', 'white'), |
| 51 | (c.add, ('Foo',), Tkinter.Button), |
| 52 | ('label_text', 'Label'), |
| 53 | ('frame_relief', 'sunken'), |
| 54 | ('frame_relief', 'bogus', expected1 + Test.reliefs), |
| 55 | (c.deleteall, ()), |
| 56 | ) |
| 57 | |
| 58 | kw_2 = { |
| 59 | 'labelpos' : 'nw', |
| 60 | 'label_text' : 'Multiple:', |
| 61 | 'selectmode' : 'multiple', |
| 62 | } |
| 63 | tests_2 = ( |
| 64 | (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}), |
| 65 | (c.add, ('Fruit',), Tkinter.Button), |
| 66 | (c.add, ('Vegetables',), Tkinter.Button), |
| 67 | (c.add, ('CornFlakes',), {'text': 'Cereals'}, Tkinter.Button), |
| 68 | (c.add, ('Legumes',), Tkinter.Button), |
| 69 | ('command', Test.callback2), |
| 70 | (c.getcurselection, (), ()), |
| 71 | (c.invoke, 'Vegetables', ('Vegetables', 1)), |
| 72 | (c.getcurselection, (), ('Vegetables',)), |
| 73 | (c.invoke, 'Legumes', ('Legumes', 1)), |
| 74 | (c.getcurselection, (), ('Vegetables', 'Legumes')), |
| 75 | (c.invoke, 'Fruit', ('Fruit', 1)), |
| 76 | (c.getcurselection, (), ('Vegetables', 'Legumes', 'Fruit')), |
| 77 | (c.invoke, 'Legumes', ('Legumes', 0)), |
| 78 | (c.getcurselection, (), ('Vegetables', 'Fruit')), |
| 79 | (c.deleteall, ()), |
| 80 | (c.add, ('Fruit',), Tkinter.Button), |
| 81 | (c.add, ('Vegetables',), Tkinter.Button), |
| 82 | (c.invoke, 'Vegetables', ('Vegetables', 1)), |
| 83 | (c.getcurselection, (), ('Vegetables',)), |
| 84 | ) |
| 85 | |
| 86 | alltests = [ |
| 87 | (tests_1, kw_1), |
| 88 | (tests_2, kw_2), |
| 89 | ] |
| 90 | |
| 91 | |
| 92 | tests_3 = ( |
| 93 | (c.pack, (), {'padx' : 10, 'pady' : 10}), |
| 94 | (c.add, ('Foo',), Tkinter.Button), |
| 95 | (c.add, ('Bar',), Tkinter.Button), |
| 96 | ) |
| 97 | |
| 98 | poslist = ('nw', 'n', 'ne', 'en', 'e', 'es', 'se', 's', 'sw', 'ws', 'w', 'wn',) |
| 99 | for pos in poslist: |
| 100 | kw_3 = { |
| 101 | 'labelpos' : pos, |
| 102 | 'orient' : 'vertical', |
| 103 | 'padx' : 20, |
| 104 | 'pady' : 20, |
| 105 | 'label_text' : 'Radio Select', |
| 106 | } |
| 107 | alltests.append((tests_3, kw_3)) |
| 108 | |
| 109 | testData = ((c, alltests),) |
| 110 | |
| 111 | if __name__ == '__main__': |
| 112 | Test.runTests(testData) |