| 1 | import Tkinter |
| 2 | import Test |
| 3 | import Pmw |
| 4 | |
| 5 | Test.initialise() |
| 6 | |
| 7 | c = Pmw.Counter |
| 8 | |
| 9 | _myValidators = { |
| 10 | 'hello' : (lambda s: s == 'hello', len), |
| 11 | } |
| 12 | |
| 13 | kw_1 = { |
| 14 | 'labelpos' : 'w', |
| 15 | 'label_text' : 'Counter:', |
| 16 | 'buttonaspect': 2.0, |
| 17 | 'autorepeat': 0, |
| 18 | 'initwait': 1000, |
| 19 | 'padx': 5, |
| 20 | 'pady': 5, |
| 21 | 'repeatrate': 20, |
| 22 | 'entryfield_value': 'First value', |
| 23 | } |
| 24 | tests_1 = ( |
| 25 | (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}), |
| 26 | (c.get, (), 'First value'), |
| 27 | (Test.num_options, (), 12), |
| 28 | ('Arrow_borderwidth', 10), |
| 29 | ('hull_background', 'yellow'), |
| 30 | ('Arrow_background', 'green'), |
| 31 | ('label_background', 'blue'), |
| 32 | ('hull_borderwidth', 10), |
| 33 | ('entryfield_command', Test.callback), |
| 34 | ('entryfield_errorbackground', 'red'), |
| 35 | ('hull_cursor', 'gumby'), |
| 36 | ('datatype', 'time'), |
| 37 | ('datatype', 'numeric'), |
| 38 | ('entry_borderwidth', 6), |
| 39 | ('entry_relief', 'raised'), |
| 40 | ('entry_exportselection', 0), |
| 41 | ('entry_foreground', 'blue'), |
| 42 | ('hull_highlightcolor', 'Red'), |
| 43 | ('hull_highlightthickness', 2), |
| 44 | ('increment', 1), |
| 45 | ('entry_insertbackground', 'Yellow'), |
| 46 | ('entry_insertbackground', 'Black'), |
| 47 | ('entry_insertborderwidth', 1), |
| 48 | ('entry_insertborderwidth', 0), |
| 49 | ('entry_insertofftime', 400), |
| 50 | ('entry_insertontime', 700), |
| 51 | ('entry_insertwidth', 3), |
| 52 | ('entryfield_invalidcommand', Test.callback), |
| 53 | ('entry_show', '*'), |
| 54 | ('entry_background', 'red'), |
| 55 | (c.setentry, '69', Pmw.OK), |
| 56 | ('entry_show', ''), |
| 57 | ('entry_justify', 'right'), |
| 58 | ('entry_justify', 'center'), |
| 59 | ('entry_justify', 'left'), |
| 60 | ('label_text', 'Label'), |
| 61 | ('entry_relief', 'raised'), |
| 62 | ('entry_relief', 'sunken'), |
| 63 | ('entry_state', 'disabled'), |
| 64 | ('entry_state', 'normal'), |
| 65 | ('entry_background', 'GhostWhite'), |
| 66 | ('entryfield_validate', 'alphabetic'), |
| 67 | ('entryfield_validate', 'numeric'), |
| 68 | ('entry_width', 30), |
| 69 | ('relief', 'bogus', 'KeyError: Unknown option "relief" for Counter'), |
| 70 | (c.invoke, (), 1), |
| 71 | (c.interior, (), Tkinter.Frame), |
| 72 | (c.increment, ()), |
| 73 | (c.get, (), '70'), |
| 74 | ('increment', 5), |
| 75 | (c.get, (), '70'), |
| 76 | (c.decrement, ()), |
| 77 | (c.get, (), '65'), |
| 78 | (c.insert, ('end', 2)), |
| 79 | (c.get, (), '652'), |
| 80 | (c.invoke, (), 1), |
| 81 | (c.clear, ()), |
| 82 | (c.get, (), ''), |
| 83 | (c.insert, ('end', 'Test String')), |
| 84 | (c.get, (), 'Test String'), |
| 85 | (c.delete, (0, 'end')), |
| 86 | (c.insert, ('end', 'Another Test')), |
| 87 | (c.icursor, 'end'), |
| 88 | (c.index, 'end', 12), |
| 89 | (c.selection_from, 0), |
| 90 | (c.selection_to, 'end'), |
| 91 | (c.xview, '3'), |
| 92 | (c.clear, ()), |
| 93 | (c.insert, ('end', '100')), |
| 94 | ('entryfield_validate', {'validator' : 'real', 'min' : 10}), |
| 95 | (c.setentry, '50', Pmw.OK), |
| 96 | (c.setentry, 'hello', Pmw.ERROR), |
| 97 | ('entryfield_extravalidators', _myValidators), |
| 98 | ('entryfield_validate', 'hello'), |
| 99 | (c.setentry, 'hello', Pmw.OK), |
| 100 | (c.setentry, 'foo', Pmw.ERROR), |
| 101 | (c.valid, (), 1), |
| 102 | (c.cget, 'entry_background', 'GhostWhite'), |
| 103 | ('entry_textvariable', Test.stringvar), |
| 104 | (c.checkentry, (), 0), |
| 105 | (c.cget, 'entry_background', 'red'), |
| 106 | ('entryfield_validate', {'validator' : 'date', 'format' : 'dmy'}), |
| 107 | (c.valid, (), 0), |
| 108 | ('datatype', {'counter' : 'date', 'format' : 'dmy', 'yyyy' : 1}), |
| 109 | (c.setentry, '22/12/1999', Pmw.OK), |
| 110 | ('increment', 10), |
| 111 | (c.increment, ()), |
| 112 | (c.get, (), '01/01/2000'), |
| 113 | |
| 114 | ('entryfield_validate', {'validator' : 'time', 'min' : '10:00:00'}), |
| 115 | (c.valid, (), 0), |
| 116 | ('increment', 60*60), |
| 117 | ('datatype', {'counter' : 'time'}), |
| 118 | (c.setentry, '11:00:00', Pmw.OK), |
| 119 | (c.decrement, ()), |
| 120 | (c.get, (), '10:00:00'), |
| 121 | (c.decrement, ()), |
| 122 | (c.get, (), '10:00:00'), |
| 123 | |
| 124 | ('entryfield_validate', {'validator' : 'time', 'separator' : '.'}), |
| 125 | (c.valid, (), 0), |
| 126 | ('datatype', {'counter' : 'time', 'separator' : '.'}), |
| 127 | (c.setentry, '11.00.00', Pmw.OK), |
| 128 | (c.decrement, ()), |
| 129 | (c.get, (), '10.00.00'), |
| 130 | |
| 131 | ('entryfield_validate', {'validator' : 'date', 'format' : 'dmy'}), |
| 132 | (c.valid, (), 0), |
| 133 | ('increment', 1), |
| 134 | ('datatype', {'counter' : 'date', 'format' : 'dmy'}), |
| 135 | (c.setentry, '25/12/99', Pmw.OK), |
| 136 | (c.decrement, ()), |
| 137 | (c.get, (), '24/12/99'), |
| 138 | |
| 139 | ('entryfield_validate', {'validator' : 'date', 'separator' : '#@!', |
| 140 | 'max' : '99#@!12#@!26'}), |
| 141 | (c.valid, (), 0), |
| 142 | ('datatype', {'counter' : 'date', 'separator' : '#@!'}), |
| 143 | (c.setentry, '99#@!12#@!25', Pmw.OK), |
| 144 | (c.increment, ()), |
| 145 | (c.get, (), '99#@!12#@!26'), |
| 146 | ('increment', 10), |
| 147 | (c.increment, ()), |
| 148 | (c.get, (), '99#@!12#@!26'), # max exceeded |
| 149 | ('entryfield_validate', {'validator' : 'date', 'separator' : '#@!', |
| 150 | 'max' : '00#@!01#@!10'}), |
| 151 | (c.increment, ()), |
| 152 | (c.get, (), '00#@!01#@!05'), # max not exceeded |
| 153 | ('increment', 1), |
| 154 | |
| 155 | ('entryfield_validate', {'validator' : 'date', 'format' : 'ymd', |
| 156 | 'separator' : '-' }), |
| 157 | (c.valid, (), 0), |
| 158 | ('datatype', {'counter' : 'date', 'format' : 'ymd', 'yyyy' : 1, |
| 159 | 'separator' : '-' }), |
| 160 | (c.setentry, '1999-12-22', 1), |
| 161 | ('increment', 10), |
| 162 | (c.increment, ()), |
| 163 | (c.get, (), '2000-01-01'), |
| 164 | ('increment', 1), |
| 165 | ) |
| 166 | |
| 167 | tests_2 = ( |
| 168 | (c.pack, (), {'padx' : 10, 'pady' : 10}), |
| 169 | ) |
| 170 | |
| 171 | alltests = [(tests_1, kw_1)] |
| 172 | |
| 173 | poslist = ('nw', 'n', 'ne', 'en', 'e', 'es', 'se', 's', 'sw', 'ws', 'w', 'wn',) |
| 174 | for count in range(len(poslist)): |
| 175 | pos = poslist[count] |
| 176 | margin = count * 10 |
| 177 | kw_2 = { |
| 178 | 'entry_width' : 12, |
| 179 | 'labelpos' : pos, |
| 180 | 'labelmargin' : margin, |
| 181 | 'label_text' : 'Counter:', |
| 182 | } |
| 183 | alltests.append((tests_2, kw_2)) |
| 184 | |
| 185 | testData = ((c, alltests),) |
| 186 | |
| 187 | if __name__ == '__main__': |
| 188 | Test.runTests(testData) |