diff options
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/multiplexed_log.py | 14 | ||||
-rw-r--r-- | test/py/tests/test_efi_loader.py | 10 | ||||
-rw-r--r-- | test/py/tests/test_efi_selftest.py | 6 | ||||
-rw-r--r-- | test/py/u_boot_console_exec_attach.py | 6 | ||||
-rw-r--r-- | test/py/u_boot_console_sandbox.py | 4 | ||||
-rw-r--r-- | test/py/u_boot_spawn.py | 26 | ||||
-rw-r--r-- | test/py/u_boot_utils.py | 25 |
7 files changed, 49 insertions, 42 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. diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py index fc8d6b8655..85473a9049 100644 --- a/test/py/tests/test_efi_loader.py +++ b/test/py/tests/test_efi_loader.py @@ -6,9 +6,6 @@ # Test efi loader implementation -import pytest -import u_boot_utils - """ Note: This test relies on boardenv_* containing configuration values to define which network environment is available for testing. Without this, the parts @@ -50,6 +47,9 @@ env__efi_loader_helloworld_file = { } """ +import pytest +import u_boot_utils + net_set_up = False def test_efi_pre_commands(u_boot_console): @@ -80,7 +80,7 @@ def test_efi_setup_dhcp(u_boot_console): env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None) if not env_vars: pytest.skip('No DHCP server available') - return None + return u_boot_console.run_command('setenv autoload no') output = u_boot_console.run_command('dhcp') @@ -193,7 +193,7 @@ def test_efi_grub_net(u_boot_console): check_smbios = u_boot_console.config.env.get('env__efi_loader_check_smbios', False) if check_smbios: u_boot_console.wait_for('grub>') - output = u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False) + u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False) u_boot_console.wait_for('SMBIOS') # Then exit cleanly diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index 63218efbc2..0161a6ea24 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -73,8 +73,7 @@ def test_efi_selftest_text_input(u_boot_console): This function calls the text input EFI selftest. """ u_boot_console.run_command(cmd='setenv efi_selftest text input') - output = u_boot_console.run_command(cmd='bootefi selftest', - wait_for_prompt=False) + u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) m = u_boot_console.p.expect([r'To terminate type \'x\'']) if m != 0: raise Exception('No prompt for \'text input\' test') @@ -143,8 +142,7 @@ def test_efi_selftest_text_input_ex(u_boot_console): This function calls the extended text input EFI selftest. """ u_boot_console.run_command(cmd='setenv efi_selftest extended text input') - output = u_boot_console.run_command(cmd='bootefi selftest', - wait_for_prompt=False) + u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']) if m != 0: raise Exception('No prompt for \'text input\' test') 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 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 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) 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 |