2626
2727# If either of these don't exist, skip the tests.
2828curses = import_module ('curses' )
29- import_module ('curses.panel' )
3029import_module ('curses.ascii' )
3130import_module ('curses.textpad' )
31+ try :
32+ import curses .panel
33+ except ImportError :
34+ pass
3235
3336def requires_curses_func (name ):
3437 return unittest .skipUnless (hasattr (curses , name ),
@@ -137,7 +140,8 @@ def test_window_funcs(self):
137140
138141 stdscr .idcok (1 )
139142 stdscr .idlok (1 )
140- stdscr .immedok (1 )
143+ if hasattr (stdscr , 'immedok' ):
144+ stdscr .immedok (1 )
141145 stdscr .insch ('c' )
142146 stdscr .insdelln (1 )
143147 stdscr .insnstr ('abc' , 3 )
@@ -171,7 +175,8 @@ def test_window_funcs(self):
171175 stdscr .setscrreg (10 ,15 )
172176 win3 = stdscr .subwin (10 ,10 )
173177 win3 = stdscr .subwin (10 ,10 , 5 ,5 )
174- stdscr .syncok (1 )
178+ if hasattr (stdscr , 'syncok' ):
179+ stdscr .syncok (1 )
175180 stdscr .timeout (5 )
176181 stdscr .touchline (5 ,5 )
177182 stdscr .touchline (5 ,5 ,0 )
@@ -201,14 +206,18 @@ def test_module_funcs(self):
201206 "Test module-level functions"
202207 for func in [curses .baudrate , curses .beep , curses .can_change_color ,
203208 curses .cbreak , curses .def_prog_mode , curses .doupdate ,
204- curses .filter , curses . flash , curses .flushinp ,
209+ curses .flash , curses .flushinp ,
205210 curses .has_colors , curses .has_ic , curses .has_il ,
206211 curses .isendwin , curses .killchar , curses .longname ,
207212 curses .nocbreak , curses .noecho , curses .nonl ,
208213 curses .noqiflush , curses .noraw ,
209214 curses .reset_prog_mode , curses .termattrs ,
210- curses .termname , curses .erasechar , curses . getsyx ]:
215+ curses .termname , curses .erasechar ]:
211216 func ()
217+ if hasattr (curses , 'filter' ):
218+ curses .filter ()
219+ if hasattr (curses , 'getsyx' ):
220+ curses .getsyx ()
212221
213222 # Functions that actually need arguments
214223 if curses .tigetstr ("cnorm" ):
@@ -232,15 +241,18 @@ def test_module_funcs(self):
232241 curses .putp (b'abc' )
233242 curses .qiflush ()
234243 curses .raw () ; curses .raw (1 )
235- curses .setsyx (5 ,5 )
244+ if hasattr (curses , 'setsyx' ):
245+ curses .setsyx (5 ,5 )
236246 curses .tigetflag ('hc' )
237247 curses .tigetnum ('co' )
238248 curses .tigetstr ('cr' )
239249 curses .tparm (b'cr' )
240- curses .typeahead (sys .__stdin__ .fileno ())
250+ if hasattr (curses , 'typeahead' ):
251+ curses .typeahead (sys .__stdin__ .fileno ())
241252 curses .unctrl ('a' )
242253 curses .ungetch ('a' )
243- curses .use_env (1 )
254+ if hasattr (curses , 'use_env' ):
255+ curses .use_env (1 )
244256
245257 # Functions only available on a few platforms
246258 def test_colors_funcs (self ):
@@ -274,6 +286,7 @@ def test_getmouse(self):
274286 curses .ungetmouse (0 , 0 , 0 , 0 , curses .BUTTON1_PRESSED )
275287 m = curses .getmouse ()
276288
289+ @requires_curses_func ('panel' )
277290 def test_userptr_without_set (self ):
278291 w = curses .newwin (10 , 10 )
279292 p = curses .panel .new_panel (w )
@@ -282,6 +295,7 @@ def test_userptr_without_set(self):
282295 msg = 'userptr should fail since not set' ):
283296 p .userptr ()
284297
298+ @requires_curses_func ('panel' )
285299 def test_userptr_memory_leak (self ):
286300 w = curses .newwin (10 , 10 )
287301 p = curses .panel .new_panel (w )
@@ -294,6 +308,7 @@ def test_userptr_memory_leak(self):
294308 self .assertEqual (sys .getrefcount (obj ), nrefs ,
295309 "set_userptr leaked references" )
296310
311+ @requires_curses_func ('panel' )
297312 def test_userptr_segfault (self ):
298313 panel = curses .panel .new_panel (self .stdscr )
299314 class A :
@@ -302,6 +317,7 @@ def __del__(self):
302317 panel .set_userptr (A ())
303318 panel .set_userptr (None )
304319
320+ @requires_curses_func ('panel' )
305321 def test_new_curses_panel (self ):
306322 panel = curses .panel .new_panel (self .stdscr )
307323 self .assertRaises (TypeError , type (panel ))
0 commit comments