diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -16,7 +16,7 @@ # option. If not available, nothing after this line will be executed. import unittest -from test.support import requires, import_module +from test.support import requires, import_module, run_unittest requires('curses') # If either of these don't exist, skip the tests. @@ -260,10 +260,6 @@ if curses.LINES != lines - 1 or curses.COLS != cols + 1: raise RuntimeError("Expected resizeterm to update LINES and COLS") -def test_issue6243(stdscr): - curses.ungetch(1025) - stdscr.getkey() - def test_unget_wch(stdscr): if not hasattr(curses, 'unget_wch'): return @@ -288,11 +284,6 @@ if read != ch: 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 @@ -311,6 +302,33 @@ else: raise AssertionError("TypeError not raised") + +class CursesTestCase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + # Testing setupterm() inside initscr/endwin causes terminal breakage. + curses.setupterm(fd=sys.__stdout__.fileno()) + + def setUp(self): + self.stdscr = curses.initscr() + curses.savetty() + + def tearDown(self): + curses.resetty() + curses.endwin() + del(self.stdscr) + + def test_issue6243(self): + curses.ungetch(1025) + self.stdscr.getkey() + + def test_issue10570(self): + b = curses.tparm(curses.tigetstr("cup"), 5, 3) + self.assertIs(type(b), bytes) + curses.putp(b) + + def main(stdscr): curses.savetty() try: @@ -318,9 +336,7 @@ window_funcs(stdscr) test_userptr_without_set(stdscr) test_resize_term(stdscr) - test_issue6243(stdscr) test_unget_wch(stdscr) - test_issue10570() test_encoding(stdscr) finally: curses.resetty() @@ -328,6 +344,11 @@ def test_main(): if not sys.__stdout__.isatty(): raise unittest.SkipTest("sys.__stdout__ is not a tty") + + test_classes = (CursesTestCase, ) + + run_unittest(*test_classes) + # testing setupterm() inside initscr/endwin # causes terminal breakage curses.setupterm(fd=sys.__stdout__.fileno()) @@ -339,5 +360,4 @@ unit_tests() if __name__ == '__main__': - curses.wrapper(main) - unit_tests() + test_main()