Skip to content

Commit de590fc

Browse files
gh-133031: Fix test_textbox_unicode on a narrow build
A narrow build stores one byte per cell, so skip the multi-byte cases there, as already done for test_textbox_edit_wide. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 564c58c commit de590fc

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

Lib/test/test_curses.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,27 +2332,36 @@ def test_textbox_8bit_fill_last_cell(self):
23322332
def test_textbox_unicode(self):
23332333
# Like test_textbox_8bit, but characters are entered as strings -- the
23342334
# way do_command() receives get_wch() input -- rather than integer
2335-
# bytes. Each string is used only if encodable in the current locale.
2335+
# bytes. Each string is used only if encodable in the current locale;
2336+
# a narrow build stores one byte per cell, so multi-byte characters
2337+
# additionally need a wide build.
23362338
for text in ['abc', 'héšλ', 'café', 'naïve ¤', 'soupçon €Š', 'дякую єі']:
2337-
if self._encodable(text):
2338-
with self.subTest(text=text):
2339-
box, win = self._make_textbox(1, 12)
2340-
for ch in text:
2341-
box.do_command(ch)
2342-
self.assertEqual(box.gather(), text + ' ')
2339+
if not self._encodable(text):
2340+
continue
2341+
if not WIDE_BUILD and len(text.encode(self.stdscr.encoding)) != len(text):
2342+
continue
2343+
with self.subTest(text=text):
2344+
box, win = self._make_textbox(1, 12)
2345+
for ch in text:
2346+
box.do_command(ch)
2347+
self.assertEqual(box.gather(), text + ' ')
23432348

23442349
def test_textbox_unicode_insert_mode(self):
23452350
# Like test_textbox_8bit_insert, but the character is entered as a string
2346-
# (get_wch() input). Each string is used only if encodable.
2351+
# (get_wch() input). Each string is used only if encodable; multi-byte
2352+
# characters additionally need a wide build (one byte per cell otherwise).
23472353
for text in ['abcd', 'aβλc', 'aéàc', 'a¤½c', 'a€Šc', 'aдві']:
2348-
if self._encodable(text):
2349-
with self.subTest(text=text):
2350-
box, win = self._make_textbox(1, 10, insert_mode=True)
2351-
for ch in text[0] + text[2:]: # all but the 2nd character
2352-
box.do_command(ch)
2353-
win.move(0, 1)
2354-
box.do_command(text[1]) # insert it at position 1
2355-
self.assertEqual(box.gather(), text + ' ')
2354+
if not self._encodable(text):
2355+
continue
2356+
if not WIDE_BUILD and len(text.encode(self.stdscr.encoding)) != len(text):
2357+
continue
2358+
with self.subTest(text=text):
2359+
box, win = self._make_textbox(1, 10, insert_mode=True)
2360+
for ch in text[0] + text[2:]: # all but the 2nd character
2361+
box.do_command(ch)
2362+
win.move(0, 1)
2363+
box.do_command(text[1]) # insert it at position 1
2364+
self.assertEqual(box.gather(), text + ' ')
23562365

23572366
@requires_wide_build
23582367
def test_textbox_combining(self):

0 commit comments

Comments
 (0)