提交 e1b21e2d 编写于 作者: C Cleber Rosa

FDDrainer: pass text to loggers

The FDDrainer reads from process output and write to loggers.  The
test log, which is intended for humans, can indeed try to treat it as
text.  The stream logger, on the other hand, should deal with data as
binary content *only*, but this will be handled on a future change.

By having text content passed to the loggers, we avoid the occurrence
of log lines that look like:

  [stdout] b'command output'

Or output files (job-YYYY-MM-DDTHH.MM-id/tests/<test>/output) that
may literally contain:

  b'command output'

The encoding used is the one specified at the command execution.  With
this fix, a number of tests on Python 3 can now run successfully.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 6a104b45
...@@ -380,18 +380,20 @@ class FDDrainer(object): ...@@ -380,18 +380,20 @@ class FDDrainer(object):
bfr += tmp bfr += tmp
if tmp.endswith(b'\n'): if tmp.endswith(b'\n'):
for line in bfr.splitlines(): for line in bfr.splitlines():
line = astring.to_text(line, self._result.encoding)
if self._logger is not None: if self._logger is not None:
self._logger.debug(self._logger_prefix, line) self._logger.debug(self._logger_prefix, line)
if self._stream_logger is not None: if self._stream_logger is not None:
self._stream_logger.debug('%s\n', line) self._stream_logger.debug(line)
bfr = b'' bfr = b''
# Write the rest of the bfr unfinished by \n # Write the rest of the bfr unfinished by \n
if self._verbose and bfr: if self._verbose and bfr:
for line in bfr.splitlines(): for line in bfr.splitlines():
line = astring.to_text(line, self._result.encoding)
if self._logger is not None: if self._logger is not None:
self._logger.debug(self._logger_prefix, line) self._logger.debug(self._logger_prefix, line)
if self._stream_logger is not None: if self._stream_logger is not None:
self._stream_logger.debug(line) self._stream_logger.debug(astring.to_text(line))
def start(self): def start(self):
self._thread = threading.Thread(target=self._drainer, name=self.name) self._thread = threading.Thread(target=self._drainer, name=self.name)
......
...@@ -607,8 +607,6 @@ class RunnerHumanOutputTest(unittest.TestCase): ...@@ -607,8 +607,6 @@ class RunnerHumanOutputTest(unittest.TestCase):
b'INTERRUPT 0 | CANCEL 1', b'INTERRUPT 0 | CANCEL 1',
result.stdout) result.stdout)
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
@unittest.skipIf(not GNU_ECHO_BINARY, @unittest.skipIf(not GNU_ECHO_BINARY,
'GNU style echo binary not available') 'GNU style echo binary not available')
def test_ugly_echo_cmd(self): def test_ugly_echo_cmd(self):
......
...@@ -329,8 +329,6 @@ class LoaderTestFunctional(unittest.TestCase): ...@@ -329,8 +329,6 @@ class LoaderTestFunctional(unittest.TestCase):
self.assertEqual(test, 11, "Number of tests is not 12 (%s):\n%s" self.assertEqual(test, 11, "Number of tests is not 12 (%s):\n%s"
% (test, result)) % (test, result))
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_python_unittest(self): def test_python_unittest(self):
test_path = os.path.join(basedir, "selftests", ".data", "unittests.py") test_path = os.path.join(basedir, "selftests", ".data", "unittests.py")
cmd = ("%s run --sysinfo=off --job-results-dir %s --json - -- %s" cmd = ("%s run --sysinfo=off --job-results-dir %s --json - -- %s"
......
...@@ -2,7 +2,6 @@ import json ...@@ -2,7 +2,6 @@ import json
import os import os
import re import re
import shutil import shutil
import sys
import tempfile import tempfile
import unittest import unittest
from xml.dom import minidom from xml.dom import minidom
...@@ -163,8 +162,6 @@ class OutputTest(unittest.TestCase): ...@@ -163,8 +162,6 @@ class OutputTest(unittest.TestCase):
"Libc double free can be seen in avocado " "Libc double free can be seen in avocado "
"doublefree output:\n%s" % output) "doublefree output:\n%s" % output)
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_print_to_std(self): def test_print_to_std(self):
def _check_output(path, exps, name): def _check_output(path, exps, name):
i = 0 i = 0
...@@ -249,8 +246,6 @@ class OutputTest(unittest.TestCase): ...@@ -249,8 +246,6 @@ class OutputTest(unittest.TestCase):
with open(output_file_path, 'r') as output: with open(output_file_path, 'r') as output:
self.assertEqual(output.read(), '') self.assertEqual(output.read(), '')
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_check_on_off(self): def test_check_on_off(self):
""" """
Checks that output will always be kept, but it will only make into Checks that output will always be kept, but it will only make into
......
import json import json
import os import os
import shutil import shutil
import sys
import tempfile import tempfile
import unittest import unittest
...@@ -139,8 +138,6 @@ class RunnerSimpleTest(unittest.TestCase): ...@@ -139,8 +138,6 @@ class RunnerSimpleTest(unittest.TestCase):
(expected_rc, result)) (expected_rc, result))
self.assertIn(tampered_msg, result.stdout) self.assertIn(tampered_msg, result.stdout)
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_output_diff(self): def test_output_diff(self):
self._check_output_record_all() self._check_output_record_all()
tampered_msg_stdout = b"I PITY THE FOOL THAT STANDS ON STDOUT!" tampered_msg_stdout = b"I PITY THE FOOL THAT STANDS ON STDOUT!"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册