[PATCH 0/5] test: fix pylint warnings

Fix pylint warning like:
* missing docstring * incorrect indentation * don't inherit from object * unused variable
Heinrich Schuchardt (5): test: fix pylint errors in multiplexed_log.py test: fix pylint errors in u_boot_spawn.py test: fix pylint errors in u_boot_utils.py test: fix pylint error in u_boot_console_sandbox.py test: fix pylint error in u_boot_console_exec_attach.py
test/py/multiplexed_log.py | 14 ++++++++------ test/py/u_boot_console_exec_attach.py | 6 ++++-- test/py/u_boot_console_sandbox.py | 4 +++- test/py/u_boot_spawn.py | 26 +++++++++++++------------- test/py/u_boot_utils.py | 25 ++++++++++++++----------- 5 files changed, 42 insertions(+), 33 deletions(-)

* don't inherit from object * remove superfluous comprehension * add module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/multiplexed_log.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 545a774302..442edada12 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -2,8 +2,10 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Generate an HTML-formatted log file containing multiple streams of data, -# each represented in a well-delineated/-structured fashion. +""" +Generate an HTML-formatted log file containing multiple streams of data, +each represented in a well-delineated/-structured fashion. +"""
import datetime import html @@ -178,7 +180,7 @@ class RunAndLog(object): raise exception return output
-class SectionCtxMgr(object): +class SectionCtxMgr: """A context manager for Python's "with" statement, which allows a certain portion of test code to be logged to a separate section of the log file. Objects of this type should be created by factory functions in the Logfile @@ -206,7 +208,7 @@ class SectionCtxMgr(object): def __exit__(self, extype, value, traceback): self.log.end_section(self.marker)
-class Logfile(object): +class Logfile: """Generates an HTML-formatted log file containing multiple streams of data, each represented in a well-delineated/-structured fashion."""
@@ -320,8 +322,8 @@ $(document).ready(function () { # The set of characters that should be represented as hexadecimal codes in # the log file. _nonprint = {ord('%')} - _nonprint.update({c for c in range(0, 32) if c not in (9, 10)}) - _nonprint.update({c for c in range(127, 256)}) + _nonprint.update(c for c in range(0, 32) if c not in (9, 10)) + _nonprint.update(range(127, 256))
def _escape(self, data): """Render data format suitable for inclusion in an HTML document.

On Mon, 22 Nov 2021 at 16:02, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
- don't inherit from object
- remove superfluous comprehension
- add module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/multiplexed_log.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

* don't inherit from object * imports should be on the top level * avoid unused variable names * avoid unnecessary else after raise
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/u_boot_spawn.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index e34cb217e8..7c48d96210 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -1,7 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to spawn a sub-process and interact with its stdio. +""" +Logic to spawn a sub-process and interact with its stdio. +"""
import os import re @@ -9,12 +11,12 @@ import pty import signal import select import time +import traceback
class Timeout(Exception): """An exception sub-class that indicates that a timeout occurred.""" - pass
-class Spawn(object): +class Spawn: """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for.
@@ -58,14 +60,14 @@ class Spawn(object): os.execvp(args[0], args) except: print('CHILD EXECEPTION:') - import traceback traceback.print_exc() finally: os._exit(255)
try: self.poll = select.poll() - self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL) + self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | + select.POLLHUP | select.POLLNVAL) except: self.close() raise @@ -106,7 +108,7 @@ class Spawn(object): elif os.WIFSIGNALED(status): signum = os.WTERMSIG(status) self.exit_code = -signum - self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum)) + self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum).name) self.waited = True return False, self.exit_code, self.exit_info
@@ -196,13 +198,11 @@ class Spawn(object): # shouldn't and explain why. This is much more friendly than # just dying with an I/O error if err.errno == 5: # Input/output error - alive, exit_code, info = self.checkalive() + alive, _, info = self.checkalive() if alive: - raise - else: - raise ValueError('U-Boot exited with %s' % info) - else: - raise + raise err + raise ValueError('U-Boot exited with %s' % info) + raise err if self.logfile_read: self.logfile_read.write(c) self.buf += c @@ -227,7 +227,7 @@ class Spawn(object): """
os.close(self.fd) - for i in range(100): + for _ in range(100): if not self.isalive(): break time.sleep(0.1)

On Mon, 22 Nov 2021 at 16:02, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
- don't inherit from object
- imports should be on the top level
- avoid unused variable names
- avoid unnecessary else after raise
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/u_boot_spawn.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

* there is no os.path.unlink() method * don't inherit from object * add module docstring * move imports to the top * avoid unused variable
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/u_boot_utils.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index e816c7fbb6..089eda5434 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -1,17 +1,20 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
-# Utility code shared across multiple tests. +""" +Utility code shared across multiple tests. +"""
import hashlib import inspect import os import os.path -import pytest +import pathlib import signal import sys import time import re +import pytest
def md5sum_data(data): """Calculate the MD5 hash of some data. @@ -48,7 +51,7 @@ def md5sum_file(fn, max_length=None): data = fh.read(*params) return md5sum_data(data)
-class PersistentRandomFile(object): +class PersistentRandomFile: """Generate and store information about a persistent file containing random data."""
@@ -144,7 +147,7 @@ def wait_until_file_open_fails(fn, ignore_errors): Nothing. """
- for i in range(100): + for _ in range(100): fh = attempt_to_open_file(fn) if not fh: return @@ -192,9 +195,9 @@ def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg): try: runner = u_boot_console.log.get_runner(cmd[0], sys.stdout) runner.run(cmd) - except Exception as e: - assert(retcode == runner.exit_status) - assert(msg in runner.output) + except Exception: + assert retcode == runner.exit_status + assert msg in runner.output else: raise Exception("Expected an exception with retcode %d message '%s'," "but it was not raised" % (retcode, msg)) @@ -279,17 +282,17 @@ class PersistentFileHelperCtxMgr(object): if filename_timestamp < self.module_timestamp: self.log.action('Removing stale generated file ' + self.filename) - os.unlink(self.filename) + pathlib.Path(self.filename).unlink()
def __exit__(self, extype, value, traceback): if extype: try: - os.path.unlink(self.filename) - except: + pathlib.Path(self.filename).unlink() + except Exception: pass return logged = False - for i in range(20): + for _ in range(20): filename_timestamp = os.path.getmtime(self.filename) if filename_timestamp > self.module_timestamp: break

On Mon, 22 Nov 2021 at 16:02, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
- there is no os.path.unlink() method
- don't inherit from object
- add module docstring
- move imports to the top
- avoid unused variable
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/u_boot_utils.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

* provide module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/u_boot_console_sandbox.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 836f5a9e2b..7e1eb0e0b4 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -2,7 +2,9 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to interact with the sandbox port of U-Boot, running as a sub-process. +""" +Logic to interact with the sandbox port of U-Boot, running as a sub-process. +"""
import time from u_boot_spawn import Spawn

On Mon, 22 Nov 2021 at 16:02, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
- provide module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/u_boot_console_sandbox.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

* provide module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/u_boot_console_exec_attach.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/py/u_boot_console_exec_attach.py b/test/py/u_boot_console_exec_attach.py index 27834b55cd..8dd8cc1230 100644 --- a/test/py/u_boot_console_exec_attach.py +++ b/test/py/u_boot_console_exec_attach.py @@ -2,8 +2,10 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-# Logic to interact with U-Boot running on real hardware, typically via a -# physical serial port. +""" +Logic to interact with U-Boot running on real hardware, typically via a +physical serial port. +"""
import sys from u_boot_spawn import Spawn

On Mon, 22 Nov 2021 at 16:02, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
- provide module docstring
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/u_boot_console_exec_attach.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
Heinrich Schuchardt
-
Simon Glass