support/testing: fix python syntax

Fix three issues with code style in our test infra:
  - 'print' is now a function,
  - exceptions need to be caught-assigned with the 'as' keyword,
  - old-style "%s"%() formatting is deprecated.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
[Thomas: drop indices in format strings.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Yann E. MORIN 2018-06-03 11:08:21 +02:00 committed by Thomas Petazzoni
parent a1f4421cc7
commit 99723554c0
3 changed files with 18 additions and 18 deletions

View File

@ -34,17 +34,17 @@ def download(dldir, filename):
os.makedirs(dldir) os.makedirs(dldir)
tmpfile = tempfile.mktemp(dir=dldir) tmpfile = tempfile.mktemp(dir=dldir)
print "Downloading to {}".format(tmpfile) print("Downloading to {}".format(tmpfile))
try: try:
url_fh = urlopen(os.path.join(ARTIFACTS_URL, filename)) url_fh = urlopen(os.path.join(ARTIFACTS_URL, filename))
with open(tmpfile, "w+") as tmpfile_fh: with open(tmpfile, "w+") as tmpfile_fh:
tmpfile_fh.write(url_fh.read()) tmpfile_fh.write(url_fh.read())
except (HTTPError, URLError), err: except (HTTPError, URLError) as err:
os.unlink(tmpfile) os.unlink(tmpfile)
raise err raise err
print "Renaming from %s to %s" % (tmpfile, finalpath) print("Renaming from {} to {}".format(tmpfile, finalpath))
os.rename(tmpfile, finalpath) os.rename(tmpfile, finalpath)
return finalpath return finalpath

View File

@ -46,8 +46,8 @@ class BRTest(unittest.TestCase):
self.config += "\nBR2_JLEVEL={}\n".format(self.jlevel) self.config += "\nBR2_JLEVEL={}\n".format(self.jlevel)
def show_msg(self, msg): def show_msg(self, msg):
print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"), print("{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
self.testname, msg) self.testname, msg))
def setUp(self): def setUp(self):
self.show_msg("Starting") self.show_msg("Starting")

View File

@ -41,7 +41,7 @@ def main():
BRTest.logtofile = False BRTest.logtofile = False
if args.list: if args.list:
print "List of tests" print("List of tests")
nose2.discover(argv=[script_path, nose2.discover(argv=[script_path,
"-s", test_dir, "-s", test_dir,
"-v", "-v",
@ -52,16 +52,16 @@ def main():
if args.download is None: if args.download is None:
args.download = os.getenv("BR2_DL_DIR") args.download = os.getenv("BR2_DL_DIR")
if args.download is None: if args.download is None:
print "Missing download directory, please use -d/--download" print("Missing download directory, please use -d/--download")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
BRTest.downloaddir = os.path.abspath(args.download) BRTest.downloaddir = os.path.abspath(args.download)
if args.output is None: if args.output is None:
print "Missing output directory, please use -o/--output" print("Missing output directory, please use -o/--output")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
@ -71,8 +71,8 @@ def main():
BRTest.outputdir = os.path.abspath(args.output) BRTest.outputdir = os.path.abspath(args.output)
if args.all is False and len(args.testname) == 0: if args.all is False and len(args.testname) == 0:
print "No test selected" print("No test selected")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
@ -80,8 +80,8 @@ def main():
if args.testcases != 1: if args.testcases != 1:
if args.testcases < 1: if args.testcases < 1:
print "Invalid number of testcases to run simultaneously" print("Invalid number of testcases to run simultaneously")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
# same default BR2_JLEVEL as package/Makefile.in # same default BR2_JLEVEL as package/Makefile.in
@ -93,16 +93,16 @@ def main():
if args.jlevel: if args.jlevel:
if args.jlevel < 0: if args.jlevel < 0:
print "Invalid BR2_JLEVEL to use for each testcase" print("Invalid BR2_JLEVEL to use for each testcase")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
# the user can override the auto calculated value # the user can override the auto calculated value
BRTest.jlevel = args.jlevel BRTest.jlevel = args.jlevel
if args.timeout_multiplier < 1: if args.timeout_multiplier < 1:
print "Invalid multiplier for timeout values" print("Invalid multiplier for timeout values")
print "" print("")
parser.print_help() parser.print_help()
return 1 return 1
BRTest.timeout_multiplier = args.timeout_multiplier BRTest.timeout_multiplier = args.timeout_multiplier