diff mbox series

[3/4] support/testing: fix python syntax

Message ID 141e1e33fdf6b4601677642ab64e7d76969ca96a.1527977964.git.yann.morin.1998@free.fr
State Changes Requested
Headers show
Series [1/4] support/docker: run apt-get update and apt-get install in two RUNs | expand

Commit Message

Yann E. MORIN June 2, 2018, 10:19 p.m. UTC
We're about to switch to using the flake8 from the distro, and that one
uncovers two more issues that the previously used pip-provided one did
not catch:

  - 'print' is now a function,
  - exceptions need to be caught-assigned with the 'as' keyword,

Additionally, old-style "%s"%() formatting is deprecated.

Fix those three issues.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
---
 support/testing/infra/__init__.py | 6 +++---
 support/testing/infra/basetest.py | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Ricardo Martincoski June 3, 2018, 4:24 a.m. UTC | #1
Hello,

On Sat, Jun 02, 2018 at 07:19 PM, Yann E. MORIN wrote:

> We're about to switch to using the flake8 from the distro, and that one
> uncovers two more issues that the previously used pip-provided one did
> not catch:

See my comments to patch 4. What generates more warnings is the fact that we
start using Python3 interpreter to call flake8.

We can call this patch a step towards Python 3 support for the test infra.

[snip]
> ---
>  support/testing/infra/__init__.py | 6 +++---
>  support/testing/infra/basetest.py | 4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)

By running one of below commands (after the others from .gitlab-ci.yml) I get:
$ python3 -m flake8 --statistics --count $(cat files.processed)
$ flake8 --statistics --count $(cat files.processed)

support/testing/infra/basetest.py:49:28: E999 SyntaxError: invalid syntax
support/testing/infra/__init__.py:37:29: E999 SyntaxError: invalid syntax
support/testing/run-tests:44:29: E999 SyntaxError: invalid syntax
3     E999 SyntaxError: invalid syntax
3

So it seems support/testing/run-tests also needs to be changed.


Regards,
Ricardo
Yann E. MORIN June 3, 2018, 7:11 a.m. UTC | #2
Ricardo, All,

On 2018-06-03 01:24 -0300, Ricardo Martincoski spake thusly:
> On Sat, Jun 02, 2018 at 07:19 PM, Yann E. MORIN wrote:
> > We're about to switch to using the flake8 from the distro, and that one
> > uncovers two more issues that the previously used pip-provided one did
> > not catch:
> 
> See my comments to patch 4. What generates more warnings is the fact that we
> start using Python3 interpreter to call flake8.

Oh, so the interpreter for flake8 has an impact onhow it interprets the
code it scans. Weird...

> We can call this patch a step towards Python 3 support for the test infra.

Yeah, I like this idea! ;-]

> [snip]
> > ---
> >  support/testing/infra/__init__.py | 6 +++---
> >  support/testing/infra/basetest.py | 4 ++--
> >  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> By running one of below commands (after the others from .gitlab-ci.yml) I get:
> $ python3 -m flake8 --statistics --count $(cat files.processed)
> $ flake8 --statistics --count $(cat files.processed)
> 
> support/testing/infra/basetest.py:49:28: E999 SyntaxError: invalid syntax
> support/testing/infra/__init__.py:37:29: E999 SyntaxError: invalid syntax
> support/testing/run-tests:44:29: E999 SyntaxError: invalid syntax

Weird, I didn't have that last one here in the docker image... But
indeed, another case of print-is-a-function-now

> 3     E999 SyntaxError: invalid syntax
> 3
> 
> So it seems support/testing/run-tests also needs to be changed.

I'll do so when I respin the series. Thanks for the reviews! :-)

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py
index b03e891771..a9352a652b 100644
--- a/support/testing/infra/__init__.py
+++ b/support/testing/infra/__init__.py
@@ -34,17 +34,17 @@  def download(dldir, filename):
         os.makedirs(dldir)
 
     tmpfile = tempfile.mktemp(dir=dldir)
-    print "Downloading to {}".format(tmpfile)
+    print("Downloading to {}".format(tmpfile))
 
     try:
         url_fh = urlopen(os.path.join(ARTIFACTS_URL, filename))
         with open(tmpfile, "w+") as tmpfile_fh:
             tmpfile_fh.write(url_fh.read())
-    except (HTTPError, URLError), err:
+    except (HTTPError, URLError) as err:
         os.unlink(tmpfile)
         raise err
 
-    print "Renaming from %s to %s" % (tmpfile, finalpath)
+    print("Renaming from {0} to {1}".format(tmpfile, finalpath))
     os.rename(tmpfile, finalpath)
     return finalpath
 
diff --git a/support/testing/infra/basetest.py b/support/testing/infra/basetest.py
index f3f13ad97f..5014fefafa 100644
--- a/support/testing/infra/basetest.py
+++ b/support/testing/infra/basetest.py
@@ -46,8 +46,8 @@  class BRTest(unittest.TestCase):
         self.config += "\nBR2_JLEVEL={}\n".format(self.jlevel)
 
     def show_msg(self, msg):
-        print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
-                                    self.testname, msg)
+        print("{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
+                                    self.testname, msg))
 
     def setUp(self):
         self.show_msg("Starting")