0001 # 0002 # Test script for the curses module 0003 # 0004 # This script doesn't actually display anything very coherent. but it 0005 # does call every method and function. 0006 # 0007 # Functions not tested: {def,reset}_{shell,prog}_mode, getch(), getstr(), 0008 # getmouse(), ungetmouse(), init_color() 0009 # 0010 0011 import curses, sys, tempfile 0012 0013 # Optionally test curses module. This currently requires that the 0014 # 'curses' resource be given on the regrtest command line using the -u 0015 # option. If not available, nothing after this line will be executed. 0016 0017 from test import test_support 0018 test_support.requires('curses') 0019 0020 def window_funcs(stdscr): 0021 "Test the methods of windows" 0022 win = curses.newwin(10,10) 0023 win = curses.newwin(5,5, 5,5) 0024 win2 = curses.newwin(15,15, 5,5) 0025 0026 for meth in [stdscr.addch, stdscr.addstr]: 0027 for args in [('a'), ('a', curses.A_BOLD), 0028 (4,4, 'a'), (5,5, 'a', curses.A_BOLD)]: 0029 meth(*args) 0030 0031 for meth in [stdscr.box, stdscr.clear, stdscr.clrtobot, 0032 stdscr.clrtoeol, stdscr.cursyncup, stdscr.delch, 0033 stdscr.deleteln, stdscr.erase, stdscr.getbegyx, 0034 stdscr.getbkgd, stdscr.getkey, stdscr.getmaxyx, 0035 stdscr.getparyx, stdscr.getyx, stdscr.inch, 0036 stdscr.insertln, stdscr.instr, stdscr.is_wintouched, 0037 win.noutrefresh, stdscr.redrawwin, stdscr.refresh, 0038 stdscr.standout, stdscr.standend, stdscr.syncdown, 0039 stdscr.syncup, stdscr.touchwin, stdscr.untouchwin]: 0040 meth() 0041 0042 stdscr.addnstr('1234', 3) 0043 stdscr.addnstr('1234', 3, curses.A_BOLD) 0044 stdscr.addnstr(4,4, '1234', 3) 0045 stdscr.addnstr(5,5, '1234', 3, curses.A_BOLD) 0046 0047 stdscr.attron(curses.A_BOLD) 0048 stdscr.attroff(curses.A_BOLD) 0049 stdscr.attrset(curses.A_BOLD) 0050 stdscr.bkgd(' ') 0051 stdscr.bkgd(' ', curses.A_REVERSE) 0052 stdscr.bkgdset(' ') 0053 stdscr.bkgdset(' ', curses.A_REVERSE) 0054 0055 win.border(65, 66, 67, 68, 0056 69, 70, 71, 72) 0057 win.border('|', '!', '-', '_', 0058 '+', '\\', '#', '/') 0059 try: 0060 win.border(65, 66, 67, 68, 0061 69, [], 71, 72) 0062 except TypeError: 0063 pass 0064 else: 0065 raise RuntimeError, "Expected win.border() to raise TypeError" 0066 0067 stdscr.clearok(1) 0068 0069 win4 = stdscr.derwin(2,2) 0070 win4 = stdscr.derwin(1,1, 5,5) 0071 win4.mvderwin(9,9) 0072 0073 stdscr.echochar('a') 0074 stdscr.echochar('a', curses.A_BOLD) 0075 stdscr.hline('-', 5) 0076 stdscr.hline('-', 5, curses.A_BOLD) 0077 stdscr.hline(1,1,'-', 5) 0078 stdscr.hline(1,1,'-', 5, curses.A_BOLD) 0079 0080 stdscr.idcok(1) 0081 stdscr.idlok(1) 0082 stdscr.immedok(1) 0083 stdscr.insch('c') 0084 stdscr.insdelln(1) 0085 stdscr.insnstr('abc', 3) 0086 stdscr.insnstr('abc', 3, curses.A_BOLD) 0087 stdscr.insnstr(5, 5, 'abc', 3) 0088 stdscr.insnstr(5, 5, 'abc', 3, curses.A_BOLD) 0089 0090 stdscr.insstr('def') 0091 stdscr.insstr('def', curses.A_BOLD) 0092 stdscr.insstr(5, 5, 'def') 0093 stdscr.insstr(5, 5, 'def', curses.A_BOLD) 0094 stdscr.is_linetouched(0) 0095 stdscr.keypad(1) 0096 stdscr.leaveok(1) 0097 stdscr.move(3,3) 0098 win.mvwin(2,2) 0099 stdscr.nodelay(1) 0100 stdscr.notimeout(1) 0101 win2.overlay(win) 0102 win2.overwrite(win) 0103 stdscr.redrawln(1,2) 0104 0105 stdscr.scrollok(1) 0106 stdscr.scroll() 0107 stdscr.scroll(2) 0108 stdscr.scroll(-3) 0109 0110 stdscr.setscrreg(10,15) 0111 win3 = stdscr.subwin(10,10) 0112 win3 = stdscr.subwin(10,10, 5,5) 0113 stdscr.syncok(1) 0114 stdscr.timeout(5) 0115 stdscr.touchline(5,5) 0116 stdscr.touchline(5,5,0) 0117 stdscr.vline('a', 3) 0118 stdscr.vline('a', 3, curses.A_STANDOUT) 0119 stdscr.vline(1,1, 'a', 3) 0120 stdscr.vline(1,1, 'a', 3, curses.A_STANDOUT) 0121 0122 if hasattr(curses, 'resize'): 0123 stdscr.resize() 0124 if hasattr(curses, 'enclose'): 0125 stdscr.enclose() 0126 0127 0128 def module_funcs(stdscr): 0129 "Test module-level functions" 0130 0131 for func in [curses.baudrate, curses.beep, curses.can_change_color, 0132 curses.cbreak, curses.def_prog_mode, curses.doupdate, 0133 curses.filter, curses.flash, curses.flushinp, 0134 curses.has_colors, curses.has_ic, curses.has_il, 0135 curses.isendwin, curses.killchar, curses.longname, 0136 curses.nocbreak, curses.noecho, curses.nonl, 0137 curses.noqiflush, curses.noraw, 0138 curses.reset_prog_mode, curses.termattrs, 0139 curses.termname, curses.erasechar, curses.getsyx]: 0140 func() 0141 0142 # Functions that actually need arguments 0143 if curses.tigetstr("cnorm"): 0144 curses.curs_set(1) 0145 curses.delay_output(1) 0146 curses.echo() ; curses.echo(1) 0147 0148 f = tempfile.TemporaryFile() 0149 stdscr.putwin(f) 0150 f.seek(0) 0151 curses.getwin(f) 0152 f.close() 0153 0154 curses.halfdelay(1) 0155 curses.intrflush(1) 0156 curses.meta(1) 0157 curses.napms(100) 0158 curses.newpad(50,50) 0159 win = curses.newwin(5,5) 0160 win = curses.newwin(5,5, 1,1) 0161 curses.nl() ; curses.nl(1) 0162 curses.putp('abc') 0163 curses.qiflush() 0164 curses.raw() ; curses.raw(1) 0165 curses.setsyx(5,5) 0166 curses.setupterm(fd=sys.__stdout__.fileno()) 0167 curses.tigetflag('hc') 0168 curses.tigetnum('co') 0169 curses.tigetstr('cr') 0170 curses.tparm('cr') 0171 curses.typeahead(sys.__stdin__.fileno()) 0172 curses.unctrl('a') 0173 curses.ungetch('a') 0174 curses.use_env(1) 0175 0176 # Functions only available on a few platforms 0177 if curses.has_colors(): 0178 curses.start_color() 0179 curses.init_pair(2, 1,1) 0180 curses.color_content(1) 0181 curses.color_pair(2) 0182 curses.pair_content(curses.COLOR_PAIRS) 0183 curses.pair_number(0) 0184 0185 if hasattr(curses, 'use_default_colors'): 0186 curses.use_default_colors() 0187 0188 if hasattr(curses, 'keyname'): 0189 curses.keyname(13) 0190 0191 if hasattr(curses, 'has_key'): 0192 curses.has_key(13) 0193 0194 if hasattr(curses, 'getmouse'): 0195 curses.mousemask(curses.BUTTON1_PRESSED) 0196 curses.mouseinterval(10) 0197 0198 def unit_tests(): 0199 from curses import ascii 0200 for ch, expected in [('a', 'a'), ('A', 'A'), 0201 (';', ';'), (' ', ' '), 0202 ('\x7f', '^?'), ('\n', '^J'), ('\0', '^@'), 0203 # Meta-bit characters 0204 ('\x8a', '!^J'), ('\xc1', '!A'), 0205 ]: 0206 if ascii.unctrl(ch) != expected: 0207 print 'curses.unctrl fails on character', repr(ch) 0208 0209 0210 0211 def main(stdscr): 0212 curses.savetty() 0213 try: 0214 module_funcs(stdscr) 0215 window_funcs(stdscr) 0216 finally: 0217 curses.resetty() 0218 0219 0220 if __name__ == '__main__': 0221 curses.wrapper(main) 0222 unit_tests() 0223 else: 0224 try: 0225 stdscr = curses.initscr() 0226 main(stdscr) 0227 finally: 0228 curses.endwin() 0229 0230 unit_tests() 0231
Generated by PyXR 0.9.4