Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
baf45c59
Kaydet (Commit)
baf45c59
authored
Eki 17, 2014
tarafından
Zachary Ware
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16000: Convert test_curses to use unittest
üst
16c41ab4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
349 additions
and
367 deletions
+349
-367
test_curses.py
Lib/test/test_curses.py
+347
-367
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_curses.py
Dosyayı görüntüle @
baf45c59
...
@@ -2,21 +2,23 @@
...
@@ -2,21 +2,23 @@
# Test script for the curses module
# Test script for the curses module
#
#
# This script doesn't actually display anything very coherent. but it
# This script doesn't actually display anything very coherent. but it
# does call every method and function.
# does call
(nearly)
every method and function.
#
#
# Functions not tested: {def,reset}_{shell,prog}_mode, getch(), getstr(),
# Functions not tested: {def,reset}_{shell,prog}_mode, getch(), getstr(),
# init_color()
# init_color()
# Only called, not tested: getmouse(), ungetmouse()
# Only called, not tested: getmouse(), ungetmouse()
#
#
import
sys
,
tempfile
,
os
import
os
import
sys
import
tempfile
import
unittest
from
test.support
import
requires
,
import_module
,
verbose
# Optionally test curses module. This currently requires that the
# Optionally test curses module. This currently requires that the
# 'curses' resource be given on the regrtest command line using the -u
# 'curses' resource be given on the regrtest command line using the -u
# option. If not available, nothing after this line will be executed.
# option. If not available, nothing after this line will be executed.
import
unittest
from
test.support
import
requires
,
import_module
import
inspect
import
inspect
requires
(
'curses'
)
requires
(
'curses'
)
...
@@ -24,372 +26,350 @@ requires('curses')
...
@@ -24,372 +26,350 @@ requires('curses')
curses
=
import_module
(
'curses'
)
curses
=
import_module
(
'curses'
)
curses
.
panel
=
import_module
(
'curses.panel'
)
curses
.
panel
=
import_module
(
'curses.panel'
)
term
=
os
.
environ
.
get
(
'TERM'
,
'unknown'
)
@unittest.skipUnless
(
sys
.
__stdout__
.
isatty
(),
'sys.__stdout__ is not a tty'
)
@unittest.skipIf
(
term
==
'unknown'
,
"$TERM=
%
r, calling initscr() may cause exit"
%
term
)
@unittest.skipIf
(
sys
.
platform
==
"cygwin"
,
"cygwin's curses mostly just hangs"
)
class
TestCurses
(
unittest
.
TestCase
):
@classmethod
def
setUpClass
(
cls
):
curses
.
setupterm
(
fd
=
sys
.
__stdout__
.
fileno
())
def
setUp
(
self
):
if
verbose
:
# just to make the test output a little more readable
print
()
self
.
stdscr
=
curses
.
initscr
()
curses
.
savetty
()
def
tearDown
(
self
):
curses
.
resetty
()
curses
.
endwin
()
def
test_window_funcs
(
self
):
"Test the methods of windows"
stdscr
=
self
.
stdscr
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
)]:
meth
(
*
args
)
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
]:
meth
()
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
(
' '
)
stdscr
.
bkgd
(
' '
,
curses
.
A_REVERSE
)
stdscr
.
bkgdset
(
' '
)
stdscr
.
bkgdset
(
' '
,
curses
.
A_REVERSE
)
# XXX: if newterm was supported we could use it instead of initscr and not exit
term
=
os
.
environ
.
get
(
'TERM'
)
if
not
term
or
term
==
'unknown'
:
raise
unittest
.
SkipTest
(
"$TERM=
%
r, calling initscr() may cause exit"
%
term
)
if
sys
.
platform
==
"cygwin"
:
raise
unittest
.
SkipTest
(
"cygwin's curses mostly just hangs"
)
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
)]:
meth
(
*
args
)
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
]:
meth
()
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
(
' '
)
stdscr
.
bkgd
(
' '
,
curses
.
A_REVERSE
)
stdscr
.
bkgdset
(
' '
)
stdscr
.
bkgdset
(
' '
,
curses
.
A_REVERSE
)
win
.
border
(
65
,
66
,
67
,
68
,
69
,
70
,
71
,
72
)
win
.
border
(
'|'
,
'!'
,
'-'
,
'_'
,
'+'
,
'
\\
'
,
'#'
,
'/'
)
try
:
win
.
border
(
65
,
66
,
67
,
68
,
win
.
border
(
65
,
66
,
67
,
68
,
69
,
[],
71
,
72
)
69
,
70
,
71
,
72
)
except
TypeError
:
win
.
border
(
'|'
,
'!'
,
'-'
,
'_'
,
pass
'+'
,
'
\\
'
,
'#'
,
'/'
)
else
:
with
self
.
assertRaises
(
TypeError
,
raise
RuntimeError
(
"Expected win.border() to raise TypeError"
)
msg
=
"Expected win.border() to raise TypeError"
):
win
.
border
(
65
,
66
,
67
,
68
,
stdscr
.
clearok
(
1
)
69
,
[],
71
,
72
)
win4
=
stdscr
.
derwin
(
2
,
2
)
stdscr
.
clearok
(
1
)
win4
=
stdscr
.
derwin
(
1
,
1
,
5
,
5
)
win4
.
mvderwin
(
9
,
9
)
win4
=
stdscr
.
derwin
(
2
,
2
)
win4
=
stdscr
.
derwin
(
1
,
1
,
5
,
5
)
stdscr
.
echochar
(
'a'
)
win4
.
mvderwin
(
9
,
9
)
stdscr
.
echochar
(
'a'
,
curses
.
A_BOLD
)
stdscr
.
hline
(
'-'
,
5
)
stdscr
.
echochar
(
'a'
)
stdscr
.
hline
(
'-'
,
5
,
curses
.
A_BOLD
)
stdscr
.
echochar
(
'a'
,
curses
.
A_BOLD
)
stdscr
.
hline
(
1
,
1
,
'-'
,
5
)
stdscr
.
hline
(
'-'
,
5
)
stdscr
.
hline
(
1
,
1
,
'-'
,
5
,
curses
.
A_BOLD
)
stdscr
.
hline
(
'-'
,
5
,
curses
.
A_BOLD
)
stdscr
.
hline
(
1
,
1
,
'-'
,
5
)
stdscr
.
idcok
(
1
)
stdscr
.
hline
(
1
,
1
,
'-'
,
5
,
curses
.
A_BOLD
)
stdscr
.
idlok
(
1
)
stdscr
.
immedok
(
1
)
stdscr
.
idcok
(
1
)
stdscr
.
insch
(
'c'
)
stdscr
.
idlok
(
1
)
stdscr
.
insdelln
(
1
)
stdscr
.
immedok
(
1
)
stdscr
.
insnstr
(
'abc'
,
3
)
stdscr
.
insch
(
'c'
)
stdscr
.
insnstr
(
'abc'
,
3
,
curses
.
A_BOLD
)
stdscr
.
insdelln
(
1
)
stdscr
.
insnstr
(
5
,
5
,
'abc'
,
3
)
stdscr
.
insnstr
(
'abc'
,
3
)
stdscr
.
insnstr
(
5
,
5
,
'abc'
,
3
,
curses
.
A_BOLD
)
stdscr
.
insnstr
(
'abc'
,
3
,
curses
.
A_BOLD
)
stdscr
.
insnstr
(
5
,
5
,
'abc'
,
3
)
stdscr
.
insstr
(
'def'
)
stdscr
.
insnstr
(
5
,
5
,
'abc'
,
3
,
curses
.
A_BOLD
)
stdscr
.
insstr
(
'def'
,
curses
.
A_BOLD
)
stdscr
.
insstr
(
5
,
5
,
'def'
)
stdscr
.
insstr
(
'def'
)
stdscr
.
insstr
(
5
,
5
,
'def'
,
curses
.
A_BOLD
)
stdscr
.
insstr
(
'def'
,
curses
.
A_BOLD
)
stdscr
.
is_linetouched
(
0
)
stdscr
.
insstr
(
5
,
5
,
'def'
)
stdscr
.
keypad
(
1
)
stdscr
.
insstr
(
5
,
5
,
'def'
,
curses
.
A_BOLD
)
stdscr
.
leaveok
(
1
)
stdscr
.
is_linetouched
(
0
)
stdscr
.
move
(
3
,
3
)
stdscr
.
keypad
(
1
)
win
.
mvwin
(
2
,
2
)
stdscr
.
leaveok
(
1
)
stdscr
.
nodelay
(
1
)
stdscr
.
move
(
3
,
3
)
stdscr
.
notimeout
(
1
)
win
.
mvwin
(
2
,
2
)
win2
.
overlay
(
win
)
stdscr
.
nodelay
(
1
)
win2
.
overwrite
(
win
)
stdscr
.
notimeout
(
1
)
win2
.
overlay
(
win
,
1
,
2
,
2
,
1
,
3
,
3
)
win2
.
overlay
(
win
)
win2
.
overwrite
(
win
,
1
,
2
,
2
,
1
,
3
,
3
)
win2
.
overwrite
(
win
)
stdscr
.
redrawln
(
1
,
2
)
win2
.
overlay
(
win
,
1
,
2
,
2
,
1
,
3
,
3
)
win2
.
overwrite
(
win
,
1
,
2
,
2
,
1
,
3
,
3
)
stdscr
.
scrollok
(
1
)
stdscr
.
redrawln
(
1
,
2
)
stdscr
.
scroll
()
stdscr
.
scroll
(
2
)
stdscr
.
scrollok
(
1
)
stdscr
.
scroll
(
-
3
)
stdscr
.
scroll
()
stdscr
.
scroll
(
2
)
stdscr
.
move
(
12
,
2
)
stdscr
.
scroll
(
-
3
)
stdscr
.
setscrreg
(
10
,
15
)
win3
=
stdscr
.
subwin
(
10
,
10
)
stdscr
.
move
(
12
,
2
)
win3
=
stdscr
.
subwin
(
10
,
10
,
5
,
5
)
stdscr
.
setscrreg
(
10
,
15
)
stdscr
.
syncok
(
1
)
win3
=
stdscr
.
subwin
(
10
,
10
)
stdscr
.
timeout
(
5
)
win3
=
stdscr
.
subwin
(
10
,
10
,
5
,
5
)
stdscr
.
touchline
(
5
,
5
)
stdscr
.
syncok
(
1
)
stdscr
.
touchline
(
5
,
5
,
0
)
stdscr
.
timeout
(
5
)
stdscr
.
vline
(
'a'
,
3
)
stdscr
.
touchline
(
5
,
5
)
stdscr
.
vline
(
'a'
,
3
,
curses
.
A_STANDOUT
)
stdscr
.
touchline
(
5
,
5
,
0
)
stdscr
.
chgat
(
5
,
2
,
3
,
curses
.
A_BLINK
)
stdscr
.
vline
(
'a'
,
3
)
stdscr
.
chgat
(
3
,
curses
.
A_BOLD
)
stdscr
.
vline
(
'a'
,
3
,
curses
.
A_STANDOUT
)
stdscr
.
chgat
(
5
,
8
,
curses
.
A_UNDERLINE
)
stdscr
.
chgat
(
5
,
2
,
3
,
curses
.
A_BLINK
)
stdscr
.
chgat
(
curses
.
A_BLINK
)
stdscr
.
chgat
(
3
,
curses
.
A_BOLD
)
stdscr
.
refresh
()
stdscr
.
chgat
(
5
,
8
,
curses
.
A_UNDERLINE
)
stdscr
.
chgat
(
curses
.
A_BLINK
)
stdscr
.
vline
(
1
,
1
,
'a'
,
3
)
stdscr
.
refresh
()
stdscr
.
vline
(
1
,
1
,
'a'
,
3
,
curses
.
A_STANDOUT
)
stdscr
.
vline
(
1
,
1
,
'a'
,
3
)
if
hasattr
(
curses
,
'resize'
):
stdscr
.
vline
(
1
,
1
,
'a'
,
3
,
curses
.
A_STANDOUT
)
stdscr
.
resize
()
if
hasattr
(
curses
,
'enclose'
):
if
hasattr
(
curses
,
'resize'
):
stdscr
.
enclose
()
stdscr
.
resize
()
if
hasattr
(
curses
,
'enclose'
):
stdscr
.
enclose
()
def
module_funcs
(
stdscr
):
"Test module-level functions"
def
test_module_funcs
(
self
):
for
func
in
[
curses
.
baudrate
,
curses
.
beep
,
curses
.
can_change_color
,
"Test module-level functions"
curses
.
cbreak
,
curses
.
def_prog_mode
,
curses
.
doupdate
,
stdscr
=
self
.
stdscr
curses
.
filter
,
curses
.
flash
,
curses
.
flushinp
,
for
func
in
[
curses
.
baudrate
,
curses
.
beep
,
curses
.
can_change_color
,
curses
.
has_colors
,
curses
.
has_ic
,
curses
.
has_il
,
curses
.
cbreak
,
curses
.
def_prog_mode
,
curses
.
doupdate
,
curses
.
isendwin
,
curses
.
killchar
,
curses
.
longname
,
curses
.
filter
,
curses
.
flash
,
curses
.
flushinp
,
curses
.
nocbreak
,
curses
.
noecho
,
curses
.
nonl
,
curses
.
has_colors
,
curses
.
has_ic
,
curses
.
has_il
,
curses
.
noqiflush
,
curses
.
noraw
,
curses
.
isendwin
,
curses
.
killchar
,
curses
.
longname
,
curses
.
reset_prog_mode
,
curses
.
termattrs
,
curses
.
nocbreak
,
curses
.
noecho
,
curses
.
nonl
,
curses
.
termname
,
curses
.
erasechar
,
curses
.
getsyx
]:
curses
.
noqiflush
,
curses
.
noraw
,
func
()
curses
.
reset_prog_mode
,
curses
.
termattrs
,
curses
.
termname
,
curses
.
erasechar
,
curses
.
getsyx
]:
# Functions that actually need arguments
func
()
if
curses
.
tigetstr
(
"cnorm"
):
curses
.
curs_set
(
1
)
# Functions that actually need arguments
curses
.
delay_output
(
1
)
if
curses
.
tigetstr
(
"cnorm"
):
curses
.
echo
()
;
curses
.
echo
(
1
)
curses
.
curs_set
(
1
)
curses
.
delay_output
(
1
)
f
=
tempfile
.
TemporaryFile
()
curses
.
echo
()
;
curses
.
echo
(
1
)
stdscr
.
putwin
(
f
)
f
.
seek
(
0
)
f
=
tempfile
.
TemporaryFile
()
curses
.
getwin
(
f
)
stdscr
.
putwin
(
f
)
f
.
close
()
f
.
seek
(
0
)
curses
.
getwin
(
f
)
curses
.
halfdelay
(
1
)
f
.
close
()
curses
.
intrflush
(
1
)
curses
.
meta
(
1
)
curses
.
halfdelay
(
1
)
curses
.
napms
(
100
)
curses
.
intrflush
(
1
)
curses
.
newpad
(
50
,
50
)
curses
.
meta
(
1
)
win
=
curses
.
newwin
(
5
,
5
)
curses
.
napms
(
100
)
win
=
curses
.
newwin
(
5
,
5
,
1
,
1
)
curses
.
newpad
(
50
,
50
)
curses
.
nl
()
;
curses
.
nl
(
1
)
win
=
curses
.
newwin
(
5
,
5
)
curses
.
putp
(
b
'abc'
)
win
=
curses
.
newwin
(
5
,
5
,
1
,
1
)
curses
.
qiflush
()
curses
.
nl
()
;
curses
.
nl
(
1
)
curses
.
raw
()
;
curses
.
raw
(
1
)
curses
.
putp
(
b
'abc'
)
curses
.
setsyx
(
5
,
5
)
curses
.
qiflush
()
curses
.
tigetflag
(
'hc'
)
curses
.
raw
()
;
curses
.
raw
(
1
)
curses
.
tigetnum
(
'co'
)
curses
.
setsyx
(
5
,
5
)
curses
.
tigetstr
(
'cr'
)
curses
.
tigetflag
(
'hc'
)
curses
.
tparm
(
b
'cr'
)
curses
.
tigetnum
(
'co'
)
curses
.
typeahead
(
sys
.
__stdin__
.
fileno
())
curses
.
tigetstr
(
'cr'
)
curses
.
unctrl
(
'a'
)
curses
.
tparm
(
b
'cr'
)
curses
.
ungetch
(
'a'
)
curses
.
typeahead
(
sys
.
__stdin__
.
fileno
())
curses
.
use_env
(
1
)
curses
.
unctrl
(
'a'
)
curses
.
ungetch
(
'a'
)
# Functions only available on a few platforms
curses
.
use_env
(
1
)
if
curses
.
has_colors
():
curses
.
start_color
()
# Functions only available on a few platforms
curses
.
init_pair
(
2
,
1
,
1
)
if
curses
.
has_colors
():
curses
.
color_content
(
1
)
curses
.
start_color
()
curses
.
color_pair
(
2
)
curses
.
init_pair
(
2
,
1
,
1
)
curses
.
pair_content
(
curses
.
COLOR_PAIRS
-
1
)
curses
.
color_content
(
1
)
curses
.
pair_number
(
0
)
curses
.
color_pair
(
2
)
curses
.
pair_content
(
curses
.
COLOR_PAIRS
-
1
)
if
hasattr
(
curses
,
'use_default_colors'
):
curses
.
pair_number
(
0
)
curses
.
use_default_colors
()
if
hasattr
(
curses
,
'use_default_colors'
):
if
hasattr
(
curses
,
'keyname'
):
curses
.
use_default_colors
()
curses
.
keyname
(
13
)
if
hasattr
(
curses
,
'keyname'
):
if
hasattr
(
curses
,
'has_key'
):
curses
.
keyname
(
13
)
curses
.
has_key
(
13
)
if
hasattr
(
curses
,
'has_key'
):
if
hasattr
(
curses
,
'getmouse'
):
curses
.
has_key
(
13
)
(
availmask
,
oldmask
)
=
curses
.
mousemask
(
curses
.
BUTTON1_PRESSED
)
# availmask indicates that mouse stuff not available.
if
hasattr
(
curses
,
'getmouse'
):
if
availmask
!=
0
:
(
availmask
,
oldmask
)
=
curses
.
mousemask
(
curses
.
BUTTON1_PRESSED
)
curses
.
mouseinterval
(
10
)
# availmask indicates that mouse stuff not available.
# just verify these don't cause errors
if
availmask
!=
0
:
curses
.
ungetmouse
(
0
,
0
,
0
,
0
,
curses
.
BUTTON1_PRESSED
)
curses
.
mouseinterval
(
10
)
m
=
curses
.
getmouse
()
# just verify these don't cause errors
curses
.
ungetmouse
(
0
,
0
,
0
,
0
,
curses
.
BUTTON1_PRESSED
)
if
hasattr
(
curses
,
'is_term_resized'
):
m
=
curses
.
getmouse
()
curses
.
is_term_resized
(
*
stdscr
.
getmaxyx
())
if
hasattr
(
curses
,
'resizeterm'
):
if
hasattr
(
curses
,
'is_term_resized'
):
curses
.
resizeterm
(
*
stdscr
.
getmaxyx
())
curses
.
is_term_resized
(
*
stdscr
.
getmaxyx
())
if
hasattr
(
curses
,
'resize_term'
):
if
hasattr
(
curses
,
'resizeterm'
):
curses
.
resize_term
(
*
stdscr
.
getmaxyx
())
curses
.
resizeterm
(
*
stdscr
.
getmaxyx
())
if
hasattr
(
curses
,
'resize_term'
):
def
unit_tests
():
curses
.
resize_term
(
*
stdscr
.
getmaxyx
())
from
curses
import
ascii
for
ch
,
expected
in
[(
'a'
,
'a'
),
(
'A'
,
'A'
),
def
test_unctrl
(
self
):
(
';'
,
';'
),
(
' '
,
' '
),
from
curses
import
ascii
(
'
\x7f
'
,
'^?'
),
(
'
\n
'
,
'^J'
),
(
'
\0
'
,
'^@'
),
for
ch
,
expected
in
[(
'a'
,
'a'
),
(
'A'
,
'A'
),
# Meta-bit characters
(
';'
,
';'
),
(
' '
,
' '
),
(
'
\x8a
'
,
'!^J'
),
(
'
\xc1
'
,
'!A'
),
(
'
\x7f
'
,
'^?'
),
(
'
\n
'
,
'^J'
),
(
'
\0
'
,
'^@'
),
]:
# Meta-bit characters
if
ascii
.
unctrl
(
ch
)
!=
expected
:
(
'
\x8a
'
,
'!^J'
),
(
'
\xc1
'
,
'!A'
),
print
(
'curses.unctrl fails on character'
,
repr
(
ch
))
]:
self
.
assertEqual
(
ascii
.
unctrl
(
ch
),
expected
,
'curses.unctrl fails on character
%
r'
%
ch
)
def
test_userptr_without_set
(
stdscr
):
w
=
curses
.
newwin
(
10
,
10
)
p
=
curses
.
panel
.
new_panel
(
w
)
def
test_userptr_without_set
(
self
):
# try to access userptr() before calling set_userptr() -- segfaults
w
=
curses
.
newwin
(
10
,
10
)
try
:
p
=
curses
.
panel
.
new_panel
(
w
)
p
.
userptr
()
# try to access userptr() before calling set_userptr() -- segfaults
raise
RuntimeError
(
'userptr should fail since not set'
)
with
self
.
assertRaises
(
curses
.
panel
.
error
,
except
curses
.
panel
.
error
:
msg
=
'userptr should fail since not set'
):
pass
p
.
userptr
()
def
test_userptr_memory_leak
(
stdscr
):
def
test_userptr_memory_leak
(
self
):
w
=
curses
.
newwin
(
10
,
10
)
w
=
curses
.
newwin
(
10
,
10
)
p
=
curses
.
panel
.
new_panel
(
w
)
p
=
curses
.
panel
.
new_panel
(
w
)
obj
=
object
()
obj
=
object
()
nrefs
=
sys
.
getrefcount
(
obj
)
nrefs
=
sys
.
getrefcount
(
obj
)
for
i
in
range
(
100
):
for
i
in
range
(
100
):
p
.
set_userptr
(
obj
)
p
.
set_userptr
(
obj
)
p
.
set_userptr
(
None
)
p
.
set_userptr
(
None
)
if
sys
.
getrefcount
(
obj
)
!=
nrefs
:
self
.
assertEqual
(
sys
.
getrefcount
(
obj
),
nrefs
,
raise
RuntimeError
(
"set_userptr leaked references"
)
"set_userptr leaked references"
)
def
test_userptr_segfault
(
stdscr
):
def
test_userptr_segfault
(
self
):
panel
=
curses
.
panel
.
new_panel
(
stdscr
)
panel
=
curses
.
panel
.
new_panel
(
self
.
stdscr
)
class
A
:
class
A
:
def
__del__
(
self
):
def
__del__
(
self
):
panel
.
set_userptr
(
None
)
panel
.
set_userptr
(
None
)
panel
.
set_userptr
(
A
())
panel
.
set_userptr
(
A
())
panel
.
set_userptr
(
None
)
panel
.
set_userptr
(
None
)
def
test_resize_term
(
stdscr
):
@unittest.skipUnless
(
hasattr
(
curses
,
'resizeterm'
),
if
hasattr
(
curses
,
'resizeterm'
):
'resizeterm not available'
)
def
test_resize_term
(
self
):
lines
,
cols
=
curses
.
LINES
,
curses
.
COLS
lines
,
cols
=
curses
.
LINES
,
curses
.
COLS
curses
.
resizeterm
(
lines
-
1
,
cols
+
1
)
new_lines
=
lines
-
1
new_cols
=
cols
+
1
if
curses
.
LINES
!=
lines
-
1
or
curses
.
COLS
!=
cols
+
1
:
curses
.
resizeterm
(
new_lines
,
new_cols
)
raise
RuntimeError
(
"Expected resizeterm to update LINES and COLS"
)
self
.
assertEqual
(
curses
.
LINES
,
new_lines
)
def
test_issue6243
(
stdscr
):
self
.
assertEqual
(
curses
.
COLS
,
new_cols
)
curses
.
ungetch
(
1025
)
stdscr
.
getkey
()
def
test_issue6243
(
self
):
curses
.
ungetch
(
1025
)
def
test_unget_wch
(
stdscr
):
self
.
stdscr
.
getkey
()
if
not
hasattr
(
curses
,
'unget_wch'
):
return
@unittest.skipUnless
(
hasattr
(
curses
,
'unget_wch'
),
encoding
=
stdscr
.
encoding
'unget_wch not available'
)
for
ch
in
(
'a'
,
'
\xe9
'
,
'
\u20ac
'
,
'
\U0010FFFF
'
):
def
test_unget_wch
(
self
):
stdscr
=
self
.
stdscr
encoding
=
stdscr
.
encoding
for
ch
in
(
'a'
,
'
\xe9
'
,
'
\u20ac
'
,
'
\U0010FFFF
'
):
try
:
ch
.
encode
(
encoding
)
except
UnicodeEncodeError
:
continue
try
:
curses
.
unget_wch
(
ch
)
except
Exception
as
err
:
self
.
fail
(
"unget_wch(
%
a) failed with encoding
%
s:
%
s"
%
(
ch
,
stdscr
.
encoding
,
err
))
read
=
stdscr
.
get_wch
()
self
.
assertEqual
(
read
,
ch
)
code
=
ord
(
ch
)
curses
.
unget_wch
(
code
)
read
=
stdscr
.
get_wch
()
self
.
assertEqual
(
read
,
ch
)
def
test_issue10570
(
self
):
b
=
curses
.
tparm
(
curses
.
tigetstr
(
"cup"
),
5
,
3
)
self
.
assertIs
(
type
(
b
),
bytes
)
curses
.
putp
(
b
)
def
test_encoding
(
self
):
stdscr
=
self
.
stdscr
import
codecs
encoding
=
stdscr
.
encoding
codecs
.
lookup
(
encoding
)
with
self
.
assertRaises
(
TypeError
):
stdscr
.
encoding
=
10
stdscr
.
encoding
=
encoding
with
self
.
assertRaises
(
TypeError
):
del
stdscr
.
encoding
def
test_issue21088
(
self
):
stdscr
=
self
.
stdscr
#
# http://bugs.python.org/issue21088
#
# the bug:
# when converting curses.window.addch to Argument Clinic
# the first two parameters were switched.
# if someday we can represent the signature of addch
# we will need to rewrite this test.
try
:
try
:
ch
.
encode
(
encoding
)
signature
=
inspect
.
signature
(
stdscr
.
addch
)
except
UnicodeEncodeError
:
self
.
assertFalse
(
signature
)
continue
except
ValueError
:
try
:
# not generating a signature is fine.
curses
.
unget_wch
(
ch
)
pass
except
Exception
as
err
:
raise
Exception
(
"unget_wch(
%
a) failed with encoding
%
s:
%
s"
# So. No signature for addch.
%
(
ch
,
stdscr
.
encoding
,
err
))
# But Argument Clinic gave us a human-readable equivalent
read
=
stdscr
.
get_wch
()
# as the first line of the docstring. So we parse that,
if
read
!=
ch
:
# and ensure that the parameters appear in the correct order.
raise
AssertionError
(
"
%
r !=
%
r"
%
(
read
,
ch
))
# Since this is parsing output from Argument Clinic, we can
# be reasonably certain the generated parsing code will be
code
=
ord
(
ch
)
# correct too.
curses
.
unget_wch
(
code
)
human_readable_signature
=
stdscr
.
addch
.
__doc__
.
split
(
"
\n
"
)[
0
]
read
=
stdscr
.
get_wch
()
offset
=
human_readable_signature
.
find
(
"[y, x,]"
)
if
read
!=
ch
:
assert
offset
>=
0
,
""
raise
AssertionError
(
"
%
r !=
%
r"
%
(
read
,
ch
))
def
test_issue10570
():
b
=
curses
.
tparm
(
curses
.
tigetstr
(
"cup"
),
5
,
3
)
assert
type
(
b
)
is
bytes
curses
.
putp
(
b
)
def
test_encoding
(
stdscr
):
import
codecs
encoding
=
stdscr
.
encoding
codecs
.
lookup
(
encoding
)
try
:
stdscr
.
encoding
=
10
except
TypeError
:
pass
else
:
raise
AssertionError
(
"TypeError not raised"
)
stdscr
.
encoding
=
encoding
try
:
del
stdscr
.
encoding
except
TypeError
:
pass
else
:
raise
AssertionError
(
"TypeError not raised"
)
def
test_issue21088
(
stdscr
):
#
# http://bugs.python.org/issue21088
#
# the bug:
# when converting curses.window.addch to Argument Clinic
# the first two parameters were switched.
# if someday we can represent the signature of addch
# we will need to rewrite this test.
try
:
signature
=
inspect
.
signature
(
stdscr
.
addch
)
self
.
assertFalse
(
signature
)
except
ValueError
:
# not generating a signature is fine.
pass
# So. No signature for addch.
# But Argument Clinic gave us a human-readable equivalent
# as the first line of the docstring. So we parse that,
# and ensure that the parameters appear in the correct order.
# Since this is parsing output from Argument Clinic, we can
# be reasonably certain the generated parsing code will be
# correct too.
human_readable_signature
=
stdscr
.
addch
.
__doc__
.
split
(
"
\n
"
)[
0
]
offset
=
human_readable_signature
.
find
(
"[y, x,]"
)
assert
offset
>=
0
,
""
def
main
(
stdscr
):
curses
.
savetty
()
try
:
module_funcs
(
stdscr
)
window_funcs
(
stdscr
)
test_userptr_without_set
(
stdscr
)
test_userptr_memory_leak
(
stdscr
)
test_userptr_segfault
(
stdscr
)
test_resize_term
(
stdscr
)
test_issue6243
(
stdscr
)
test_unget_wch
(
stdscr
)
test_issue10570
()
test_encoding
(
stdscr
)
test_issue21088
(
stdscr
)
finally
:
curses
.
resetty
()
def
test_main
():
if
not
sys
.
__stdout__
.
isatty
():
raise
unittest
.
SkipTest
(
"sys.__stdout__ is not a tty"
)
# testing setupterm() inside initscr/endwin
# causes terminal breakage
curses
.
setupterm
(
fd
=
sys
.
__stdout__
.
fileno
())
try
:
stdscr
=
curses
.
initscr
()
main
(
stdscr
)
finally
:
curses
.
endwin
()
unit_tests
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
curses
.
wrapper
(
main
)
unittest
.
main
()
unit_tests
()
Misc/NEWS
Dosyayı görüntüle @
baf45c59
...
@@ -75,6 +75,8 @@ Library
...
@@ -75,6 +75,8 @@ Library
Tests
Tests
-----
-----
- Issue #16000: Convert test_curses to use unittest.
- Issue #21456: Skip two tests in test_urllib2net.py if _ssl module not
- Issue #21456: Skip two tests in test_urllib2net.py if _ssl module not
present. Patch by Remi Pointel.
present. Patch by Remi Pointel.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment