| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d60a677 commit 3428959
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,12 @@ def wrapped(self, *args, **kwargs): | |||
| 80 | 80 | term = os.environ.get('TERM') | |
| 81 | 81 | SHORT_MAX = 0x7fff | |
| 82 | 82 | ||
| 83 | + # ncurses before 6.5 can crash on repeated newterm(). Fall back to initscr() | ||
| 84 | + # and skip the tests that need several screens. | ||
| 85 | + _ncurses_version = getattr(curses, 'ncurses_version', None) | ||
| 86 | + BROKEN_NEWTERM = _ncurses_version is not None and _ncurses_version < (6, 5) | ||
| 87 | + USE_NEWTERM = hasattr(curses, 'newterm') and not BROKEN_NEWTERM | ||
| 88 | + | ||
| 83 | 89 | # newterm() is used when available (it reports errors instead of exiting), but | |
| 84 | 90 | # initscr() is still the fallback, and an unusable $TERM has no terminal to | |
| 85 | 91 | # drive either way. | |
@@ -139,7 +145,7 @@ def setUp(self): | |||
| 139 | 145 | sys.stderr.flush() | |
| 140 | 146 | sys.stdout.flush() | |
| 141 | 147 | print(file=self.output, flush=True) | |
| 142 | - if hasattr(curses, 'newterm'): | ||
| 148 | + if USE_NEWTERM: | ||
| 143 | 149 | # Use newterm() rather than initscr(): it reports errors instead of | |
| 144 | 150 | # exiting, and gives each test a fresh screen, which also lets | |
| 145 | 151 | # ScreenTests run newterm()/set_term() in the same process. | |
@@ -157,7 +163,11 @@ def setUp(self): | |||
| 157 | 163 | self.addCleanup(setattr, self, 'screen', None) | |
| 158 | 164 | self.addCleanup(setattr, self, 'stdscr', None) | |
| 159 | 165 | else: | |
| 166 | + # Tests share one initscr() screen; clear the rendition and | ||
| 167 | + # background so a previous test's does not bleed in. | ||
| 160 | 168 | self.stdscr = curses.initscr() | |
| 169 | + self.stdscr.attrset(curses.A_NORMAL) | ||
| 170 | + self.stdscr.bkgdset(' ') | ||
| 161 | 171 | if self.isatty: | |
| 162 | 172 | curses.savetty() | |
| 163 | 173 | self.addCleanup(curses.endwin) | |
@@ -2026,6 +2036,7 @@ def test_use_window(self): | |||
| 2026 | 2036 | ||
| 2027 | 2037 | @unittest.skipUnless(hasattr(curses.screen, 'use'), | |
| 2028 | 2038 | 'requires screen.use()') | |
| 2039 | + @unittest.skipUnless(USE_NEWTERM, 'no screen object without newterm()') | ||
| 2029 | 2040 | def test_use_screen(self): | |
| 2030 | 2041 | screen = self.screen | |
| 2031 | 2042 | self.assertEqual( | |
@@ -2913,6 +2924,7 @@ def stop_reader(): | |||
| 2913 | 2924 | ||
| 2914 | 2925 | ||
| 2915 | 2926 | @unittest.skipUnless(hasattr(curses, 'newterm'), 'requires curses.newterm()') | |
| 2927 | + @unittest.skipIf(BROKEN_NEWTERM, 'ncurses < 6.5 mishandles repeated newterm()') | ||
| 2916 | 2928 | @unittest.skipIf(not term or term == 'unknown', | |
| 2917 | 2929 | f"$TERM={term!r}, newterm() may not work") | |
| 2918 | 2930 | @unittest.skipIf(sys.platform == "cygwin", | |
@@ -2994,6 +3006,7 @@ def test_disallow_instantiation(self): | |||
| 2994 | 3006 | ||
| 2995 | 3007 | @unittest.skipUnless(hasattr(curses, 'slk_init'), 'requires curses.slk_init()') | |
| 2996 | 3008 | @unittest.skipUnless(hasattr(curses, 'newterm'), 'requires curses.newterm()') | |
| 3009 | + @unittest.skipIf(BROKEN_NEWTERM, 'ncurses < 6.5 mishandles repeated newterm()') | ||
| 2997 | 3010 | @unittest.skipIf(not term or term == 'unknown', | |
| 2998 | 3011 | f"$TERM={term!r}, newterm() may not work") | |
| 2999 | 3012 | @unittest.skipIf(sys.platform == "cygwin", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments