2525
2626# If either of these don't exist, skip the tests.
2727curses = import_module ('curses' )
28- import_module ('curses.panel' )
2928import_module ('curses.ascii' )
3029import_module ('curses.textpad' )
30+ try :
31+ import curses .panel
32+ except ImportError :
33+ pass
3134
3235def requires_curses_func (name ):
3336 return unittest .skipUnless (hasattr (curses , name ),
@@ -138,7 +141,8 @@ def test_window_funcs(self):
138141
139142 stdscr .idcok (1 )
140143 stdscr .idlok (1 )
141- stdscr .immedok (1 )
144+ if hasattr (stdscr , 'immedok' ):
145+ stdscr .immedok (1 )
142146 stdscr .insch ('c' )
143147 stdscr .insdelln (1 )
144148 stdscr .insnstr ('abc' , 3 )
@@ -172,7 +176,8 @@ def test_window_funcs(self):
172176 stdscr .setscrreg (10 ,15 )
173177 win3 = stdscr .subwin (10 ,10 )
174178 win3 = stdscr .subwin (10 ,10 , 5 ,5 )
175- stdscr .syncok (1 )
179+ if hasattr (stdscr , 'syncok' ):
180+ stdscr .syncok (1 )
176181 stdscr .timeout (5 )
177182 stdscr .touchline (5 ,5 )
178183 stdscr .touchline (5 ,5 ,0 )
@@ -211,15 +216,19 @@ def test_module_funcs(self):
211216 "Test module-level functions"
212217 for func in [curses .baudrate , curses .beep , curses .can_change_color ,
213218 curses .cbreak , curses .def_prog_mode , curses .doupdate ,
214- curses .filter , curses . flash , curses .flushinp ,
219+ curses .flash , curses .flushinp ,
215220 curses .has_colors , curses .has_ic , curses .has_il ,
216221 curses .isendwin , curses .killchar , curses .longname ,
217222 curses .nocbreak , curses .noecho , curses .nonl ,
218223 curses .noqiflush , curses .noraw ,
219224 curses .reset_prog_mode , curses .termattrs ,
220- curses .termname , curses .erasechar , curses . getsyx ]:
225+ curses .termname , curses .erasechar ]:
221226 with self .subTest (func = func .__qualname__ ):
222227 func ()
228+ if hasattr (curses , 'filter' ):
229+ curses .filter ()
230+ if hasattr (curses , 'getsyx' ):
231+ curses .getsyx ()
223232
224233 # Functions that actually need arguments
225234 if curses .tigetstr ("cnorm" ):
@@ -243,15 +252,18 @@ def test_module_funcs(self):
243252 curses .putp (b'abc' )
244253 curses .qiflush ()
245254 curses .raw () ; curses .raw (1 )
246- curses .setsyx (5 ,5 )
255+ if hasattr (curses , 'setsyx' ):
256+ curses .setsyx (5 ,5 )
247257 curses .tigetflag ('hc' )
248258 curses .tigetnum ('co' )
249259 curses .tigetstr ('cr' )
250260 curses .tparm (b'cr' )
251- curses .typeahead (sys .__stdin__ .fileno ())
261+ if hasattr (curses , 'typeahead' ):
262+ curses .typeahead (sys .__stdin__ .fileno ())
252263 curses .unctrl ('a' )
253264 curses .ungetch ('a' )
254- curses .use_env (1 )
265+ if hasattr (curses , 'use_env' ):
266+ curses .use_env (1 )
255267
256268 # Functions only available on a few platforms
257269 def test_colors_funcs (self ):
@@ -285,6 +297,7 @@ def test_getmouse(self):
285297 curses .ungetmouse (0 , 0 , 0 , 0 , curses .BUTTON1_PRESSED )
286298 m = curses .getmouse ()
287299
300+ @requires_curses_func ('panel' )
288301 def test_userptr_without_set (self ):
289302 w = curses .newwin (10 , 10 )
290303 p = curses .panel .new_panel (w )
@@ -293,6 +306,7 @@ def test_userptr_without_set(self):
293306 msg = 'userptr should fail since not set' ):
294307 p .userptr ()
295308
309+ @requires_curses_func ('panel' )
296310 def test_userptr_memory_leak (self ):
297311 w = curses .newwin (10 , 10 )
298312 p = curses .panel .new_panel (w )
@@ -305,6 +319,7 @@ def test_userptr_memory_leak(self):
305319 self .assertEqual (sys .getrefcount (obj ), nrefs ,
306320 "set_userptr leaked references" )
307321
322+ @requires_curses_func ('panel' )
308323 def test_userptr_segfault (self ):
309324 panel = curses .panel .new_panel (self .stdscr )
310325 class A :
@@ -313,6 +328,7 @@ def __del__(self):
313328 panel .set_userptr (A ())
314329 panel .set_userptr (None )
315330
331+ @requires_curses_func ('panel' )
316332 def test_new_curses_panel (self ):
317333 panel = curses .panel .new_panel (self .stdscr )
318334 self .assertRaises (TypeError , type (panel ))
0 commit comments