Commit e8debf39 authored by Stephen Warren's avatar Stephen Warren Committed by Simon Glass

test/py: use " for docstrings

Python's coding style docs indicate to use " not ' for docstrings.

test/py has other violations of the coding style docs, since the docs
specify a stranger style than I would expect, but nobody has complained
about those yet:-)
Signed-off-by: default avatarStephen Warren <swarren@nvidia.com>
Reviewed-by: default avatarSimon Glass <sjg@chromium.org>
parent 56382a81
......@@ -29,7 +29,7 @@ log = None
console = None
def mkdir_p(path):
'''Create a directory path.
"""Create a directory path.
This includes creating any intermediate/parent directories. Any errors
caused due to already extant directories are ignored.
......@@ -39,7 +39,7 @@ def mkdir_p(path):
Returns:
Nothing.
'''
"""
try:
os.makedirs(path)
......@@ -50,14 +50,14 @@ def mkdir_p(path):
raise
def pytest_addoption(parser):
'''pytest hook: Add custom command-line options to the cmdline parser.
"""pytest hook: Add custom command-line options to the cmdline parser.
Args:
parser: The pytest command-line parser.
Returns:
Nothing.
'''
"""
parser.addoption('--build-dir', default=None,
help='U-Boot build directory (O=)')
......@@ -73,14 +73,14 @@ def pytest_addoption(parser):
help='Compile U-Boot before running tests')
def pytest_configure(config):
'''pytest hook: Perform custom initialization at startup time.
"""pytest hook: Perform custom initialization at startup time.
Args:
config: The pytest configuration.
Returns:
Nothing.
'''
"""
global log
global console
......@@ -190,7 +190,7 @@ def pytest_configure(config):
console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
def pytest_generate_tests(metafunc):
'''pytest hook: parameterize test functions based on custom rules.
"""pytest hook: parameterize test functions based on custom rules.
If a test function takes parameter(s) (fixture names) of the form brd__xxx
or env__xxx, the brd and env configuration dictionaries are consulted to
......@@ -202,7 +202,7 @@ def pytest_generate_tests(metafunc):
Returns:
Nothing.
'''
"""
subconfigs = {
'brd': console.config.brd,
......@@ -229,14 +229,14 @@ def pytest_generate_tests(metafunc):
@pytest.fixture(scope='function')
def u_boot_console(request):
'''Generate the value of a test's u_boot_console fixture.
"""Generate the value of a test's u_boot_console fixture.
Args:
request: The pytest request.
Returns:
The fixture value.
'''
"""
console.ensure_spawned()
return console
......@@ -247,7 +247,7 @@ tests_skipped = set()
tests_passed = set()
def pytest_itemcollected(item):
'''pytest hook: Called once for each test found during collection.
"""pytest hook: Called once for each test found during collection.
This enables our custom result analysis code to see the list of all tests
that should eventually be run.
......@@ -257,12 +257,12 @@ def pytest_itemcollected(item):
Returns:
Nothing.
'''
"""
tests_not_run.add(item.name)
def cleanup():
'''Clean up all global state.
"""Clean up all global state.
Executed (via atexit) once the entire test process is complete. This
includes logging the status of all tests, and the identity of any failed
......@@ -273,7 +273,7 @@ def cleanup():
Returns:
Nothing.
'''
"""
if console:
console.close()
......@@ -295,7 +295,7 @@ def cleanup():
atexit.register(cleanup)
def setup_boardspec(item):
'''Process any 'boardspec' marker for a test.
"""Process any 'boardspec' marker for a test.
Such a marker lists the set of board types that a test does/doesn't
support. If tests are being executed on an unsupported board, the test is
......@@ -306,7 +306,7 @@ def setup_boardspec(item):
Returns:
Nothing.
'''
"""
mark = item.get_marker('boardspec')
if not mark:
......@@ -323,7 +323,7 @@ def setup_boardspec(item):
pytest.skip('board not supported')
def setup_buildconfigspec(item):
'''Process any 'buildconfigspec' marker for a test.
"""Process any 'buildconfigspec' marker for a test.
Such a marker lists some U-Boot configuration feature that the test
requires. If tests are being executed on an U-Boot build that doesn't
......@@ -334,7 +334,7 @@ def setup_buildconfigspec(item):
Returns:
Nothing.
'''
"""
mark = item.get_marker('buildconfigspec')
if not mark:
......@@ -344,7 +344,7 @@ def setup_buildconfigspec(item):
pytest.skip('.config feature not enabled')
def pytest_runtest_setup(item):
'''pytest hook: Configure (set up) a test item.
"""pytest hook: Configure (set up) a test item.
Called once for each test to perform any custom configuration. This hook
is used to skip the test if certain conditions apply.
......@@ -354,14 +354,14 @@ def pytest_runtest_setup(item):
Returns:
Nothing.
'''
"""
log.start_section(item.name)
setup_boardspec(item)
setup_buildconfigspec(item)
def pytest_runtest_protocol(item, nextitem):
'''pytest hook: Called to execute a test.
"""pytest hook: Called to execute a test.
This hook wraps the standard pytest runtestprotocol() function in order
to acquire visibility into, and record, each test function's result.
......@@ -372,7 +372,7 @@ def pytest_runtest_protocol(item, nextitem):
Returns:
A list of pytest reports (test result data).
'''
"""
reports = runtestprotocol(item, nextitem=nextitem)
failed = None
......
This diff is collapsed.
......@@ -9,7 +9,7 @@
# command prompt.
def test_version(u_boot_console):
'''Test that the "version" command prints the U-Boot version.'''
"""Test that the "version" command prints the U-Boot version."""
# "version" prints the U-Boot sign-on message. This is usually considered
# an error, so that any unexpected reboot causes an error. Here, this
......
......@@ -12,7 +12,7 @@ import os.path
import pytest
import u_boot_utils
'''
"""
Note: This test relies on:
a) boardenv_* to contain configuration values to define which USB ports are
......@@ -44,7 +44,7 @@ ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNELS=="3-13", MODE:="66
(You may wish to change the group ID instead of setting the permissions wide
open. All that matters is that the user ID running the test can access the
device.)
'''
"""
# The set of file sizes to test. These values trigger various edge-cases such
# as one less than, equal to, and one greater than typical USB max packet
......@@ -71,7 +71,7 @@ first_usb_dev_port = None
@pytest.mark.buildconfigspec('cmd_dfu')
def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
'''Test the "dfu" command; the host system must be able to enumerate a USB
"""Test the "dfu" command; the host system must be able to enumerate a USB
device when "dfu" is running, various DFU transfers are tested, and the
USB device must disappear when "dfu" is aborted.
......@@ -86,10 +86,10 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
def start_dfu():
'''Start U-Boot's dfu shell command.
"""Start U-Boot's dfu shell command.
This also waits for the host-side USB enumeration process to complete.
......@@ -98,7 +98,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
fh = u_boot_utils.attempt_to_open_file(
env__usb_dev_port['host_usb_dev_node'])
......@@ -120,7 +120,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
fh.close()
def stop_dfu(ignore_errors):
'''Stop U-Boot's dfu shell command from executing.
"""Stop U-Boot's dfu shell command from executing.
This also waits for the host-side USB de-enumeration process to
complete.
......@@ -133,7 +133,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
try:
u_boot_console.log.action(
......@@ -148,7 +148,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
raise
def run_dfu_util(alt_setting, fn, up_dn_load_arg):
'''Invoke dfu-util on the host.
"""Invoke dfu-util on the host.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
......@@ -159,7 +159,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
cmd = ['dfu-util', '-a', str(alt_setting), up_dn_load_arg, fn]
if 'host_usb_port_path' in env__usb_dev_port:
......@@ -168,7 +168,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
u_boot_console.wait_for('Ctrl+C to exit ...')
def dfu_write(alt_setting, fn):
'''Write a file to the target board using DFU.
"""Write a file to the target board using DFU.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
......@@ -177,12 +177,12 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
run_dfu_util(alt_setting, fn, '-D')
def dfu_read(alt_setting, fn):
'''Read a file from the target board using DFU.
"""Read a file from the target board using DFU.
Args:
alt_setting: The DFU "alternate setting" identifier to interact
......@@ -191,7 +191,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
# dfu-util fails reads/uploads if the host file already exists
if os.path.exists(fn):
......@@ -199,7 +199,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
run_dfu_util(alt_setting, fn, '-U')
def dfu_write_read_check(size):
'''Test DFU transfers of a specific size of data
"""Test DFU transfers of a specific size of data
This function first writes data to the board then reads it back and
compares the written and read back data. Measures are taken to avoid
......@@ -210,7 +210,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Returns:
Nothing.
'''
"""
test_f = u_boot_utils.PersistentRandomFile(u_boot_console,
'dfu_%d.bin' % size, size)
......
......@@ -10,34 +10,34 @@ import pytest
# FIXME: This might be useful for other tests;
# perhaps refactor it into ConsoleBase or some other state object?
class StateTestEnv(object):
'''Container that represents the state of all U-Boot environment variables.
"""Container that represents the state of all U-Boot environment variables.
This enables quick determination of existant/non-existant variable
names.
'''
"""
def __init__(self, u_boot_console):
'''Initialize a new StateTestEnv object.
"""Initialize a new StateTestEnv object.
Args:
u_boot_console: A U-Boot console.
Returns:
Nothing.
'''
"""
self.u_boot_console = u_boot_console
self.get_env()
self.set_var = self.get_non_existent_var()
def get_env(self):
'''Read all current environment variables from U-Boot.
"""Read all current environment variables from U-Boot.
Args:
None.
Returns:
Nothing.
'''
"""
response = self.u_boot_console.run_command('printenv')
self.env = {}
......@@ -48,27 +48,27 @@ class StateTestEnv(object):
self.env[var] = value
def get_existent_var(self):
'''Return the name of an environment variable that exists.
"""Return the name of an environment variable that exists.
Args:
None.
Returns:
The name of an environment variable.
'''
"""
for var in self.env:
return var
def get_non_existent_var(self):
'''Return the name of an environment variable that does not exist.
"""Return the name of an environment variable that does not exist.
Args:
None.
Returns:
The name of an environment variable.
'''
"""
n = 0
while True:
......@@ -80,7 +80,7 @@ class StateTestEnv(object):
ste = None
@pytest.fixture(scope='function')
def state_test_env(u_boot_console):
'''pytest fixture to provide a StateTestEnv object to tests.'''
"""pytest fixture to provide a StateTestEnv object to tests."""
global ste
if not ste:
......@@ -88,7 +88,7 @@ def state_test_env(u_boot_console):
return ste
def unset_var(state_test_env, var):
'''Unset an environment variable.
"""Unset an environment variable.
This both executes a U-Boot shell command and updates a StateTestEnv
object.
......@@ -99,14 +99,14 @@ def unset_var(state_test_env, var):
Returns:
Nothing.
'''
"""
state_test_env.u_boot_console.run_command('setenv %s' % var)
if var in state_test_env.env:
del state_test_env.env[var]
def set_var(state_test_env, var, value):
'''Set an environment variable.
"""Set an environment variable.
This both executes a U-Boot shell command and updates a StateTestEnv
object.
......@@ -118,26 +118,26 @@ def set_var(state_test_env, var, value):
Returns:
Nothing.
'''
"""
state_test_env.u_boot_console.run_command('setenv %s "%s"' % (var, value))
state_test_env.env[var] = value
def validate_empty(state_test_env, var):
'''Validate that a variable is not set, using U-Boot shell commands.
"""Validate that a variable is not set, using U-Boot shell commands.
Args:
var: The variable name to test.
Returns:
Nothing.
'''
"""
response = state_test_env.u_boot_console.run_command('echo $%s' % var)
assert response == ''
def validate_set(state_test_env, var, value):
'''Validate that a variable is set, using U-Boot shell commands.
"""Validate that a variable is set, using U-Boot shell commands.
Args:
var: The variable name to test.
......@@ -145,7 +145,7 @@ def validate_set(state_test_env, var, value):
Returns:
Nothing.
'''
"""
# echo does not preserve leading, internal, or trailing whitespace in the
# value. printenv does, and hence allows more complete testing.
......@@ -153,20 +153,20 @@ def validate_set(state_test_env, var, value):
assert response == ('%s=%s' % (var, value))
def test_env_echo_exists(state_test_env):
'''Test echoing a variable that exists.'''
"""Test echoing a variable that exists."""
var = state_test_env.get_existent_var()
value = state_test_env.env[var]
validate_set(state_test_env, var, value)
def test_env_echo_non_existent(state_test_env):
'''Test echoing a variable that doesn't exist.'''
"""Test echoing a variable that doesn't exist."""
var = state_test_env.set_var
validate_empty(state_test_env, var)
def test_env_printenv_non_existent(state_test_env):
'''Test printenv error message for non-existant variables.'''
"""Test printenv error message for non-existant variables."""
var = state_test_env.set_var
c = state_test_env.u_boot_console
......@@ -175,14 +175,14 @@ def test_env_printenv_non_existent(state_test_env):
assert(response == '## Error: "%s" not defined' % var)
def test_env_unset_non_existent(state_test_env):
'''Test unsetting a nonexistent variable.'''
"""Test unsetting a nonexistent variable."""
var = state_test_env.get_non_existent_var()
unset_var(state_test_env, var)
validate_empty(state_test_env, var)
def test_env_set_non_existent(state_test_env):
'''Test set a non-existant variable.'''
"""Test set a non-existant variable."""
var = state_test_env.set_var
value = 'foo'
......@@ -190,7 +190,7 @@ def test_env_set_non_existent(state_test_env):
validate_set(state_test_env, var, value)
def test_env_set_existing(state_test_env):
'''Test setting an existant variable.'''
"""Test setting an existant variable."""
var = state_test_env.set_var
value = 'bar'
......@@ -198,14 +198,14 @@ def test_env_set_existing(state_test_env):
validate_set(state_test_env, var, value)
def test_env_unset_existing(state_test_env):
'''Test unsetting a variable.'''
"""Test unsetting a variable."""
var = state_test_env.set_var
unset_var(state_test_env, var)
validate_empty(state_test_env, var)
def test_env_expansion_spaces(state_test_env):
'''Test expanding a variable that contains a space in its value.'''
"""Test expanding a variable that contains a space in its value."""
var_space = None
var_test = None
......
......@@ -4,6 +4,6 @@
# SPDX-License-Identifier: GPL-2.0
def test_help(u_boot_console):
'''Test that the "help" command can be executed.'''
"""Test that the "help" command can be executed."""
u_boot_console.run_command('help')
......@@ -95,7 +95,7 @@ subtests = (
)
def exec_hush_if(u_boot_console, expr, result):
'''Execute a shell "if" command, and validate its result.'''
"""Execute a shell "if" command, and validate its result."""
cmd = 'if ' + expr + '; then echo true; else echo false; fi'
response = u_boot_console.run_command(cmd)
......@@ -103,7 +103,7 @@ def exec_hush_if(u_boot_console, expr, result):
@pytest.mark.buildconfigspec('sys_hush_parser')
def test_hush_if_test_setup(u_boot_console):
'''Set up environment variables used during the "if" tests.'''
"""Set up environment variables used during the "if" tests."""
u_boot_console.run_command('setenv ut_var_nonexistent')
u_boot_console.run_command('setenv ut_var_exists 1')
......@@ -111,13 +111,13 @@ def test_hush_if_test_setup(u_boot_console):
@pytest.mark.buildconfigspec('sys_hush_parser')
@pytest.mark.parametrize('expr,result', subtests)
def test_hush_if_test(u_boot_console, expr, result):
'''Test a single "if test" condition.'''
"""Test a single "if test" condition."""
exec_hush_if(u_boot_console, expr, result)
@pytest.mark.buildconfigspec('sys_hush_parser')
def test_hush_if_test_teardown(u_boot_console):
'''Clean up environment variables used during the "if" tests.'''
"""Clean up environment variables used during the "if" tests."""
u_boot_console.run_command('setenv ut_var_exists')
......@@ -126,7 +126,7 @@ def test_hush_if_test_teardown(u_boot_console):
# Of those, only UMS currently allows file removal though.
@pytest.mark.boardspec('sandbox')
def test_hush_if_test_host_file_exists(u_boot_console):
'''Test the "if test -e" shell command.'''
"""Test the "if test -e" shell command."""
test_file = u_boot_console.config.result_dir + \
'/creating_this_file_breaks_u_boot_tests'
......
......@@ -8,8 +8,8 @@ import u_boot_utils
@pytest.mark.buildconfigspec('cmd_memory')
def test_md(u_boot_console):
'''Test that md reads memory as expected, and that memory can be modified
using the mw command.'''
"""Test that md reads memory as expected, and that memory can be modified
using the mw command."""
ram_base = u_boot_utils.find_ram_base(u_boot_console)
addr = '%08x' % ram_base
......@@ -24,8 +24,8 @@ def test_md(u_boot_console):
@pytest.mark.buildconfigspec('cmd_memory')
def test_md_repeat(u_boot_console):
'''Test command repeat (via executing an empty command) operates correctly
for "md"; the command must repeat and dump an incrementing address.'''
"""Test command repeat (via executing an empty command) operates correctly
for "md"; the command must repeat and dump an incrementing address."""
ram_base = u_boot_utils.find_ram_base(u_boot_console)
addr_base = '%08x' % ram_base
......
......@@ -8,7 +8,7 @@
import pytest
import u_boot_utils
'''
"""
Note: This test relies on boardenv_* containing configuration values to define
which the network environment available for testing. Without this, this test
will be automatically skipped.
......@@ -46,16 +46,16 @@ env__net_tftp_readable_file = {
"size": 5058624,
"crc32": "c2244b26",
}
'''
"""
net_set_up = False
def test_net_pre_commands(u_boot_console):
'''Execute any commands required to enable network hardware.
"""Execute any commands required to enable network hardware.
These commands are provided by the boardenv_* file; see the comment at the
beginning of this file.
'''
"""
init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
if init_usb:
......@@ -67,11 +67,11 @@ def test_net_pre_commands(u_boot_console):
@pytest.mark.buildconfigspec('cmd_dhcp')
def test_net_dhcp(u_boot_console):
'''Test the dhcp command.
"""Test the dhcp command.
The boardenv_* file may be used to enable/disable this test; see the
comment at the beginning of this file.
'''
"""
test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
......@@ -86,11 +86,11 @@ def test_net_dhcp(u_boot_console):
@pytest.mark.buildconfigspec('net')
def test_net_setup_static(u_boot_console):
'''Set up a static IP configuration.
"""Set up a static IP configuration.
The configuration is provided by the boardenv_* file; see the comment at
the beginning of this file.
'''
"""
env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
if not env_vars:
......@@ -104,12 +104,12 @@ def test_net_setup_static(u_boot_console):
@pytest.mark.buildconfigspec('cmd_ping')
def test_net_ping(u_boot_console):
'''Test the ping command.
"""Test the ping command.
The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
is pinged. The test validates that the host is alive, as reported by the
ping command's output.
'''
"""
if not net_set_up:
pytest.skip("Network not initialized")
......@@ -119,14 +119,14 @@ def test_net_ping(u_boot_console):
@pytest.mark.buildconfigspec('cmd_net')
def test_net_tftpboot(u_boot_console):
'''Test the tftpboot command.
"""Test the tftpboot command.
A file is downloaded from the TFTP server, its size and optionally its
CRC32 are validated.
The details of the file to download are provided by the boardenv_* file;
see the comment at the beginning of this file.
'''
"""
if not net_set_up:
pytest.skip("Network not initialized")
......
......@@ -9,14 +9,14 @@ import signal
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('reset')
def test_reset(u_boot_console):
'''Test that the "reset" command exits sandbox process.'''
"""Test that the "reset" command exits sandbox process."""
u_boot_console.run_command('reset', wait_for_prompt=False)
assert(u_boot_console.validate_exited())
@pytest.mark.boardspec('sandbox')
def test_ctrl_c(u_boot_console):
'''Test that sending SIGINT to sandbox causes it to exit.'''
"""Test that sending SIGINT to sandbox causes it to exit."""
u_boot_console.kill(signal.SIGINT)
assert(u_boot_console.validate_exited())
......@@ -5,13 +5,13 @@
# Test basic shell functionality, such as commands separate by semi-colons.
def test_shell_execute(u_boot_console):
'''Test any shell command.'''
"""Test any shell command."""
response = u_boot_console.run_command('echo hello')
assert response.strip() == 'hello'
def test_shell_semicolon_two(u_boot_console):
'''Test two shell commands separate by a semi-colon.'''
"""Test two shell commands separate by a semi-colon."""
cmd = 'echo hello; echo world'
response = u_boot_console.run_command(cmd)
......@@ -19,8 +19,8 @@ def test_shell_semicolon_two(u_boot_console):
assert response.index('hello') < response.index('world')
def test_shell_semicolon_three(u_boot_console):
'''Test three shell commands separate by a semi-colon, with variable
expansion dependencies between them.'''
"""Test three shell commands separate by a semi-colon, with variable
expansion dependencies between them."""
cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
'echo ${list}'
......@@ -29,7 +29,7 @@ def test_shell_semicolon_three(u_boot_console):
u_boot_console.run_command('setenv list')
def test_shell_run(u_boot_console):
'''Test the "run" shell command.'''
"""Test the "run" shell command."""
u_boot_console.run_command('setenv foo \"setenv monty 1; setenv python 2\"')
u_boot_console.run_command('run foo')
......
......@@ -6,8 +6,8 @@ import pytest
import time
def test_sleep(u_boot_console):
'''Test the sleep command, and validate that it sleeps for approximately
the correct amount of time.'''
"""Test the sleep command, and validate that it sleeps for approximately
the correct amount of time."""
# 3s isn't too long, but is enough to cross a few second boundaries.
sleep_time = 3
......
......@@ -14,7 +14,7 @@ import re
import time
import u_boot_utils
'''
"""
Note: This test relies on:
a) boardenv_* to contain configuration values to define which USB ports are
......@@ -69,11 +69,11 @@ root permissions. For example: