All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv3 06/13] test/py: Manual python3 fixes
Date: Thu, 24 Oct 2019 11:59:21 -0400	[thread overview]
Message-ID: <20191024155928.28616-7-trini@konsulko.com> (raw)
In-Reply-To: <20191024155928.28616-1-trini@konsulko.com>

- Modern pytest is more visible in telling us about parameters that we
  had not described, so describe a few more.
- ConfigParser.readfp(...) is now configparser.read_file(...)
- As part of the "strings vs bytes" conversions in Python 3, we use the
  default encoding/decoding of utf-8 but in some places tell Python to
  replace problematic conversions rather than throw a fatal error.
- Fix a typo noticed while doing the above ("tot he" -> "to the").
- As suggested by Stephen, re-alphabetize the import list
- Per Heinrich, replace how we write contents in test_fit.py

Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Simon Glass <sjg@chromium.org> [on sandbox]
Signed-off-by: Tom Rini <trini@konsulko.com>
---
Changes in v3:
- Switch to single quotes not double quotes, per Stephen
- Switch to a Python 3.5.x happy subprocess and decode set of
  statements, also from Stephen
---
 test/py/conftest.py        |  9 ++++-----
 test/py/multiplexed_log.py | 11 ++++++++---
 test/py/pytest.ini         |  3 +++
 test/py/tests/test_fit.py  |  4 ++--
 test/py/u_boot_spawn.py    |  4 ++--
 5 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/test/py/conftest.py b/test/py/conftest.py
index 5c19af1d5034..bffee6b8a3a2 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -13,17 +13,16 @@
 # - Implementing custom pytest markers.
 
 import atexit
+import configparser
 import errno
+import io
 import os
 import os.path
 import pytest
-from _pytest.runner import runtestprotocol
 import re
-import io
+from _pytest.runner import runtestprotocol
 import sys
 
-import configparser
-
 # Globals: The HTML log file, and the connection to the U-Boot console.
 log = None
 console = None
@@ -168,7 +167,7 @@ def pytest_configure(config):
             ini_str = '[root]\n' + f.read()
             ini_sio = io.StringIO(ini_str)
             parser = configparser.RawConfigParser()
-            parser.readfp(ini_sio)
+            parser.read_file(ini_sio)
             ubconfig.buildconfig.update(parser.items('root'))
 
     ubconfig.test_py_dir = test_py_dir
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index de0aacc659b8..545a77430223 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -51,7 +51,7 @@ class LogfileStream(object):
         """Write data to the log stream.
 
         Args:
-            data: The data to write tot he file.
+            data: The data to write to the file.
             implicit: Boolean indicating whether data actually appeared in the
                 stream, or was implicitly generated. A valid use-case is to
                 repeat a shell prompt at the start of each separate log
@@ -64,7 +64,8 @@ class LogfileStream(object):
 
         self.logfile.write(self, data, implicit)
         if self.chained_file:
-            self.chained_file.write(data)
+            # Chained file is console, convert things a little
+            self.chained_file.write((data.encode('ascii', 'replace')).decode())
 
     def flush(self):
         """Flush the log stream, to ensure correct log interleaving.
@@ -136,6 +137,10 @@ class RunAndLog(object):
             p = subprocess.Popen(cmd, cwd=cwd,
                 stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
             (stdout, stderr) = p.communicate()
+            if stdout is not None:
+                stdout = stdout.decode('utf-8')
+            if stderr is not None:
+                stderr = stderr.decode('utf-8')
             output = ''
             if stdout:
                 if stderr:
@@ -215,7 +220,7 @@ class Logfile(object):
             Nothing.
         """
 
-        self.f = open(fn, 'wt')
+        self.f = open(fn, 'wt', encoding='utf-8')
         self.last_stream = None
         self.blocks = []
         self.cur_evt = 1
diff --git a/test/py/pytest.ini b/test/py/pytest.ini
index 7e400682bf25..e93d010f1fa2 100644
--- a/test/py/pytest.ini
+++ b/test/py/pytest.ini
@@ -8,3 +8,6 @@
 markers =
     boardspec: U-Boot: Describes the set of boards a test can/can't run on.
     buildconfigspec: U-Boot: Describes Kconfig/config-header constraints.
+    notbuildconfigspec: U-Boot: Describes required disabled Kconfig options.
+    requiredtool: U-Boot: Required host tools for a test.
+    slow: U-Boot: Specific test will run slowly.
diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
index 4922b9dcc664..356d9a20f299 100755
--- a/test/py/tests/test_fit.py
+++ b/test/py/tests/test_fit.py
@@ -153,7 +153,7 @@ def test_fit(u_boot_console):
         src = make_fname('u-boot.dts')
         dtb = make_fname('u-boot.dtb')
         with open(src, 'w') as fd:
-            print(base_fdt, file=fd)
+            fd.write(base_fdt)
         util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb])
         return dtb
 
@@ -186,7 +186,7 @@ def test_fit(u_boot_console):
         its = make_its(params)
         util.run_and_log(cons, [mkimage, '-f', its, fit])
         with open(make_fname('u-boot.dts'), 'w') as fd:
-            print(base_fdt, file=fd)
+            fd.write(base_fdt)
         return fit
 
     def make_kernel(filename, text):
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
index b011a3e3da25..4f898cdefe5a 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/u_boot_spawn.py
@@ -113,7 +113,7 @@ class Spawn(object):
             Nothing.
         """
 
-        os.write(self.fd, data)
+        os.write(self.fd, data.encode(errors='replace'))
 
     def expect(self, patterns):
         """Wait for the sub-process to emit specific data.
@@ -171,7 +171,7 @@ class Spawn(object):
                 events = self.poll.poll(poll_maxwait)
                 if not events:
                     raise Timeout()
-                c = os.read(self.fd, 1024)
+                c = os.read(self.fd, 1024).decode(errors='replace')
                 if not c:
                     raise EOFError()
                 if self.logfile_read:
-- 
2.17.1

  parent reply	other threads:[~2019-10-24 15:59 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 20:53 [U-Boot] [PATCH 00/10] Moving test/py to Python 3 Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 01/10] gitlab-ci: Fix indentation in some stanzas Tom Rini
2019-10-21 15:25   ` Simon Glass
2019-10-18 20:53 ` [U-Boot] [PATCH 02/10] gitlab-ci: Prepend to PATH rather than overwrite it Tom Rini
2019-10-21 15:25   ` Simon Glass
2019-10-18 20:53 ` [U-Boot] [PATCH 03/10] test/py: Fix pytest4 deprecation warnings Tom Rini
2019-10-21 15:25   ` Simon Glass
2019-10-21 15:51     ` Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 04/10] test/py: Automated conversion to Python 3 Tom Rini
2019-10-18 21:12   ` Stephen Warren
2019-10-18 22:08     ` Tom Rini
2019-10-19  5:25   ` Heinrich Schuchardt
2019-10-19  6:13     ` [U-Boot] [RFC v2 4/10] " Heinrich Schuchardt
2019-10-19 11:22       ` Tom Rini
2019-10-19 12:16     ` [U-Boot] [PATCH 04/10] " Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 05/10] test/py: Split mark to multiple lines Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 06/10] test/py: test_ut.py: Ensure we use bytes Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 07/10] test/py: Manual python3 fixes Tom Rini
2019-10-19  6:33   ` Heinrich Schuchardt
2019-10-18 20:53 ` [U-Boot] [PATCH 08/10] WORKAROUND: gitlab-ci: Rework how and when we use virtualenv in order to have python3 Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 09/10] WORKAROUND: test/py: Skip fs tests for now Tom Rini
2019-10-18 21:16   ` Stephen Warren
2019-10-18 22:07     ` Tom Rini
2019-10-18 20:53 ` [U-Boot] [PATCH 10/10] HACK: test.py: Disable EFI " Tom Rini
2019-10-18 21:17   ` Stephen Warren
2019-10-18 21:18 ` [U-Boot] [PATCH 00/10] Moving test/py to Python 3 Stephen Warren
2019-10-23  3:19 ` [U-Boot] [PATCHv2 00/13] " Tom Rini
2019-10-23  3:19   ` [U-Boot] [PATCHv2 01/13] gitlab-ci: Fix indentation in some stanzas Tom Rini
2019-10-23  3:19   ` [U-Boot] [PATCHv2 02/13] gitlab-ci: Prepend to PATH rather than replace it Tom Rini
2019-10-23  3:20   ` [U-Boot] [PATCHv2 03/13] test/py: Split mark to multiple lines Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 04/13] test/py: Fix pytest4 deprecation warnings Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 05/13] test/py: Automated conversion to Python 3 Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 06/13] test/py: Manual python3 fixes Tom Rini
2019-10-23 18:50     ` Stephen Warren
2019-10-23 19:01       ` Tom Rini
2019-10-23 19:27         ` Stephen Warren
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 07/13] test/py: test_ut.py: Ensure we use bytes Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 08/13] test/py: test_efi_selftest.py: Updates for python 3 support Tom Rini
2019-10-23 16:47     ` Stephen Warren
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 09/13] test/py: Update test_fs to decode check_output calls Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 10/13] test/py: Rework test.py to be a different kind of wrapper Tom Rini
2019-10-23 16:55     ` Stephen Warren
2019-10-23 16:58       ` Tom Rini
2019-10-23 17:03         ` Stephen Warren
2019-10-23 17:12           ` Tom Rini
2019-10-23 17:29             ` Stephen Warren
2019-10-23 18:04               ` Stephen Warren
2019-10-23 18:17                 ` Tom Rini
2019-10-23 21:11                   ` Stephen Warren
2019-10-23 21:37                     ` Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 11/13] test/py: Update docs, add requirements.txt for pip Tom Rini
2019-10-23 18:30     ` Stephen Warren
2019-10-23 18:49       ` Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 12/13] gitlab/travis: Rework how and when we use virtualenv in order to use python3 Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-23  3:20   ` [U-Boot] [PATCHv2 13/13] test/py: Use raw strings more to avoid deprecation warnings Tom Rini
2019-10-24  0:59     ` Simon Glass
2019-10-24 15:59   ` [U-Boot] [PATCHv3 00/13] Moving test/py to Python 3 Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 01/13] gitlab-ci: Fix indentation in some stanzas Tom Rini
2019-11-01 13:31       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 02/13] gitlab-ci: Prepend to PATH rather than replace it Tom Rini
2019-11-01 13:31       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 03/13] test/py: Split mark to multiple lines Tom Rini
2019-11-01 13:31       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 04/13] test/py: Fix pytest4 deprecation warnings Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 05/13] test/py: Automated conversion to Python 3 Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` Tom Rini [this message]
2019-11-01 13:32       ` [U-Boot] [PATCHv3 06/13] test/py: Manual python3 fixes Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 07/13] test/py: test_ut.py: Ensure we use bytes Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 08/13] test/py: test_efi_selftest.py: Updates for python 3 support Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 09/13] test/py: Update test_fs to decode check_output calls Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 10/13] test/py: Rework test.py to be a different kind of wrapper Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 11/13] test/py: Update docs, add requirements.txt for pip Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 12/13] gitlab/travis: Rework how and when we use virtualenv in order to use python3 Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 15:59     ` [U-Boot] [PATCHv3 13/13] test/py: Use raw strings more to avoid deprecation warnings Tom Rini
2019-11-01 13:32       ` Tom Rini
2019-10-24 16:01     ` [U-Boot] [PATCH 1/2] Dockerfile: Update to latest bionic tag Tom Rini
2019-10-24 16:01       ` [U-Boot] [PATCH 2/2] Dockerfile: Add python3-pip Tom Rini
2019-10-30 17:02         ` Tom Rini
2019-10-30 17:02       ` [U-Boot] [PATCH 1/2] Dockerfile: Update to latest bionic tag Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191024155928.28616-7-trini@konsulko.com \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.