From 29c5ac71bc3da35ed631719a43af4c45652d62aa Mon Sep 17 00:00:00 2001 From: wim glenn Date: Wed, 29 Aug 2018 22:58:04 -0500 Subject: [PATCH 1/5] improve line width estimate --- setup.py | 2 +- src/_pytest/terminal.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 6207ad09b..a3125611f 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def get_environment_marker_support_level(): def main(): extras_require = {} install_requires = [ - "py>=1.5.0", + "py>=1.6.0", "six>=1.10.0", "setuptools", "attrs>=17.4.0", diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 746d08c47..48c652bd0 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -413,7 +413,7 @@ class TerminalReporter(object): self._write_progress_information_filling_space() else: past_edge = ( - self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1 + self._tw.width_of_current_line + self._PROGRESS_LENGTH + 1 >= self._screen_width ) if past_edge: @@ -433,10 +433,8 @@ class TerminalReporter(object): def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() - fill = " " * ( - self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1 - ) - self.write(fill + msg, cyan=True) + fill = self._tw.fullwidth - self._tw.width_of_current_line - 1 + self.write(msg.rjust(fill), cyan=True) def pytest_collection(self): if not self.isatty and self.config.option.verbose >= 1: From ed4b94a180412a292c9fe7e65faabbeb01f5f49c Mon Sep 17 00:00:00 2001 From: wim glenn Date: Wed, 29 Aug 2018 23:57:24 -0500 Subject: [PATCH 2/5] add changelog entry --- changelog/3911.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3911.bugfix.rst diff --git a/changelog/3911.bugfix.rst b/changelog/3911.bugfix.rst new file mode 100644 index 000000000..1185c2304 --- /dev/null +++ b/changelog/3911.bugfix.rst @@ -0,0 +1 @@ +the terminal writer now takes into account unicode character width when writing out progress From c18a5b5179f724e7046742bae60da51dc74469d4 Mon Sep 17 00:00:00 2001 From: wim glenn Date: Thu, 30 Aug 2018 19:06:20 -0500 Subject: [PATCH 3/5] try to be backwards compat --- setup.py | 2 +- src/_pytest/terminal.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index a3125611f..6207ad09b 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def get_environment_marker_support_level(): def main(): extras_require = {} install_requires = [ - "py>=1.6.0", + "py>=1.5.0", "six>=1.10.0", "setuptools", "attrs>=17.4.0", diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 48c652bd0..9fbae49c4 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -412,10 +412,12 @@ class TerminalReporter(object): if last_item: self._write_progress_information_filling_space() else: - past_edge = ( - self._tw.width_of_current_line + self._PROGRESS_LENGTH + 1 - >= self._screen_width - ) + try: + w = self._tw.width_of_current_line + except AttributeError: + # py < 1.6.0 + w = self._tw.chars_on_current_line + past_edge = w + self._PROGRESS_LENGTH + 1 >= self._screen_width if past_edge: msg = self._get_progress_information_message() self._tw.write(msg + "\n", cyan=True) @@ -433,7 +435,12 @@ class TerminalReporter(object): def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() - fill = self._tw.fullwidth - self._tw.width_of_current_line - 1 + try: + w = self._tw.width_of_current_line + except AttributeError: + # py < 1.6.0 + w = self._tw.chars_on_current_line + fill = self._tw.fullwidth - w - 1 self.write(msg.rjust(fill), cyan=True) def pytest_collection(self): From 96aad2983b590c10a87f4cde6cbb0a9f08f9937b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Aug 2018 21:16:35 -0300 Subject: [PATCH 4/5] Move code to get width of current line to a function --- setup.py | 2 +- src/_pytest/terminal.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 6207ad09b..4c12fbfcc 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def get_environment_marker_support_level(): def main(): extras_require = {} install_requires = [ - "py>=1.5.0", + "py>=1.5.0", # if py gets upgrade to >=1.6, remove _width_of_current_line in terminal.py "six>=1.10.0", "setuptools", "attrs>=17.4.0", diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 9fbae49c4..53083961d 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -412,11 +412,7 @@ class TerminalReporter(object): if last_item: self._write_progress_information_filling_space() else: - try: - w = self._tw.width_of_current_line - except AttributeError: - # py < 1.6.0 - w = self._tw.chars_on_current_line + w = self._width_of_current_line past_edge = w + self._PROGRESS_LENGTH + 1 >= self._screen_width if past_edge: msg = self._get_progress_information_message() @@ -435,14 +431,19 @@ class TerminalReporter(object): def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() - try: - w = self._tw.width_of_current_line - except AttributeError: - # py < 1.6.0 - w = self._tw.chars_on_current_line + w = self._width_of_current_line fill = self._tw.fullwidth - w - 1 self.write(msg.rjust(fill), cyan=True) + @property + def _width_of_current_line(self): + """Return the width of current line, using the superior implementation of py-1.6 when available""" + try: + return self._tw.width_of_current_line + except AttributeError: + # py < 1.6.0 + return self._tw.chars_on_current_line + def pytest_collection(self): if not self.isatty and self.config.option.verbose >= 1: self.write("collecting ... ", bold=True) From 19fa01b91dc5289c82cc2c7dfd971eebc39cf28a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Aug 2018 21:17:14 -0300 Subject: [PATCH 5/5] Tweak changelog --- changelog/3911.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/3911.bugfix.rst b/changelog/3911.bugfix.rst index 1185c2304..8839fe7d9 100644 --- a/changelog/3911.bugfix.rst +++ b/changelog/3911.bugfix.rst @@ -1 +1 @@ -the terminal writer now takes into account unicode character width when writing out progress +Terminal writer now takes into account unicode character width when writing out progress.