test/py: Automated conversion to Python 3

Use the 2to3 tool to perform numerous automatic conversions from Python
2 syntax to Python 3.  Also fix whitespace problems that Python 3
catches that Python 2 did not.

Reviewed-by: Stephen Warren <swarren@nvidia.com>
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>
This commit is contained in:
Tom Rini 2019-10-24 11:59:20 -04:00
parent 3c941e048c
commit fe1193e254
8 changed files with 64 additions and 73 deletions

View file

@ -19,13 +19,10 @@ import os.path
import pytest import pytest
from _pytest.runner import runtestprotocol from _pytest.runner import runtestprotocol
import re import re
import StringIO import io
import sys import sys
try: import configparser
import configparser
except:
import ConfigParser as configparser
# Globals: The HTML log file, and the connection to the U-Boot console. # Globals: The HTML log file, and the connection to the U-Boot console.
log = None log = None
@ -169,7 +166,7 @@ def pytest_configure(config):
with open(dot_config, 'rt') as f: with open(dot_config, 'rt') as f:
ini_str = '[root]\n' + f.read() ini_str = '[root]\n' + f.read()
ini_sio = StringIO.StringIO(ini_str) ini_sio = io.StringIO(ini_str)
parser = configparser.RawConfigParser() parser = configparser.RawConfigParser()
parser.readfp(ini_sio) parser.readfp(ini_sio)
ubconfig.buildconfig.update(parser.items('root')) ubconfig.buildconfig.update(parser.items('root'))

View file

@ -5,8 +5,8 @@
# Generate an HTML-formatted log file containing multiple streams of data, # Generate an HTML-formatted log file containing multiple streams of data,
# each represented in a well-delineated/-structured fashion. # each represented in a well-delineated/-structured fashion.
import cgi
import datetime import datetime
import html
import os.path import os.path
import shutil import shutil
import subprocess import subprocess
@ -334,7 +334,7 @@ $(document).ready(function () {
data = data.replace(chr(13), '') data = data.replace(chr(13), '')
data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or
c for c in data) c for c in data)
data = cgi.escape(data) data = html.escape(data)
return data return data
def _terminate_stream(self): def _terminate_stream(self):

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015 Stephen Warren # Copyright (c) 2015 Stephen Warren
@ -7,8 +7,6 @@
# Wrapper script to invoke pytest with the directory name that contains the # Wrapper script to invoke pytest with the directory name that contains the
# U-Boot tests. # U-Boot tests.
from __future__ import print_function
import os import os
import os.path import os.path
import sys import sys

View file

@ -3,8 +3,6 @@
# #
# Sanity check of the FIT handling in U-Boot # Sanity check of the FIT handling in U-Boot
from __future__ import print_function
import os import os
import pytest import pytest
import struct import struct

View file

@ -175,29 +175,29 @@ def test_fpga_load_fail(u_boot_console):
f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load') f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load')
for cmd in ['dump', 'load', 'loadb']: for cmd in ['dump', 'load', 'loadb']:
# missing dev parameter # missing dev parameter
expected = 'fpga: incorrect parameters passed' expected = 'fpga: incorrect parameters passed'
output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr)) output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
#assert expected in output #assert expected in output
assert expected_usage in output assert expected_usage in output
# more parameters - 0 at the end # more parameters - 0 at the end
expected = 'fpga: more parameters passed' expected = 'fpga: more parameters passed'
output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr)) output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
#assert expected in output #assert expected in output
assert expected_usage in output assert expected_usage in output
# 0 address # 0 address
expected = 'fpga: zero fpga_data address' expected = 'fpga: zero fpga_data address'
output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev)) output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
#assert expected in output #assert expected in output
assert expected_usage in output assert expected_usage in output
# 0 filesize # 0 filesize
expected = 'fpga: zero size' expected = 'fpga: zero size'
output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr)) output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
#assert expected in output #assert expected in output
assert expected_usage in output assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga') @pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_echo') @pytest.mark.buildconfigspec('cmd_echo')

View file

@ -508,8 +508,8 @@ def fs_obj_unlink(request, u_boot_config):
# Test Case 2 # Test Case 2
check_call('mkdir %s/dir2' % mount_dir, shell=True) check_call('mkdir %s/dir2' % mount_dir, shell=True)
for i in range(0, 20): for i in range(0, 20):
check_call('mkdir %s/dir2/0123456789abcdef%02x' check_call('mkdir %s/dir2/0123456789abcdef%02x'
% (mount_dir, i), shell=True) % (mount_dir, i), shell=True)
# Test Case 4 # Test Case 4

View file

@ -27,9 +27,9 @@ def test_log(u_boot_console):
""" """
for i in range(max_level): for i in range(max_level):
if mask & 1: if mask & 1:
assert 'log_run() log %d' % i == lines.next() assert 'log_run() log %d' % i == next(lines)
if mask & 3: if mask & 3:
assert 'func() _log %d' % i == lines.next() assert 'func() _log %d' % i == next(lines)
def run_test(testnum): def run_test(testnum):
"""Run a particular test number (the 'log test' command) """Run a particular test number (the 'log test' command)
@ -43,7 +43,7 @@ def test_log(u_boot_console):
output = u_boot_console.run_command('log test %d' % testnum) output = u_boot_console.run_command('log test %d' % testnum)
split = output.replace('\r', '').splitlines() split = output.replace('\r', '').splitlines()
lines = iter(split) lines = iter(split)
assert 'test %d' % testnum == lines.next() assert 'test %d' % testnum == next(lines)
return lines return lines
def test0(): def test0():
@ -88,7 +88,7 @@ def test_log(u_boot_console):
def test10(): def test10():
lines = run_test(10) lines = run_test(10)
for i in range(7): for i in range(7):
assert 'log_test() level %d' % i == lines.next() assert 'log_test() level %d' % i == next(lines)
# TODO(sjg@chromium.org): Consider structuring this as separate tests # TODO(sjg@chromium.org): Consider structuring this as separate tests
cons = u_boot_console cons = u_boot_console

View file

@ -67,41 +67,39 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
for i in range(test_iterations): for i in range(test_iterations):
# Generate random data # Generate random data
cmd = 'random %s %x' % (src_addr, count_bytes) cmd = 'random %s %x' % (src_addr, count_bytes)
response = u_boot_console.run_command(cmd) response = u_boot_console.run_command(cmd)
good_response = '%d bytes filled with random data' % (count_bytes) good_response = '%d bytes filled with random data' % (count_bytes)
assert good_response in response assert good_response in response
# Select MMC device # Select MMC device
cmd = 'mmc dev %d' % devid cmd = 'mmc dev %d' % devid
if is_emmc: if is_emmc:
cmd += ' %d' % partid cmd += ' %d' % partid
response = u_boot_console.run_command(cmd) response = u_boot_console.run_command(cmd)
assert 'no card present' not in response assert 'no card present' not in response
if is_emmc: if is_emmc:
partid_response = "(part %d)" % partid partid_response = "(part %d)" % partid
else: else:
partid_response = "" partid_response = ""
good_response = 'mmc%d%s is current device' % (devid, partid_response) good_response = 'mmc%d%s is current device' % (devid, partid_response)
assert good_response in response assert good_response in response
# Write data # Write data
cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors) cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
response = u_boot_console.run_command(cmd) response = u_boot_console.run_command(cmd)
good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % ( good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
devid, sector, count_sectors, count_sectors) assert good_response in response
assert good_response in response
# Read data # Read data
cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors) cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
response = u_boot_console.run_command(cmd) response = u_boot_console.run_command(cmd)
good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % ( good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
devid, sector, count_sectors, count_sectors) assert good_response in response
assert good_response in response
# Compare src and dst data # Compare src and dst data
cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes) cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
response = u_boot_console.run_command(cmd) response = u_boot_console.run_command(cmd)
good_response = 'Total of %d byte(s) were the same' % (count_bytes) good_response = 'Total of %d byte(s) were the same' % (count_bytes)
assert good_response in response assert good_response in response