From e1b21e2d7fd87b9dd1a47b09d7d175909d295db5 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Fri, 20 Apr 2018 16:24:37 -0400 Subject: [PATCH] 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//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: Cleber Rosa --- avocado/utils/process.py | 6 ++++-- selftests/functional/test_basic.py | 2 -- selftests/functional/test_loader.py | 2 -- selftests/functional/test_output.py | 5 ----- selftests/functional/test_output_check.py | 3 --- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 788a31df..06e7343d 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -380,18 +380,20 @@ class FDDrainer(object): bfr += tmp if tmp.endswith(b'\n'): for line in bfr.splitlines(): + line = astring.to_text(line, self._result.encoding) if self._logger is not None: self._logger.debug(self._logger_prefix, line) if self._stream_logger is not None: - self._stream_logger.debug('%s\n', line) + self._stream_logger.debug(line) bfr = b'' # Write the rest of the bfr unfinished by \n if self._verbose and bfr: for line in bfr.splitlines(): + line = astring.to_text(line, self._result.encoding) if self._logger is not None: self._logger.debug(self._logger_prefix, line) if self._stream_logger is not None: - self._stream_logger.debug(line) + self._stream_logger.debug(astring.to_text(line)) def start(self): self._thread = threading.Thread(target=self._drainer, name=self.name) diff --git a/selftests/functional/test_basic.py b/selftests/functional/test_basic.py index f1ddba0d..50b06fae 100644 --- a/selftests/functional/test_basic.py +++ b/selftests/functional/test_basic.py @@ -607,8 +607,6 @@ class RunnerHumanOutputTest(unittest.TestCase): b'INTERRUPT 0 | CANCEL 1', result.stdout) - @unittest.skipIf(sys.version_info[0] == 3, - "Test currently broken on Python 3") @unittest.skipIf(not GNU_ECHO_BINARY, 'GNU style echo binary not available') def test_ugly_echo_cmd(self): diff --git a/selftests/functional/test_loader.py b/selftests/functional/test_loader.py index 182cb9b3..770d08e5 100644 --- a/selftests/functional/test_loader.py +++ b/selftests/functional/test_loader.py @@ -329,8 +329,6 @@ class LoaderTestFunctional(unittest.TestCase): self.assertEqual(test, 11, "Number of tests is not 12 (%s):\n%s" % (test, result)) - @unittest.skipIf(sys.version_info[0] == 3, - "Test currently broken on Python 3") def test_python_unittest(self): test_path = os.path.join(basedir, "selftests", ".data", "unittests.py") cmd = ("%s run --sysinfo=off --job-results-dir %s --json - -- %s" diff --git a/selftests/functional/test_output.py b/selftests/functional/test_output.py index 554da3d7..016703a0 100644 --- a/selftests/functional/test_output.py +++ b/selftests/functional/test_output.py @@ -2,7 +2,6 @@ import json import os import re import shutil -import sys import tempfile import unittest from xml.dom import minidom @@ -163,8 +162,6 @@ class OutputTest(unittest.TestCase): "Libc double free can be seen in avocado " "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 _check_output(path, exps, name): i = 0 @@ -249,8 +246,6 @@ class OutputTest(unittest.TestCase): with open(output_file_path, 'r') as output: self.assertEqual(output.read(), '') - @unittest.skipIf(sys.version_info[0] == 3, - "Test currently broken on Python 3") def test_check_on_off(self): """ Checks that output will always be kept, but it will only make into diff --git a/selftests/functional/test_output_check.py b/selftests/functional/test_output_check.py index 987cd9f4..fda9cfff 100644 --- a/selftests/functional/test_output_check.py +++ b/selftests/functional/test_output_check.py @@ -1,7 +1,6 @@ import json import os import shutil -import sys import tempfile import unittest @@ -139,8 +138,6 @@ class RunnerSimpleTest(unittest.TestCase): (expected_rc, result)) self.assertIn(tampered_msg, result.stdout) - @unittest.skipIf(sys.version_info[0] == 3, - "Test currently broken on Python 3") def test_output_diff(self): self._check_output_record_all() tampered_msg_stdout = b"I PITY THE FOOL THAT STANDS ON STDOUT!" -- GitLab