summaryrefslogtreecommitdiffstats
path: root/contrib/python/wcwidth/py3/tests/test_benchmarks.py
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/python/wcwidth/py3/tests/test_benchmarks.py')
-rw-r--r--contrib/python/wcwidth/py3/tests/test_benchmarks.py86
1 files changed, 84 insertions, 2 deletions
diff --git a/contrib/python/wcwidth/py3/tests/test_benchmarks.py b/contrib/python/wcwidth/py3/tests/test_benchmarks.py
index 80c9be01de6..7afcb2c0a5c 100644
--- a/contrib/python/wcwidth/py3/tests/test_benchmarks.py
+++ b/contrib/python/wcwidth/py3/tests/test_benchmarks.py
@@ -10,8 +10,9 @@ import pytest
# local
import wcwidth
-
-_width_module = sys.modules['wcwidth._width']
+# Access via import to trigger lazy-load on Python 3.15+; on older
+# Python _width is already in sys.modules and this is a no-op.
+import wcwidth._width as _width_module # noqa: E402
def test_wcwidth_ascii(benchmark):
@@ -605,3 +606,84 @@ def test_ljust_udhr_lines(benchmark):
benchmark.pedantic(lambda: [wcwidth.ljust(line, w + 1, UDHR_FILLCHAR)
for line, w in zip(UDHR_LINES, UDHR_WIDTHS)],
rounds=1, iterations=1)
+
+
+_TERM_PROGRAMS = [
+ 'ghostty',
+ 'xterm.js',
+]
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_term_program(benchmark, term_program):
+ """Benchmark wcstwidth() with term_program (ghostty=0 overrides vs xterm.js=237)."""
+ text = 'Hello 世界 😀 café ' * 20
+ benchmark(wcwidth.wcstwidth, text, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_ri_term_program(benchmark, term_program):
+ """Benchmark wcstwidth() with RI flags and term_program."""
+ benchmark(wcwidth.wcstwidth, RI_FLAGS_PAIRED, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_emoji_term_program(benchmark, term_program):
+ """Benchmark wcstwidth() with emoji ZWJ sequences and term_program."""
+ text = '👨\u200d👩\u200d👧\u200d👦' * 20
+ benchmark(wcwidth.wcstwidth, text, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_wide_term_program(benchmark, term_program):
+ """Benchmark wcstwidth() with wide CJK and term_program."""
+ text = 'コンニチハ、セカイ!' * 20
+ benchmark(wcwidth.wcstwidth, text, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_width_term_program(benchmark, term_program):
+ """Benchmark width() with term_program (ghostty=0 overrides vs xterm.js=237)."""
+ text = 'Hello 世界 😀 café ' * 20
+ benchmark(wcwidth.width, text, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_width_ri_term_program(benchmark, term_program):
+ """Benchmark width() with RI flags and term_program."""
+ benchmark(wcwidth.width, RI_FLAGS_PAIRED, term_program=term_program)
+
+
+# VS16/VS15-heavy text to exercise the vs16_narrower/vs15_wider bisearch paths
+_VS16_TEXT = ('\u263A\uFE0F' # WHITE SMILING FACE + VS16
+ '\u2764\uFE0F' # HEAVY BLACK HEART + VS16
+ '\u2600\uFE0F' # BLACK SUN WITH RAYS + VS16
+ '\u2615\uFE0F') * 25 # HOT BEVERAGE + VS16
+
+_VS15_TEXT = ('\u2615\uFE0E' # HOT BEVERAGE + VS15 (wide=2 narrows to 1)
+ '\u231A\uFE0E' # WATCH + VS15 (wide=2 narrows to 1)
+ '\u23F0\uFE0E') * 34 # ALARM CLOCK + VS15 (wide=2 narrows to 1)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_vs16_term_program(benchmark, term_program):
+ """Benchmark wcswidth() with VS16 sequences to exercise vs16_narrower bisearch."""
+ benchmark(wcwidth.wcstwidth, _VS16_TEXT, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_wcstwidth_vs15_term_program(benchmark, term_program):
+ """Benchmark wcswidth() with VS15 sequences to exercise vs15_wider bisearch."""
+ benchmark(wcwidth.wcstwidth, _VS15_TEXT, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_width_vs16_term_program(benchmark, term_program):
+ """Benchmark width() with VS16 sequences to exercise vs16_narrower bisearch."""
+ benchmark(wcwidth.width, _VS16_TEXT, term_program=term_program)
+
+
[email protected]('term_program', _TERM_PROGRAMS)
+def test_width_vs15_term_program(benchmark, term_program):
+ """Benchmark width() with VS15 sequences to exercise vs15_wider bisearch."""
+ benchmark(wcwidth.width, _VS15_TEXT, term_program=term_program)