summaryrefslogtreecommitdiffstats
path: root/test/units/utils
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2022-08-29 16:06:37 +0200
committerGitHub <noreply@github.com>2022-08-29 16:06:37 +0200
commitd8cb9117acf2b7a3624eb3b00df2daa6e97c5ae4 (patch)
treeaa32a12e7be0f44b2c4a9387038b884131d13d4a /test/units/utils
parentNote that `become_user` is required for `runas` (#78603) (diff)
downloadansible-d8cb9117acf2b7a3624eb3b00df2daa6e97c5ae4.tar.xz
ansible-d8cb9117acf2b7a3624eb3b00df2daa6e97c5ae4.zip
Skip test if no there are no problematic chars for wcswidth (#78645)
Diffstat (limited to 'test/units/utils')
-rw-r--r--test/units/utils/test_display.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/test/units/utils/test_display.py b/test/units/utils/test_display.py
index 34e39b6f61..6b1914bb64 100644
--- a/test/units/utils/test_display.py
+++ b/test/units/utils/test_display.py
@@ -6,14 +6,32 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import locale
+import sys
+import unicodedata
from unittest.mock import MagicMock
import pytest
-from ansible.utils.display import Display, get_text_width
+from ansible.utils.display import _LIBC, _MAX_INT, Display, get_text_width
from ansible.utils.multiprocessing import context as multiprocessing_context
+@pytest.fixture
+def problematic_wcswidth_chars():
+ problematic = []
+ try:
+ locale.setlocale(locale.LC_ALL, 'C.UTF-8')
+ except Exception:
+ return problematic
+
+ candidates = set(chr(c) for c in range(sys.maxunicode) if unicodedata.category(chr(c)) == 'Cf')
+ for c in candidates:
+ if _LIBC.wcswidth(c, _MAX_INT) == -1:
+ problematic.append(c)
+
+ return problematic
+
+
def test_get_text_width():
locale.setlocale(locale.LC_ALL, '')
assert get_text_width(u'コンニチハ') == 10
@@ -35,9 +53,11 @@ def test_get_text_width():
pytest.raises(TypeError, get_text_width, b'four')
-def test_get_text_width_no_locale():
+def test_get_text_width_no_locale(problematic_wcswidth_chars):
+ if not problematic_wcswidth_chars:
+ pytest.skip("No problmatic wcswidth chars")
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
- pytest.raises(EnvironmentError, get_text_width, '\U000110cd')
+ pytest.raises(EnvironmentError, get_text_width, problematic_wcswidth_chars[0])
def test_Display_banner_get_text_width(monkeypatch):