10000 bpo-42681: Fix range checks for color and pair numbers in curses by serhiy-storchaka · Pull Request #23874 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42681: Fix range checks for color and pair numbers in curses #23874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 3, 2021
Prev Previous commit
Next Next commit
Fix repeated test running.
  • Loading branch information
serhiy-storchaka committed Jan 3, 2021
commit 3ec8133b613ba08747e42830351e6089dfe9caa5
16 changes: 14 additions & 2 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ def test_init_color(self):
if not curses.can_change_color:
self.skipTest('cannot change color')

self.addCleanup(curses.init_color, 0, *curses.color_content(0))
self.addCleanup(curses.init_color, curses.COLORS - 1,
*curses.color_content(curses.COLORS - 1))

curses.init_color(0, 0, 0, 0)
self.assertEqual(curses.color_content(0), (0, 0, 0))
curses.init_color(0, 1000, 1000, 1000)
Expand All @@ -355,15 +359,21 @@ def test_init_color(self):

@requires_colors
def test_pair_content(self):
self.assertEqual(curses.pair_content(0),
(curses.COLOR_WHITE, curses.COLOR_BLACK))
if not hasattr(curses, 'use_default_colors'):
self.assertEqual(curses.pair_content(0),
(curses.COLOR_WHITE, curses.COLOR_BLACK))
curses.pair_content(0)
curses.pair_content(curses.COLOR_PAIRS - 1)

for pair in self.bad_pairs():
self.assertRaises(ValueError, curses.pair_content, pair)

@requires_colors
def test_init_pair(self):
self.addCleanup(curses.init_pair, 1, *curses.pair_content(1))
self.addCleanup(curses.init_pair, curses.COLOR_PAIRS - 1,
*curses.pair_content(curses.COLOR_PAIRS - 1))

curses.init_pair(1, 0, 0)
self.assertEqual(curses.pair_content(1), (0, 0))
curses.init_pair(1, curses.COLORS - 1, curses.COLORS - 1)
Expand All @@ -390,6 +400,8 @@ def test_color_attrs(self):
@requires_curses_func('use_default_colors')
@requires_colors
def test_use_default_colors(self):
self.assertIn(curses.pair_content(0),
((curses.COLOR_WHITE, curses.COLOR_BLACK), (-1, -1)))
curses.use_default_colors()
self.assertEqual(curses.pair_content(0), (-1, -1))

Expand Down
0