diff mbox series

[U-Boot,04/10] test/py: Automated conversion to Python 3

Message ID 20191018205338.14879-5-trini@konsulko.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series Moving test/py to Python 3 | expand

Commit Message

Tom Rini Oct. 18, 2019, 8:53 p.m. UTC
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.

Signed-off-by: Tom Rini <trini@konsulko.com>
---
 test/py/conftest.py               |  9 ++--
 test/py/multiplexed_log.py        |  4 +-
 test/py/test.py                   |  4 +-
 test/py/tests/test_fit.py         |  2 -
 test/py/tests/test_fpga.py        | 46 +++++++++----------
 test/py/tests/test_fs/conftest.py |  4 +-
 test/py/tests/test_log.py         |  8 ++--
 test/py/tests/test_mmc_wr.py      | 74 +++++++++++++++----------------
 8 files changed, 71 insertions(+), 80 deletions(-)

Comments

Stephen Warren Oct. 18, 2019, 9:12 p.m. UTC | #1
On 10/18/19 2:53 PM, Tom Rini wrote:
> 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.

> diff --git a/test/py/conftest.py b/test/py/conftest.py

>   import pytest
>   from _pytest.runner import runtestprotocol
>   import re
> -import StringIO
> +import io
>   import sys

I think that list used to be sorted. IIRC some PEP8 tools complain about 
unsorted import lists.

> -try:
> -    import configparser
> -except:
> -    import ConfigParser as configparser
> +import configparser

Now that this is a plain import statement, let's put it with all the 
others at the appropriate point in the sorted list above.


(Not sure if you want to merge fixes like this into this patch, or put 
them in path 7?)


I didn't validate that the large chunks of code that had TAB->spaces 
conversions didn't change anything other than the indentation whitespace...
Tom Rini Oct. 18, 2019, 10:08 p.m. UTC | #2
On Fri, Oct 18, 2019 at 03:12:06PM -0600, Stephen Warren wrote:
> On 10/18/19 2:53 PM, Tom Rini wrote:
> > 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.
> 
> > diff --git a/test/py/conftest.py b/test/py/conftest.py
> 
> >   import pytest
> >   from _pytest.runner import runtestprotocol
> >   import re
> > -import StringIO
> > +import io
> >   import sys
> 
> I think that list used to be sorted. IIRC some PEP8 tools complain about
> unsorted import lists.
> 
> > -try:
> > -    import configparser
> > -except:
> > -    import ConfigParser as configparser
> > +import configparser
> 
> Now that this is a plain import statement, let's put it with all the others
> at the appropriate point in the sorted list above.
> 
> 
> (Not sure if you want to merge fixes like this into this patch, or put them
> in path 7?)

I'll take care of both of those in patch 7, thanks!
Heinrich Schuchardt Oct. 19, 2019, 5:25 a.m. UTC | #3
On 10/18/19 10:53 PM, Tom Rini wrote:
> 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.
>
> Signed-off-by: Tom Rini <trini@konsulko.com>

This patch breaks

./test/py/test.py --bd=qemu-arm64 --build-dir=. -k=test_efi_

For remediation see below.

> ---
>   test/py/conftest.py               |  9 ++--
>   test/py/multiplexed_log.py        |  4 +-
>   test/py/test.py                   |  4 +-
>   test/py/tests/test_fit.py         |  2 -
>   test/py/tests/test_fpga.py        | 46 +++++++++----------
>   test/py/tests/test_fs/conftest.py |  4 +-
>   test/py/tests/test_log.py         |  8 ++--
>   test/py/tests/test_mmc_wr.py      | 74 +++++++++++++++----------------
>   8 files changed, 71 insertions(+), 80 deletions(-)
>
> diff --git a/test/py/conftest.py b/test/py/conftest.py
> index 30c898b40a0d..5c19af1d5034 100644
> --- a/test/py/conftest.py
> +++ b/test/py/conftest.py
> @@ -19,13 +19,10 @@ import os.path
>   import pytest
>   from _pytest.runner import runtestprotocol
>   import re
> -import StringIO
> +import io
>   import sys
>
> -try:
> -    import configparser
> -except:
> -    import ConfigParser as configparser
> +import configparser
>
>   # Globals: The HTML log file, and the connection to the U-Boot console.
>   log = None
> @@ -169,7 +166,7 @@ def pytest_configure(config):
>
>           with open(dot_config, 'rt') as f:
>               ini_str = '[root]\n' + f.read()
> -            ini_sio = StringIO.StringIO(ini_str)
> +            ini_sio = io.StringIO(ini_str)

This results in an error

INTERNALERROR>   File "/home/user/u-boot/test/py/conftest.py", line 169,
in pytest_configure
INTERNALERROR>     ini_sio = io.StringIO(ini_str)
INTERNALERROR> TypeError: initial_value must be unicode or None, not str

-            ini_sio = io.StringIO(ini_str)
+            ini_sio = io.StringIO(ini_str.decode())

>               parser = configparser.RawConfigParser()
>               parser.readfp(ini_sio)
>               ubconfig.buildconfig.update(parser.items('root'))
> diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
> index 637a3bd257ba..de0aacc659b8 100644
> --- a/test/py/multiplexed_log.py
> +++ b/test/py/multiplexed_log.py
> @@ -5,8 +5,8 @@
>   # Generate an HTML-formatted log file containing multiple streams of data,
>   # each represented in a well-delineated/-structured fashion.
>
> -import cgi
>   import datetime
> +import html
>   import os.path
>   import shutil
>   import subprocess
> @@ -334,7 +334,7 @@ $(document).ready(function () {
>           data = data.replace(chr(13), '')
>           data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or
>                          c for c in data)
> -        data = cgi.escape(data)
> +        data = html.escape(data)
>           return data
>
>       def _terminate_stream(self):
> diff --git a/test/py/test.py b/test/py/test.py
> index a5140945d4b9..0ce1838833f6 100755
> --- a/test/py/test.py
> +++ b/test/py/test.py
> @@ -1,4 +1,4 @@
> -#!/usr/bin/env python2
> +#!/usr/bin/env python3
>   # SPDX-License-Identifier: GPL-2.0
>
>   # Copyright (c) 2015 Stephen Warren
> @@ -7,8 +7,6 @@
>   # Wrapper script to invoke pytest with the directory name that contains the
>   # U-Boot tests.
>
> -from __future__ import print_function
> -
>   import os
>   import os.path
>   import sys
> diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
> index e3210ed43fa4..4922b9dcc664 100755
> --- a/test/py/tests/test_fit.py
> +++ b/test/py/tests/test_fit.py

Please, replace all occurrences of

-            print(base_fdt, file=fd)
+            fd.write(base_fdt)

in this file.

Together with the correction in test/py/conftest.py I now can run

./test/py/test.py --bd=qemu-arm64 --build-dir=. -k=test_efi_

using origin/master + patches 1-4.

Best regards

Heinrich

> @@ -3,8 +3,6 @@
>   #
>   # Sanity check of the FIT handling in U-Boot
>
> -from __future__ import print_function
> -
>   import os
>   import pytest
>   import struct
> diff --git a/test/py/tests/test_fpga.py b/test/py/tests/test_fpga.py
> index e3bb7b41c749..ca7ef8ea40d6 100644
> --- a/test/py/tests/test_fpga.py
> +++ b/test/py/tests/test_fpga.py
> @@ -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')
>
>       for cmd in ['dump', 'load', 'loadb']:
> -	# missing dev parameter
> -	expected = 'fpga: incorrect parameters passed'
> -	output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
> -	#assert expected in output
> -	assert expected_usage in output
> -
> -	# more parameters - 0 at the end
> -	expected = 'fpga: more parameters passed'
> -	output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
> -	#assert expected in output
> -	assert expected_usage in output
> -
> -	# 0 address
> -	expected = 'fpga: zero fpga_data address'
> -	output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
> -	#assert expected in output
> -	assert expected_usage in output
> -
> -	# 0 filesize
> -	expected = 'fpga: zero size'
> -	output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
> -	#assert expected in output
> -	assert expected_usage in output
> +        # missing dev parameter
> +        expected = 'fpga: incorrect parameters passed'
> +        output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
> +        #assert expected in output
> +        assert expected_usage in output
> +
> +        # more parameters - 0 at the end
> +        expected = 'fpga: more parameters passed'
> +        output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
> +        #assert expected in output
> +        assert expected_usage in output
> +
> +        # 0 address
> +        expected = 'fpga: zero fpga_data address'
> +        output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
> +        #assert expected in output
> +        assert expected_usage in output
> +
> +        # 0 filesize
> +        expected = 'fpga: zero size'
> +        output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
> +        #assert expected in output
> +        assert expected_usage in output
>
>   @pytest.mark.buildconfigspec('cmd_fpga')
>   @pytest.mark.buildconfigspec('cmd_echo')
> diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
> index 9324657d2160..354d17672fe4 100644
> --- a/test/py/tests/test_fs/conftest.py
> +++ b/test/py/tests/test_fs/conftest.py
> @@ -508,8 +508,8 @@ def fs_obj_unlink(request, u_boot_config):
>
>           # Test Case 2
>           check_call('mkdir %s/dir2' % mount_dir, shell=True)
> -	for i in range(0, 20):
> -	    check_call('mkdir %s/dir2/0123456789abcdef%02x'
> +        for i in range(0, 20):
> +            check_call('mkdir %s/dir2/0123456789abcdef%02x'
>                                       % (mount_dir, i), shell=True)
>
>           # Test Case 4
> diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
> index cb183444c6fc..75325fad61ad 100644
> --- a/test/py/tests/test_log.py
> +++ b/test/py/tests/test_log.py
> @@ -27,9 +27,9 @@ def test_log(u_boot_console):
>           """
>           for i in range(max_level):
>               if mask & 1:
> -                assert 'log_run() log %d' % i == lines.next()
> +                assert 'log_run() log %d' % i == next(lines)
>               if mask & 3:
> -                assert 'func() _log %d' % i == lines.next()
> +                assert 'func() _log %d' % i == next(lines)
>
>       def run_test(testnum):
>           """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)
>           split = output.replace('\r', '').splitlines()
>           lines = iter(split)
> -        assert 'test %d' % testnum == lines.next()
> +        assert 'test %d' % testnum == next(lines)
>           return lines
>
>       def test0():
> @@ -88,7 +88,7 @@ def test_log(u_boot_console):
>       def test10():
>           lines = run_test(10)
>           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
>       cons = u_boot_console
> diff --git a/test/py/tests/test_mmc_wr.py b/test/py/tests/test_mmc_wr.py
> index 8b18781eac74..2ce79f58e3b1 100644
> --- a/test/py/tests/test_mmc_wr.py
> +++ b/test/py/tests/test_mmc_wr.py
> @@ -65,41 +65,39 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
>
>
>       for i in range(test_iterations):
> -	# Generate random data
> -	cmd = 'random %s %x' % (src_addr, count_bytes)
> -	response = u_boot_console.run_command(cmd)
> -	good_response = '%d bytes filled with random data' % (count_bytes)
> -	assert good_response in response
> -
> -	# Select MMC device
> -	cmd = 'mmc dev %d' % devid
> -	if is_emmc:
> -		cmd += ' %d' % partid
> -	response = u_boot_console.run_command(cmd)
> -	assert 'no card present' not in response
> -	if is_emmc:
> -		partid_response = "(part %d)" % partid
> -	else:
> -		partid_response = ""
> -	good_response = 'mmc%d%s is current device' % (devid, partid_response)
> -	assert good_response in response
> -
> -	# Write data
> -	cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
> -	response = u_boot_console.run_command(cmd)
> -	good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (
> -		devid, sector, count_sectors, count_sectors)
> -	assert good_response in response
> -
> -	# Read data
> -	cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
> -	response = u_boot_console.run_command(cmd)
> -	good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
> -		devid, sector, count_sectors, count_sectors)
> -	assert good_response in response
> -
> -	# Compare src and dst data
> -	cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
> -	response = u_boot_console.run_command(cmd)
> -	good_response = 'Total of %d byte(s) were the same' % (count_bytes)
> -	assert good_response in response
> +        # Generate random data
> +        cmd = 'random %s %x' % (src_addr, count_bytes)
> +        response = u_boot_console.run_command(cmd)
> +        good_response = '%d bytes filled with random data' % (count_bytes)
> +        assert good_response in response
> +
> +        # Select MMC device
> +        cmd = 'mmc dev %d' % devid
> +        if is_emmc:
> +            cmd += ' %d' % partid
> +        response = u_boot_console.run_command(cmd)
> +        assert 'no card present' not in response
> +        if is_emmc:
> +            partid_response = "(part %d)" % partid
> +        else:
> +            partid_response = ""
> +        good_response = 'mmc%d%s is current device' % (devid, partid_response)
> +        assert good_response in response
> +
> +        # Write data
> +        cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
> +        response = u_boot_console.run_command(cmd)
> +        good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
> +        assert good_response in response
> +
> +        # Read data
> +        cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
> +        response = u_boot_console.run_command(cmd)
> +        good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
> +        assert good_response in response
> +
> +        # Compare src and dst data
> +        cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
> +        response = u_boot_console.run_command(cmd)
> +        good_response = 'Total of %d byte(s) were the same' % (count_bytes)
> +        assert good_response in response
>
Tom Rini Oct. 19, 2019, 12:16 p.m. UTC | #4
On Sat, Oct 19, 2019 at 07:25:37AM +0200, Heinrich Schuchardt wrote:
> On 10/18/19 10:53 PM, Tom Rini wrote:
> > 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.
> > 
> > Signed-off-by: Tom Rini <trini@konsulko.com>
> 
> This patch breaks
> 
> ./test/py/test.py --bd=qemu-arm64 --build-dir=. -k=test_efi_
> 
> For remediation see below.
> 
> > ---
> >   test/py/conftest.py               |  9 ++--
> >   test/py/multiplexed_log.py        |  4 +-
> >   test/py/test.py                   |  4 +-
> >   test/py/tests/test_fit.py         |  2 -
> >   test/py/tests/test_fpga.py        | 46 +++++++++----------
> >   test/py/tests/test_fs/conftest.py |  4 +-
> >   test/py/tests/test_log.py         |  8 ++--
> >   test/py/tests/test_mmc_wr.py      | 74 +++++++++++++++----------------
> >   8 files changed, 71 insertions(+), 80 deletions(-)
> > 
> > diff --git a/test/py/conftest.py b/test/py/conftest.py
> > index 30c898b40a0d..5c19af1d5034 100644
> > --- a/test/py/conftest.py
> > +++ b/test/py/conftest.py
> > @@ -19,13 +19,10 @@ import os.path
> >   import pytest
> >   from _pytest.runner import runtestprotocol
> >   import re
> > -import StringIO
> > +import io
> >   import sys
> > 
> > -try:
> > -    import configparser
> > -except:
> > -    import ConfigParser as configparser
> > +import configparser
> > 
> >   # Globals: The HTML log file, and the connection to the U-Boot console.
> >   log = None
> > @@ -169,7 +166,7 @@ def pytest_configure(config):
> > 
> >           with open(dot_config, 'rt') as f:
> >               ini_str = '[root]\n' + f.read()
> > -            ini_sio = StringIO.StringIO(ini_str)
> > +            ini_sio = io.StringIO(ini_str)
> 
> This results in an error
> 
> INTERNALERROR>   File "/home/user/u-boot/test/py/conftest.py", line 169,
> in pytest_configure
> INTERNALERROR>     ini_sio = io.StringIO(ini_str)
> INTERNALERROR> TypeError: initial_value must be unicode or None, not str
> 
> -            ini_sio = io.StringIO(ini_str)
> +            ini_sio = io.StringIO(ini_str.decode())

With the whole series applied:
INTERNALERROR> AttributeError: 'str' object has no attribute 'decode'

> >               parser = configparser.RawConfigParser()
> >               parser.readfp(ini_sio)
> >               ubconfig.buildconfig.update(parser.items('root'))
> > diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
> > index 637a3bd257ba..de0aacc659b8 100644
> > --- a/test/py/multiplexed_log.py
> > +++ b/test/py/multiplexed_log.py
> > @@ -5,8 +5,8 @@
> >   # Generate an HTML-formatted log file containing multiple streams of data,
> >   # each represented in a well-delineated/-structured fashion.
> > 
> > -import cgi
> >   import datetime
> > +import html
> >   import os.path
> >   import shutil
> >   import subprocess
> > @@ -334,7 +334,7 @@ $(document).ready(function () {
> >           data = data.replace(chr(13), '')
> >           data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or
> >                          c for c in data)
> > -        data = cgi.escape(data)
> > +        data = html.escape(data)
> >           return data
> > 
> >       def _terminate_stream(self):
> > diff --git a/test/py/test.py b/test/py/test.py
> > index a5140945d4b9..0ce1838833f6 100755
> > --- a/test/py/test.py
> > +++ b/test/py/test.py
> > @@ -1,4 +1,4 @@
> > -#!/usr/bin/env python2
> > +#!/usr/bin/env python3
> >   # SPDX-License-Identifier: GPL-2.0
> > 
> >   # Copyright (c) 2015 Stephen Warren
> > @@ -7,8 +7,6 @@
> >   # Wrapper script to invoke pytest with the directory name that contains the
> >   # U-Boot tests.
> > 
> > -from __future__ import print_function
> > -
> >   import os
> >   import os.path
> >   import sys
> > diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
> > index e3210ed43fa4..4922b9dcc664 100755
> > --- a/test/py/tests/test_fit.py
> > +++ b/test/py/tests/test_fit.py
> 
> Please, replace all occurrences of
> 
> -            print(base_fdt, file=fd)
> +            fd.write(base_fdt)
> 
> in this file.
> 
> Together with the correction in test/py/conftest.py I now can run
> 
> ./test/py/test.py --bd=qemu-arm64 --build-dir=. -k=test_efi_
> 
> using origin/master + patches 1-4.

Wait, sorry.  You need to have everything applied.  A partial conversion
to python3 doesn't work, there's other changes needed and then show the
EFI problem I hit.

That said, if you re-work what I do in my patch #7 to get our input
generally encoded to fix the "doing str stuff on byte object" problems
and EFI is still happy in the end and we only have the pytest warnings
to fix, I'm fine with that.  I'm not a python expert and am happy to
take the fixes in another direction.  Thanks!
diff mbox series

Patch

diff --git a/test/py/conftest.py b/test/py/conftest.py
index 30c898b40a0d..5c19af1d5034 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -19,13 +19,10 @@  import os.path
 import pytest
 from _pytest.runner import runtestprotocol
 import re
-import StringIO
+import io
 import sys
 
-try:
-    import configparser
-except:
-    import ConfigParser as configparser
+import configparser
 
 # Globals: The HTML log file, and the connection to the U-Boot console.
 log = None
@@ -169,7 +166,7 @@  def pytest_configure(config):
 
         with open(dot_config, 'rt') as f:
             ini_str = '[root]\n' + f.read()
-            ini_sio = StringIO.StringIO(ini_str)
+            ini_sio = io.StringIO(ini_str)
             parser = configparser.RawConfigParser()
             parser.readfp(ini_sio)
             ubconfig.buildconfig.update(parser.items('root'))
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 637a3bd257ba..de0aacc659b8 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -5,8 +5,8 @@ 
 # Generate an HTML-formatted log file containing multiple streams of data,
 # each represented in a well-delineated/-structured fashion.
 
-import cgi
 import datetime
+import html
 import os.path
 import shutil
 import subprocess
@@ -334,7 +334,7 @@  $(document).ready(function () {
         data = data.replace(chr(13), '')
         data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or
                        c for c in data)
-        data = cgi.escape(data)
+        data = html.escape(data)
         return data
 
     def _terminate_stream(self):
diff --git a/test/py/test.py b/test/py/test.py
index a5140945d4b9..0ce1838833f6 100755
--- a/test/py/test.py
+++ b/test/py/test.py
@@ -1,4 +1,4 @@ 
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
 # Copyright (c) 2015 Stephen Warren
@@ -7,8 +7,6 @@ 
 # Wrapper script to invoke pytest with the directory name that contains the
 # U-Boot tests.
 
-from __future__ import print_function
-
 import os
 import os.path
 import sys
diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
index e3210ed43fa4..4922b9dcc664 100755
--- a/test/py/tests/test_fit.py
+++ b/test/py/tests/test_fit.py
@@ -3,8 +3,6 @@ 
 #
 # Sanity check of the FIT handling in U-Boot
 
-from __future__ import print_function
-
 import os
 import pytest
 import struct
diff --git a/test/py/tests/test_fpga.py b/test/py/tests/test_fpga.py
index e3bb7b41c749..ca7ef8ea40d6 100644
--- a/test/py/tests/test_fpga.py
+++ b/test/py/tests/test_fpga.py
@@ -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')
 
     for cmd in ['dump', 'load', 'loadb']:
-	# missing dev parameter
-	expected = 'fpga: incorrect parameters passed'
-	output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
-	#assert expected in output
-	assert expected_usage in output
-
-	# more parameters - 0 at the end
-	expected = 'fpga: more parameters passed'
-	output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
-	#assert expected in output
-	assert expected_usage in output
-
-	# 0 address
-	expected = 'fpga: zero fpga_data address'
-	output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
-	#assert expected in output
-	assert expected_usage in output
-
-	# 0 filesize
-	expected = 'fpga: zero size'
-	output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
-	#assert expected in output
-	assert expected_usage in output
+        # missing dev parameter
+        expected = 'fpga: incorrect parameters passed'
+        output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
+        #assert expected in output
+        assert expected_usage in output
+
+        # more parameters - 0 at the end
+        expected = 'fpga: more parameters passed'
+        output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
+        #assert expected in output
+        assert expected_usage in output
+
+        # 0 address
+        expected = 'fpga: zero fpga_data address'
+        output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
+        #assert expected in output
+        assert expected_usage in output
+
+        # 0 filesize
+        expected = 'fpga: zero size'
+        output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
+        #assert expected in output
+        assert expected_usage in output
 
 @pytest.mark.buildconfigspec('cmd_fpga')
 @pytest.mark.buildconfigspec('cmd_echo')
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index 9324657d2160..354d17672fe4 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -508,8 +508,8 @@  def fs_obj_unlink(request, u_boot_config):
 
         # Test Case 2
         check_call('mkdir %s/dir2' % mount_dir, shell=True)
-	for i in range(0, 20):
-	    check_call('mkdir %s/dir2/0123456789abcdef%02x'
+        for i in range(0, 20):
+            check_call('mkdir %s/dir2/0123456789abcdef%02x'
                                     % (mount_dir, i), shell=True)
 
         # Test Case 4
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index cb183444c6fc..75325fad61ad 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -27,9 +27,9 @@  def test_log(u_boot_console):
         """
         for i in range(max_level):
             if mask & 1:
-                assert 'log_run() log %d' % i == lines.next()
+                assert 'log_run() log %d' % i == next(lines)
             if mask & 3:
-                assert 'func() _log %d' % i == lines.next()
+                assert 'func() _log %d' % i == next(lines)
 
     def run_test(testnum):
         """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)
         split = output.replace('\r', '').splitlines()
         lines = iter(split)
-        assert 'test %d' % testnum == lines.next()
+        assert 'test %d' % testnum == next(lines)
         return lines
 
     def test0():
@@ -88,7 +88,7 @@  def test_log(u_boot_console):
     def test10():
         lines = run_test(10)
         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
     cons = u_boot_console
diff --git a/test/py/tests/test_mmc_wr.py b/test/py/tests/test_mmc_wr.py
index 8b18781eac74..2ce79f58e3b1 100644
--- a/test/py/tests/test_mmc_wr.py
+++ b/test/py/tests/test_mmc_wr.py
@@ -65,41 +65,39 @@  def test_mmc_wr(u_boot_console, env__mmc_wr_config):
 
 
     for i in range(test_iterations):
-	# Generate random data
-	cmd = 'random %s %x' % (src_addr, count_bytes)
-	response = u_boot_console.run_command(cmd)
-	good_response = '%d bytes filled with random data' % (count_bytes)
-	assert good_response in response
-
-	# Select MMC device
-	cmd = 'mmc dev %d' % devid
-	if is_emmc:
-		cmd += ' %d' % partid
-	response = u_boot_console.run_command(cmd)
-	assert 'no card present' not in response
-	if is_emmc:
-		partid_response = "(part %d)" % partid
-	else:
-		partid_response = ""
-	good_response = 'mmc%d%s is current device' % (devid, partid_response)
-	assert good_response in response
-
-	# Write data
-	cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
-	response = u_boot_console.run_command(cmd)
-	good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (
-		devid, sector, count_sectors, count_sectors)
-	assert good_response in response
-
-	# Read data
-	cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
-	response = u_boot_console.run_command(cmd)
-	good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
-		devid, sector, count_sectors, count_sectors)
-	assert good_response in response
-
-	# Compare src and dst data
-	cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
-	response = u_boot_console.run_command(cmd)
-	good_response = 'Total of %d byte(s) were the same' % (count_bytes)
-	assert good_response in response
+        # Generate random data
+        cmd = 'random %s %x' % (src_addr, count_bytes)
+        response = u_boot_console.run_command(cmd)
+        good_response = '%d bytes filled with random data' % (count_bytes)
+        assert good_response in response
+
+        # Select MMC device
+        cmd = 'mmc dev %d' % devid
+        if is_emmc:
+            cmd += ' %d' % partid
+        response = u_boot_console.run_command(cmd)
+        assert 'no card present' not in response
+        if is_emmc:
+            partid_response = "(part %d)" % partid
+        else:
+            partid_response = ""
+        good_response = 'mmc%d%s is current device' % (devid, partid_response)
+        assert good_response in response
+
+        # Write data
+        cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
+        response = u_boot_console.run_command(cmd)
+        good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
+        assert good_response in response
+
+        # Read data
+        cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
+        response = u_boot_console.run_command(cmd)
+        good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
+        assert good_response in response
+
+        # Compare src and dst data
+        cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
+        response = u_boot_console.run_command(cmd)
+        good_response = 'Total of %d byte(s) were the same' % (count_bytes)
+        assert good_response in response