diff options
author | Ran Benita <ran@unusedvar.com> | 2020-05-26 14:59:16 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-05-26 17:14:01 +0300 |
commit | aca534c67dea7eb0fcddf194bc64d65bc3e07c8b (patch) | |
tree | 511634fe07169a2996a4d807f9f2665d4edfeeb2 /testing/test_terminal.py | |
parent | 54ae27f081b9d7d164d880d9cbce842cc477772a (diff) | |
download | pytest-aca534c67dea7eb0fcddf194bc64d65bc3e07c8b.tar.gz |
Improve our own wcwidth implementation and remove dependency on wcwidth package
`TerminalWriter`, imported recently from `py`, contains its own
incomplete wcwidth (`char_with`/`get_line_width`) implementation. The
`TerminalReporter` also needs this, but uses the external `wcwidth`
package.
This commit brings the `TerminalWriter` implementation up-to-par with
`wcwidth`, moves to implementation to a new file `_pytest._io.wcwidth`
which is used everywhere, and removes the dependency.
The differences compared to the `wcwidth` package are:
- Normalizes the string before counting.
- Uses Python's `unicodedata` instead of vendored Unicode tables. This
means the data corresponds to the Python's version Unicode version
instead of the `wcwidth`'s package version.
- Apply some optimizations.
Diffstat (limited to 'testing/test_terminal.py')
-rw-r--r-- | testing/test_terminal.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 0f5b4cb68..17fd29238 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -14,7 +14,9 @@ import pluggy import py import _pytest.config +import _pytest.terminal import pytest +from _pytest._io.wcwidth import wcswidth from _pytest.config import ExitCode from _pytest.pytester import Testdir from _pytest.reports import BaseReport @@ -2027,9 +2029,6 @@ def test_skip_reasons_folding(): def test_line_with_reprcrash(monkeypatch): - import _pytest.terminal - from wcwidth import wcswidth - mocked_verbose_word = "FAILED" mocked_pos = "some::nodeid" @@ -2079,19 +2078,19 @@ def test_line_with_reprcrash(monkeypatch): check("some\nmessage", 80, "FAILED some::nodeid - some") # Test unicode safety. - check("😄😄😄😄😄\n2nd line", 25, "FAILED some::nodeid - ...") - check("😄😄😄😄😄\n2nd line", 26, "FAILED some::nodeid - ...") - check("😄😄😄😄😄\n2nd line", 27, "FAILED some::nodeid - 😄...") - check("😄😄😄😄😄\n2nd line", 28, "FAILED some::nodeid - 😄...") - check("😄😄😄😄😄\n2nd line", 29, "FAILED some::nodeid - 😄😄...") + check("🉐🉐🉐🉐🉐\n2nd line", 25, "FAILED some::nodeid - ...") + check("🉐🉐🉐🉐🉐\n2nd line", 26, "FAILED some::nodeid - ...") + check("🉐🉐🉐🉐🉐\n2nd line", 27, "FAILED some::nodeid - 🉐...") + check("🉐🉐🉐🉐🉐\n2nd line", 28, "FAILED some::nodeid - 🉐...") + check("🉐🉐🉐🉐🉐\n2nd line", 29, "FAILED some::nodeid - 🉐🉐...") # NOTE: constructed, not sure if this is supported. - mocked_pos = "nodeid::😄::withunicode" - check("😄😄😄😄😄\n2nd line", 29, "FAILED nodeid::😄::withunicode") - check("😄😄😄😄😄\n2nd line", 40, "FAILED nodeid::😄::withunicode - 😄😄...") - check("😄😄😄😄😄\n2nd line", 41, "FAILED nodeid::😄::withunicode - 😄😄...") - check("😄😄😄😄😄\n2nd line", 42, "FAILED nodeid::😄::withunicode - 😄😄😄...") - check("😄😄😄😄😄\n2nd line", 80, "FAILED nodeid::😄::withunicode - 😄😄😄😄😄") + mocked_pos = "nodeid::🉐::withunicode" + check("🉐🉐🉐🉐🉐\n2nd line", 29, "FAILED nodeid::🉐::withunicode") + check("🉐🉐🉐🉐🉐\n2nd line", 40, "FAILED nodeid::🉐::withunicode - 🉐🉐...") + check("🉐🉐🉐🉐🉐\n2nd line", 41, "FAILED nodeid::🉐::withunicode - 🉐🉐...") + check("🉐🉐🉐🉐🉐\n2nd line", 42, "FAILED nodeid::🉐::withunicode - 🉐🉐🉐...") + check("🉐🉐🉐🉐🉐\n2nd line", 80, "FAILED nodeid::🉐::withunicode - 🉐🉐🉐🉐🉐") @pytest.mark.parametrize( |