Skip to content

Commit

Permalink
bpo-43016: Fix test_curses on platform without cursesw (GH-24405) (GH…
Browse files Browse the repository at this point in the history
…-24408)

(cherry picked from commit a1e9a1e)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
miss-islington and serhiy-storchaka authored Feb 1, 2021
1 parent 931263b commit aab84a5
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,21 @@ def test_refresh_control(self):

def test_output_character(self):
stdscr = self.stdscr
encoding = stdscr.encoding
# addch()
stdscr.refresh()
stdscr.move(0, 0)
stdscr.addch('A')
stdscr.addch(b'A')
stdscr.addch(65)
stdscr.addch('\u20ac')
c = '\u20ac'
try:
stdscr.addch(c)
except UnicodeEncodeError:
self.assertRaises(UnicodeEncodeError, c.encode, encoding)
except OverflowError:
encoded = c.encode(encoding)
self.assertNotEqual(len(encoded), 1, repr(encoded))
stdscr.addch('A', curses.A_BOLD)
stdscr.addch(1, 2, 'A')
stdscr.addch(2, 3, 'A', curses.A_BOLD)
Expand All @@ -257,19 +265,25 @@ def test_output_character(self):
stdscr.echochar('A')
stdscr.echochar(b'A')
stdscr.echochar(65)
self.assertRaises(OverflowError, stdscr.echochar, '\u20ac')
with self.assertRaises((UnicodeEncodeError, OverflowError)):
stdscr.echochar('\u20ac')
stdscr.echochar('A', curses.A_BOLD)
self.assertIs(stdscr.is_wintouched(), False)

def test_output_string(self):
stdscr = self.stdscr
encoding = stdscr.encoding
# addstr()/insstr()
for func in [stdscr.addstr, stdscr.insstr]:
with self.subTest(func.__qualname__):
stdscr.move(0, 0)
func('abcd')
func(b'abcd')
func('àßçđ')
s = 'àßçđ'
try:
func(s)
except UnicodeEncodeError:
self.assertRaises(UnicodeEncodeError, s.encode, encoding)
func('abcd', curses.A_BOLD)
func(1, 2, 'abcd')
func(2, 3, 'abcd', curses.A_BOLD)
Expand All @@ -280,7 +294,11 @@ def test_output_string(self):
stdscr.move(0, 0)
func('1234', 3)
func(b'1234', 3)
func('\u0661\u0662\u0663\u0664', 3)
s = '\u0661\u0662\u0663\u0664'
try:
func(s, 3)
except UnicodeEncodeError:
self.assertRaises(UnicodeEncodeError, s.encode, encoding)
func('1234', 5)
func('1234', 3, curses.A_BOLD)
func(1, 2, '1234', 3)
Expand Down Expand Up @@ -470,7 +488,7 @@ def test_background(self):
win = curses.newwin(5, 15, 5, 2)
win.addstr(0, 0, 'Lorem ipsum')

self.assertEqual(win.getbkgd(), 0)
self.assertIn(win.getbkgd(), (0, 32))

# bkgdset()
win.bkgdset('_')
Expand Down

0 comments on commit aab84a5

Please sign in to comment.