Skip to content

Commit d01e871

Browse files
committed
Remove TerminalWriter hack for counting chars
1 parent 8caedc9 commit d01e871

File tree

2 files changed

+2
-66
lines changed

2 files changed

+2
-66
lines changed

_pytest/terminal.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ def __init__(self, config, file=None):
147147
self.reportchars = getreportopt(config)
148148
self.hasmarkup = self.writer.hasmarkup
149149
self.isatty = file.isatty()
150-
self._current_line_chars = 0
151-
self._install_line_chars_tracker()
152150
self._progress_items_reported = 0
153151

154152
@property
@@ -161,28 +159,6 @@ def _tw(self):
161159
stacklevel=2)
162160
return self.writer
163161

164-
@staticmethod
165-
def _new_tw_write(msg, **kw):
166-
terminal_reporter = kw.pop('_terminal_reporter')
167-
original_write = kw.pop('_original_write')
168-
fields = msg.rsplit('\n', 1)
169-
if '\n' in msg:
170-
terminal_reporter._current_line_chars = len(fields[-1])
171-
else:
172-
terminal_reporter._current_line_chars += len(fields[-1])
173-
original_write(msg, **kw)
174-
175-
def _install_line_chars_tracker(self):
176-
"""
177-
178-
:return:
179-
"""
180-
import functools
181-
import weakref
182-
self.writer.write = functools.partial(self._new_tw_write,
183-
_terminal_reporter=weakref.proxy(self),
184-
_original_write=self.writer.write)
185-
186162
def hasopt(self, char):
187163
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
188164
return char in self.reportchars
@@ -329,7 +305,7 @@ def _maybe_write_progress_information(self):
329305
self._write_progress_information_filling_space()
330306
return
331307

332-
past_right_side = self._current_line_chars + self._PROGRESS_LENGTH + 1 >= self._screen_width
308+
past_right_side = self.writer.chars_on_current_line + self._PROGRESS_LENGTH + 1 >= self._screen_width
333309
if past_right_side:
334310
msg = self._get_progress_information_message()
335311
self.writer.line(msg)
@@ -342,7 +318,7 @@ def _get_progress_information_message(self):
342318

343319
def _write_progress_information_filling_space(self):
344320
msg = self._get_progress_information_message()
345-
fill = ' ' * (self.writer.fullwidth - self._current_line_chars - len(msg) - 1)
321+
fill = ' ' * (self.writer.fullwidth - self.writer.chars_on_current_line - len(msg) - 1)
346322
self.write(fill + msg)
347323

348324
def pytest_collection(self):

testing/test_terminal.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -964,43 +964,3 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
964964
testdir.makeini('[pytest]')
965965
result = testdir.runpytest('')
966966
assert 'inifile: tox.ini\n' in result.stdout.str()
967-
968-
969-
def test_new_tw_write():
970-
""" DOCUMENT ME"""
971-
class Dummy:
972-
973-
def __init__(self):
974-
self._current_line_chars = 0
975-
976-
def write(self, *args, **kwargs):
977-
self.args = args
978-
self.kwargs = kwargs
979-
980-
dummy = Dummy()
981-
982-
def write_and_check(s, expected):
983-
TerminalReporter._new_tw_write(s, _terminal_reporter=dummy, _original_write=dummy.write, bold=True)
984-
assert dummy._current_line_chars == expected
985-
assert dummy.args == (s,)
986-
assert dummy.kwargs == {'bold': True}
987-
988-
write_and_check('foo', 3)
989-
write_and_check('bar', 6)
990-
write_and_check('\n', 0)
991-
write_and_check('\n', 0)
992-
write_and_check('\n\n\n', 0)
993-
write_and_check('\nfoo', 3)
994-
write_and_check('\nfbar\nhello', 5)
995-
996-
997-
def test_write_updates_line_chars_count(testdir):
998-
config = testdir.parseconfig()
999-
f = py.io.TextIO()
1000-
tr = TerminalReporter(config, file=f)
1001-
assert tr._current_line_chars == 0
1002-
tr.write('foo')
1003-
assert tr._current_line_chars == 3
1004-
tr.line('bar')
1005-
assert tr._current_line_chars == 0
1006-
assert f.getvalue() == 'foobar\n'

0 commit comments

Comments
 (0)