1# Based on iwidgets2.2.0/tests/entryfield.test code. 2 3import tkinter 4import Test 5import Pmw 6 7Test.initialise() 8 9_myValidators = { 10 'hello' : (lambda s: s == 'hello', len), 11} 12 13c = Pmw.EntryField 14 15kw_1 = {'entry_width' : 12, 'labelpos' : 'n', 'label_text' : 'Entry Field:'} 16tests_1 = ( 17 (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}), 18 (Test.num_options, (), 10), 19 ('errorbackground', 'red'), 20 ('hull_background', 'yellow'), 21 ('label_background', 'yellow'), 22 ('entry_background', 'yellow'), 23 ('hull_show', 'X', 'TclError: unknown option "-show"'), 24 ('entry_show', ''), 25 ('entry_borderwidth', 4), 26 ('entry_borderwidth', 2), 27 ('command', Test.callback), 28 ('hull_cursor', 'gumby'), 29 ('entry_exportselection', 0), 30 ('label_foreground', 'Green'), 31 ('entry_foreground', 'Green'), 32 ('label_foreground', 'Black'), 33 ('entry_foreground', 'Black'), 34 ('label_highlightcolor', 'Red'), 35 ('entry_highlightcolor', 'Red'), 36 ('entry_highlightthickness', 2), 37 ('entry_insertbackground', 'Yellow'), 38 ('entry_insertbackground', 'Black'), 39 ('entry_insertborderwidth', 1), 40 ('entry_insertborderwidth', 0), 41 ('entry_insertofftime', 400), 42 ('entry_insertontime', 700), 43 ('entry_insertwidth', 3), 44 ('invalidcommand', Test.callback), 45 ('entry_justify', 'right'), 46 ('entry_justify', 'center'), 47 ('entry_justify', 'left'), 48 ('label_text', 'Label'), 49 ('entry_relief', 'raised'), 50 ('entry_relief', 'sunken'), 51 ('entry_state', 'disabled'), 52 ('entry_state', 'normal'), 53 ('entry_background', 'GhostWhite'), 54 ('validate', 'numeric'), 55 ('validate', 'alphabetic'), 56 ('entry_width', 30), 57 ('validate', 'bogus', 58 "ValueError: bad validate value \"bogus\": must be a function or one " + 59 "of the standard validators ('alphabetic', 'alphanumeric', 'date', " + 60 "'hexadecimal', 'integer', 'numeric', 'real', 'time') or extra " + 61 "validators ()"), 62 ('relief', 'bogus', 'KeyError: Unknown option "relief" for EntryField'), 63 (c.invoke, (), 1), 64 (c.interior, (), tkinter.Frame), 65 (c.clear, ()), 66 (c.get, (), ''), 67 (c.insert, ('end', 'Test String')), 68 (c.get, (), 'Test String'), 69 (c.delete, (0, 'end')), 70 (c.insert, ('end', 'Another Test')), 71 (c.icursor, 'end'), 72 (c.index, 'end', 12), 73 (c.selection_from, 0), 74 (c.selection_to, 'end'), 75 (c.xview, '3'), 76 (c.clear, ()), 77 (c.insert, ('end', '100')), 78 ('validate', {'validator' : 'real', 'min' : 10}), 79 (c.setentry, '50', 1), 80 (c.setentry, 'hello', 0), 81 ('extravalidators', _myValidators), 82 ('validate', 'hello'), 83 (c.setentry, 'hello', 1), 84 (c.setentry, 'foo', 0), 85 (c.valid, (), 1), 86 (c.cget, 'entry_background', 'GhostWhite'), 87 ('entry_textvariable', Test.stringvar), 88 (c.checkentry, (), 0), 89 (c.cget, 'entry_background', 'red'), 90) 91 92tests_2 = ( 93 (c.pack, (), {'padx' : 10, 'pady' : 10}), 94) 95 96alltests = [(tests_1, kw_1)] 97 98poslist = ('nw', 'n', 'ne', 'en', 'e', 'es', 'se', 's', 'sw', 'ws', 'w', 'wn',) 99for pos in poslist: 100 kw_2 = { 101 'labelpos' : pos, 102 'label_text' : 'Entry Field', 103 } 104 alltests.append((tests_2, kw_2)) 105 106testData = ((c, alltests),) 107 108if __name__ == '__main__': 109 Test.runTests(testData) 110