Commit 4205b1db authored by Vadim Mazaev's avatar Vadim Mazaev

fix handling new line in tail

parent 253e4576
...@@ -49,10 +49,9 @@ def test_tail(case: Case, tmp_path: Path) -> None: ...@@ -49,10 +49,9 @@ def test_tail(case: Case, tmp_path: Path) -> None:
output = io.BytesIO() output = io.BytesIO()
tail(test_file, lines_amount=case.lines, output=output) tail(test_file, lines_amount=case.lines, output=output)
answer = output.getvalue().decode().split('\n') answer = output.getvalue().splitlines() # universal split handling all the \r\n vs \n
assert answer[-1] == '' lines = [line.decode() for line in answer]
lines = answer[:-1]
assert case.result == lines assert case.result == lines
...@@ -62,10 +61,9 @@ def test_real_log_file() -> None: ...@@ -62,10 +61,9 @@ def test_real_log_file() -> None:
output = io.BytesIO() output = io.BytesIO()
tail(log_file, lines_amount=100, output=output) tail(log_file, lines_amount=100, output=output)
answer = output.getvalue().decode().split('\n') answer = output.getvalue().splitlines()
assert answer[-1] == '' lines = [line.decode() for line in answer]
lines = answer[:-1]
ips = Counter(line.split()[3] for line in lines) ips = Counter(line.split()[3] for line in lines)
handles = Counter(line.split()[5] for line in lines) handles = Counter(line.split()[5] for line in lines)
...@@ -91,6 +89,8 @@ def test_stdout_by_default(capsys: CaptureFixture) -> None: ...@@ -91,6 +89,8 @@ def test_stdout_by_default(capsys: CaptureFixture) -> None:
last_line = '[28/Sep/2019:15:57:03 +0000] py.manytask.org 91.228.178.70 "GET / HTTP/1.1" 200 0.130 8337 "0.128"' last_line = '[28/Sep/2019:15:57:03 +0000] py.manytask.org 91.228.178.70 "GET / HTTP/1.1" 200 0.130 8337 "0.128"'
tail(log_file, lines_amount=10) tail(log_file, lines_amount=10)
# stdout is TextIOWrapper with "universal newlines" enabled
# so splitting should always be done by \n
answer = capsys.readouterr().out.split('\n') answer = capsys.readouterr().out.split('\n')
assert answer[-1] == '' assert answer[-1] == ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment