diff options
author | Alexey Stepanov <penguinolog@users.noreply.github.com> | 2023-05-09 09:13:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 09:13:40 +0200 |
commit | ffbfa07533809a523938d5e342ff7482a12dd5d0 (patch) | |
tree | f82251e47e72b9fe873f0eb20410c105387407b9 /urwid/tests/test_widget.py | |
parent | d26cb42a9fd28cb0743ad04d5ed2a0c7f28b89e3 (diff) | |
download | urwid-master.tar.gz |
* 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 <alekseis@nvidia.com>
Diffstat (limited to 'urwid/tests/test_widget.py')
-rw-r--r-- | urwid/tests/test_widget.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/urwid/tests/test_widget.py b/urwid/tests/test_widget.py index 4ea2944..9da2abb 100644 --- a/urwid/tests/test_widget.py +++ b/urwid/tests/test_widget.py @@ -1,10 +1,23 @@ from __future__ import annotations +import contextlib import unittest +from collections.abc import Generator import urwid +@contextlib.contextmanager +def encoding(encoding_name: str) -> Generator[None, None, None]: + old_encoding = 'ascii' # Default fallback value + try: + old_encoding = urwid.util._target_encoding + urwid.set_encoding(encoding_name) + yield + finally: + urwid.set_encoding(old_encoding) + + class TextTest(unittest.TestCase): def setUp(self): self.t = urwid.Text("I walk the\ncity in the night") @@ -33,10 +46,10 @@ class TextTest(unittest.TestCase): assert got == expected, f"got: {got!r} expected: {expected!r}" def test5_encode_error(self): - urwid.set_encoding("ascii") - expected = [b"? "] - got = urwid.Text('û').render((3,))._text - assert got == expected, f"got: {got!r} expected: {expected!r}" + with encoding("ascii"): + expected = [b"? "] + got = urwid.Text('û').render((3,))._text + assert got == expected, f"got: {got!r} expected: {expected!r}" class EditTest(unittest.TestCase): @@ -87,12 +100,12 @@ class EditTest(unittest.TestCase): self.ktest(self.t3,'down','down',15,"down at bottom") def test_utf8_input(self): - urwid.set_encoding("utf-8") - self.t1.set_edit_text('') - self.t1.keypress((12,), 'û') - self.assertEqual(self.t1.edit_text, 'û'.encode()) - self.t4.keypress((12,), 'û') - self.assertEqual(self.t4.edit_text, 'û') + with encoding("utf-8"): + self.t1.set_edit_text('') + self.t1.keypress((12,), 'û') + self.assertEqual(self.t1.edit_text, 'û'.encode()) + self.t4.keypress((12,), 'û') + self.assertEqual(self.t4.edit_text, 'û') class EditRenderTest(unittest.TestCase): |