From ffbfa07533809a523938d5e342ff7482a12dd5d0 Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Tue, 9 May 2023 09:13:40 +0200 Subject: Fix `TextCanvas` `CanvasError("Attribute extends beyond text...")` (#555) * Fix TextCanvas `CanvasError("Attribute extends beyond text...") * `[[]] * ...` causes list of 1 list with pointers amount equal to multiplier instead of "list of lists" * Add 2 basic font tests which check for Canvas create issue * Add few type annotations during debug process Fix: #554 * Force tests to restore default encoding in tearDown Tests order change should not cause tests failures --------- Co-authored-by: Aleksei Stepanov --- urwid/tests/test_graphics.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'urwid/tests/test_graphics.py') diff --git a/urwid/tests/test_graphics.py b/urwid/tests/test_graphics.py index f731208..1ae1f98 100644 --- a/urwid/tests/test_graphics.py +++ b/urwid/tests/test_graphics.py @@ -7,6 +7,13 @@ from urwid import graphics class LineBoxTest(unittest.TestCase): + def setUp(self) -> None: + self.old_encoding = urwid.util._target_encoding + urwid.set_encoding("utf-8") + + def tearDown(self) -> None: + urwid.set_encoding(self.old_encoding) + def border(self, tl, t, tr, l, r, bl, b, br): return [b''.join([tl, t, tr]), b''.join([l, b" ", r]), @@ -14,7 +21,6 @@ class LineBoxTest(unittest.TestCase): def test_linebox_pack(self): # Bug #346 'pack' Padding does not run with LineBox - urwid.set_encoding("utf-8") t = urwid.Text("AAA\nCCC\nDDD") size = t.pack() l = urwid.LineBox(t) @@ -23,7 +29,6 @@ class LineBoxTest(unittest.TestCase): self.assertEqual(l.pack()[1], size[1] + 2) def test_linebox_border(self): - urwid.set_encoding("utf-8") t = urwid.Text("") l = urwid.LineBox(t).render((3,)).text @@ -87,8 +92,14 @@ class BarGraphTest(unittest.TestCase): (1,[(3,3)]) ] ) class SmoothBarGraphTest(unittest.TestCase): + def setUp(self) -> None: + self.old_encoding = urwid.util._target_encoding + urwid.set_encoding("utf-8") + + def tearDown(self) -> None: + urwid.set_encoding(self.old_encoding) + def sbgtest(self, desc, data, top, exp ): - urwid.set_encoding('utf-8') g = urwid.BarGraph( ['black','red','blue'], None, {(1,0):'red/black', (2,1):'blue/red'}) g.set_data( data, top ) -- cgit v1.2.1