# Test script for the curses module
# This script doesn't actually display anything very coherent. but it
# does call every method and function.
# Functions not tested: {def,reset}_{shell,prog}_mode, getch(), getstr(),
# getmouse(), ungetmouse(), init_color()
import curses
, sys
, tempfile
# Optionally test curses module. This currently requires that the
# 'curses' resource be given on the regrtest command line using the -u
# option. If not available, nothing after this line will be executed.
from test
import test_support
test_support
.requires('curses')
def window_funcs(stdscr
):
"Test the methods of windows"
win
= curses
.newwin(10,10)
win
= curses
.newwin(5,5, 5,5)
win2
= curses
.newwin(15,15, 5,5)
for meth
in [stdscr
.addch
, stdscr
.addstr
]:
for args
in [('a'), ('a', curses
.A_BOLD
),
(4,4, 'a'), (5,5, 'a', curses
.A_BOLD
)]:
for meth
in [stdscr
.box
, stdscr
.clear
, stdscr
.clrtobot
,
stdscr
.clrtoeol
, stdscr
.cursyncup
, stdscr
.delch
,
stdscr
.deleteln
, stdscr
.erase
, stdscr
.getbegyx
,
stdscr
.getbkgd
, stdscr
.getkey
, stdscr
.getmaxyx
,
stdscr
.getparyx
, stdscr
.getyx
, stdscr
.inch
,
stdscr
.insertln
, stdscr
.instr
, stdscr
.is_wintouched
,
win
.noutrefresh
, stdscr
.redrawwin
, stdscr
.refresh
,
stdscr
.standout
, stdscr
.standend
, stdscr
.syncdown
,
stdscr
.syncup
, stdscr
.touchwin
, stdscr
.untouchwin
]:
stdscr
.addnstr('1234', 3)
stdscr
.addnstr('1234', 3, curses
.A_BOLD
)
stdscr
.addnstr(4,4, '1234', 3)
stdscr
.addnstr(5,5, '1234', 3, curses
.A_BOLD
)
stdscr
.attron(curses
.A_BOLD
)
stdscr
.attroff(curses
.A_BOLD
)
stdscr
.attrset(curses
.A_BOLD
)
stdscr
.bkgd(' ', curses
.A_REVERSE
)
stdscr
.bkgdset(' ', curses
.A_REVERSE
)
win
.border(65, 66, 67, 68,
win
.border('|', '!', '-', '_',
win
.border(65, 66, 67, 68,
raise RuntimeError, "Expected win.border() to raise TypeError"
win4
= stdscr
.derwin(2,2)
win4
= stdscr
.derwin(1,1, 5,5)
stdscr
.echochar('a', curses
.A_BOLD
)
stdscr
.hline('-', 5, curses
.A_BOLD
)
stdscr
.hline(1,1,'-', 5, curses
.A_BOLD
)
stdscr
.insnstr('abc', 3, curses
.A_BOLD
)
stdscr
.insnstr(5, 5, 'abc', 3)
stdscr
.insnstr(5, 5, 'abc', 3, curses
.A_BOLD
)
stdscr
.insstr('def', curses
.A_BOLD
)
stdscr
.insstr(5, 5, 'def')
stdscr
.insstr(5, 5, 'def', curses
.A_BOLD
)
win3
= stdscr
.subwin(10,10)
win3
= stdscr
.subwin(10,10, 5,5)
stdscr
.vline('a', 3, curses
.A_STANDOUT
)
stdscr
.vline(1,1, 'a', 3)
stdscr
.vline(1,1, 'a', 3, curses
.A_STANDOUT
)
if hasattr(curses
, 'resize'):
if hasattr(curses
, 'enclose'):
def module_funcs(stdscr
):
"Test module-level functions"
for func
in [curses
.baudrate
, curses
.beep
, curses
.can_change_color
,
curses
.cbreak
, curses
.def_prog_mode
, curses
.doupdate
,
curses
.filter, curses
.flash
, curses
.flushinp
,
curses
.has_colors
, curses
.has_ic
, curses
.has_il
,
curses
.isendwin
, curses
.killchar
, curses
.longname
,
curses
.nocbreak
, curses
.noecho
, curses
.nonl
,
curses
.noqiflush
, curses
.noraw
,
curses
.reset_prog_mode
, curses
.termattrs
,
curses
.termname
, curses
.erasechar
, curses
.getsyx
]:
# Functions that actually need arguments
if curses
.tigetstr("cnorm"):
curses
.echo() ; curses
.echo(1)
f
= tempfile
.TemporaryFile()
win
= curses
.newwin(5,5, 1,1)
curses
.nl() ; curses
.nl(1)
curses
.raw() ; curses
.raw(1)
curses
.setupterm(fd
=sys
.__stdout
__.fileno())
curses
.typeahead(sys
.__stdin
__.fileno())
# Functions only available on a few platforms
curses
.pair_content(curses
.COLOR_PAIRS
- 1)
if hasattr(curses
, 'use_default_colors'):
curses
.use_default_colors()
if hasattr(curses
, 'keyname'):
if hasattr(curses
, 'has_key'):
if hasattr(curses
, 'getmouse'):
curses
.mousemask(curses
.BUTTON1_PRESSED
)
for ch
, expected
in [('a', 'a'), ('A', 'A'),
('\x7f', '^?'), ('\n', '^J'), ('\0', '^@'),
('\x8a', '!^J'), ('\xc1', '!A'),
if ascii
.unctrl(ch
) != expected
:
print 'curses.unctrl fails on character', repr(ch
)
if __name__
== '__main__':
stdscr
= curses
.initscr()