From 07715bfdac3ef2626165dee0a0b936e837bd3fd2 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sun, 26 Jan 2025 21:15:02 +0100 Subject: [PATCH 1/4] Add tests for _pyrepr.utils --- Lib/test/test_pyrepl/test_utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Lib/test/test_pyrepl/test_utils.py diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py new file mode 100644 index 00000000000000..3e350edacc00bb --- /dev/null +++ b/Lib/test/test_pyrepl/test_utils.py @@ -0,0 +1,23 @@ +from unittest import TestCase + +from _pyrepl.utils import str_width, wlen + + +class TestUtils(TestCase): + def test_str_width(self): + characters = ['a', '1', '_', '!', '\x1a', '\u263A', '\uffb9'] + for c in characters: + self.assertEqual(str_width(c), 1) + + characters = [chr(99989), chr(99999)] + for c in characters: + self.assertEqual(str_width(c), 2) + + def test_wlen(self): + for c in ['a', 'b', '1', '!', '_']: + self.assertEqual(wlen(c), 1) + self.assertEqual(wlen('\x1a'), 2) + + self.assertEqual(wlen('hello'), 5) + self.assertEqual(wlen('hello'+'\x1a'), 7) + self.assertEqual(wlen('hello'+'\0x1B'), 9) From 36996782b1ee2ab2a15c5a974567b18af6abbdd4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:18:04 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst diff --git a/Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst b/Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst new file mode 100644 index 00000000000000..09a301faec47ef --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst @@ -0,0 +1 @@ +Add unit tests for pyrepl. From 5ce442a62e60869c35eec35bf766ac5f2760eefd Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 20 Feb 2025 19:28:39 +0100 Subject: [PATCH 3/4] improve test --- Lib/test/test_pyrepl/test_utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py index 3e350edacc00bb..0d59968206a613 100644 --- a/Lib/test/test_pyrepl/test_utils.py +++ b/Lib/test/test_pyrepl/test_utils.py @@ -18,6 +18,10 @@ def test_wlen(self): self.assertEqual(wlen(c), 1) self.assertEqual(wlen('\x1a'), 2) + char_east_asian_width_N = chr(3800) + self.assertEqual(wlen(char_east_asian_width_N), 1) + char_east_asian_width_W = chr(4352) + self.assertEqual(wlen(char_east_asian_width_W), 2) + self.assertEqual(wlen('hello'), 5) - self.assertEqual(wlen('hello'+'\x1a'), 7) - self.assertEqual(wlen('hello'+'\0x1B'), 9) + self.assertEqual(wlen('hello' + '\x1a'), 7) From b17710eeaeb04b1c8e8aaa8717fe4329c8604ac1 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 21 Feb 2025 16:46:33 +0100 Subject: [PATCH 4/4] fix news entry name --- .../2025-01-26-20-17-58.gh-issue-126332.c0wUS-.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst => Tests/2025-01-26-20-17-58.gh-issue-126332.c0wUS-.rst} (100%) diff --git a/Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst b/Misc/NEWS.d/next/Tests/2025-01-26-20-17-58.gh-issue-126332.c0wUS-.rst similarity index 100% rename from Misc/NEWS.d/next/Library/2025-01-26-20-17-58.gh-issue-gh-126332.c0wUS-.rst rename to Misc/NEWS.d/next/Tests/2025-01-26-20-17-58.gh-issue-126332.c0wUS-.rst