25
25
26
26
# If either of these don't exist, skip the tests.
27
27
curses = import_module ('curses' )
28
- import_module ('curses.panel' )
29
28
import_module ('curses.ascii' )
30
29
import_module ('curses.textpad' )
30
+ try :
31
+ import curses .panel
32
+ except ImportError :
33
+ pass
31
34
32
35
def requires_curses_func (name ):
33
36
return unittest .skipUnless (hasattr (curses , name ),
@@ -138,7 +141,8 @@ def test_window_funcs(self):
138
141
139
142
stdscr .idcok (1 )
140
143
stdscr .idlok (1 )
141
- stdscr .immedok (1 )
144
+ if hasattr (stdscr , 'immedok' ):
145
+ stdscr .immedok (1 )
142
146
stdscr .insch ('c' )
143
147
stdscr .insdelln (1 )
144
148
stdscr .insnstr ('abc' , 3 )
@@ -172,7 +176,8 @@ def test_window_funcs(self):
172
176
stdscr .setscrreg (10 ,15 )
173
177
win3 = stdscr .subwin (10 ,10 )
174
178
win3 = stdscr .subwin (10 ,10 , 5 ,5 )
175
- stdscr .syncok (1 )
179
+ if hasattr (stdscr , 'syncok' ):
180
+ stdscr .syncok (1 )
176
181
stdscr .timeout (5 )
177
182
stdscr .touchline (5 ,5 )
178
183
stdscr .touchline (5 ,5 ,0 )
@@ -211,15 +216,19 @@ def test_module_funcs(self):
211
216
"Test module-level functions"
212
217
for func in [curses .baudrate , curses .beep , curses .can_change_color ,
213
218
curses .cbreak , curses .def_prog_mode , curses .doupdate ,
214
- curses .filter , curses . flash , curses .flushinp ,
219
+ curses .flash , curses .flushinp ,
215
220
curses .has_colors , curses .has_ic , curses .has_il ,
216
221
curses .isendwin , curses .killchar , curses .longname ,
217
222
curses .nocbreak , curses .noecho , curses .nonl ,
218
223
curses .noqiflush , curses .noraw ,
219
224
curses .reset_prog_mode , curses .termattrs ,
220
- curses .termname , curses .erasechar , curses . getsyx ]:
225
+ curses .termname , curses .erasechar ]:
221
226
with self .subTest (func = func .__qualname__ ):
222
227
func ()
228
+ if hasattr (curses , 'filter' ):
229
+ curses .filter ()
230
+ if hasattr (curses , 'getsyx' ):
231
+ curses .getsyx ()
223
232
224
233
# Functions that actually need arguments
225
234
if curses .tigetstr ("cnorm" ):
@@ -243,15 +252,18 @@ def test_module_funcs(self):
243
252
curses .putp (b'abc' )
244
253
curses .qiflush ()
245
254
curses .raw () ; curses .raw (1 )
246
- curses .setsyx (5 ,5 )
255
+ if hasattr (curses , 'setsyx' ):
256
+ curses .setsyx (5 ,5 )
247
257
curses .tigetflag ('hc' )
248
258
curses .tigetnum ('co' )
249
259
curses .tigetstr ('cr' )
250
260
curses .tparm (b'cr' )
251
- curses .typeahead (sys .__stdin__ .fileno ())
261
+ if hasattr (curses , 'typeahead' ):
262
+ curses .typeahead (sys .__stdin__ .fileno ())
252
263
curses .unctrl ('a' )
253
264
curses .ungetch ('a' )
254
- curses .use_env (1 )
265
+ if hasattr (curses , 'use_env' ):
266
+ curses .use_env (1 )
255
267
256
268
# Functions only available on a few platforms
257
269
def test_colors_funcs (self ):
@@ -285,6 +297,7 @@ def test_getmouse(self):
285
297
curses .ungetmouse (0 , 0 , 0 , 0 , curses .BUTTON1_PRESSED )
286
298
m = curses .getmouse ()
287
299
300
+ @requires_curses_func ('panel' )
288
301
def test_userptr_without_set (self ):
289
302
w = curses .newwin (10 , 10 )
290
303
p = curses .panel .new_panel (w )
@@ -293,6 +306,7 @@ def test_userptr_without_set(self):
293
306
msg = 'userptr should fail since not set' ):
294
307
p .userptr ()
295
308
309
+ @requires_curses_func ('panel' )
296
310
def test_userptr_memory_leak (self ):
297
311
w = curses .newwin (10 , 10 )
298
312
p = curses .panel .new_panel (w )
@@ -305,6 +319,7 @@ def test_userptr_memory_leak(self):
305
319
self .assertEqual (sys .getrefcount (obj ), nrefs ,
306
320
"set_userptr leaked references" )
307
321
322
+ @requires_curses_func ('panel' )
308
323
def test_userptr_segfault (self ):
309
324
panel = curses .panel .new_panel (self .stdscr )
310
325
class A :
@@ -313,6 +328,7 @@ def __del__(self):
313
328
panel .set_userptr (A ())
314
329
panel .set_userptr (None )
315
330
331
+ @requires_curses_func ('panel' )
316
332
def test_new_curses_panel (self ):
317
333
panel = curses .panel .new_panel (self .stdscr )
318
334
self .assertRaises (TypeError , type (panel ))
0 commit comments