diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py index 43045d0173..6392aa679b 100644 --- a/support/testing/infra/__init__.py +++ b/support/testing/infra/__init__.py @@ -3,7 +3,8 @@ import re import sys import tempfile import subprocess -from urllib2 import urlopen, HTTPError, URLError +from urllib.request import urlopen +from urllib.error import HTTPError, URLError ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/" BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), "../../..")) @@ -44,7 +45,7 @@ def download(dldir, filename): try: url_fh = urlopen(os.path.join(ARTIFACTS_URL, filename)) - with open(tmpfile, "w+") as tmpfile_fh: + with open(tmpfile, "w+b") as tmpfile_fh: tmpfile_fh.write(url_fh.read()) except (HTTPError, URLError) as err: os.unlink(tmpfile) @@ -60,7 +61,8 @@ def run_cmd_on_host(builddir, cmd): out = subprocess.check_output(cmd, stderr=open(os.devnull, "w"), cwd=builddir, - env={"LANG": "C"}) + env={"LANG": "C"}, + universal_newlines=True) return out diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index 093a643a8b..5611ec96e8 100644 --- a/support/testing/infra/emulator.py +++ b/support/testing/infra/emulator.py @@ -76,6 +76,7 @@ class Emulator(object): self.logfile.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) self.qemu = pexpect.spawn(qemu_cmd[0], qemu_cmd[1:], timeout=5 * self.timeout_multiplier, + encoding='utf-8', env={"QEMU_AUDIO_DRV": "none"}) # We want only stdout into the log to avoid double echo self.qemu.logfile_read = self.logfile diff --git a/support/testing/run-tests b/support/testing/run-tests index 813b927045..74741aee1b 100755 --- a/support/testing/run-tests +++ b/support/testing/run-tests @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import argparse import sys import os diff --git a/support/testing/tests/core/test_post_scripts.py b/support/testing/tests/core/test_post_scripts.py index 40a36b7904..bc61f4af58 100644 --- a/support/testing/tests/core/test_post_scripts.py +++ b/support/testing/tests/core/test_post_scripts.py @@ -20,7 +20,7 @@ class TestPostScripts(infra.basetest.BRTest): def check_post_log_file(self, f, what, target_dir): lines = {} - with open(os.path.join(self.builddir, "build", f), 'rb') as csvfile: + with open(os.path.join(self.builddir, "build", f), newline='') as csvfile: r = csv.reader(csvfile, delimiter=',') for row in r: lines[row[0]] = row[1] diff --git a/support/testing/tests/download/gitremote.py b/support/testing/tests/download/gitremote.py index 3b35456dd1..7df252d031 100644 --- a/support/testing/tests/download/gitremote.py +++ b/support/testing/tests/download/gitremote.py @@ -32,7 +32,8 @@ class GitRemote(object): for port in range(GIT_REMOTE_PORT_INITIAL, GIT_REMOTE_PORT_LAST + 1): cmd = daemon_cmd + ["--port={port}".format(port=port)] self.logfile.write("> starting git remote with '{}'\n".format(" ".join(cmd))) - self.daemon = pexpect.spawn(cmd[0], cmd[1:], logfile=self.logfile) + self.daemon = pexpect.spawn(cmd[0], cmd[1:], logfile=self.logfile, + encoding='utf-8') ret = self.daemon.expect(["Ready to rumble", "Address already in use"]) if ret == 0: diff --git a/support/testing/tests/download/test_git.py b/support/testing/tests/download/test_git.py index 2455557298..ec5b8f3fdd 100644 --- a/support/testing/tests/download/test_git.py +++ b/support/testing/tests/download/test_git.py @@ -1,7 +1,7 @@ import os import shutil -from gitremote import GitRemote +from tests.download.gitremote import GitRemote import infra diff --git a/support/testing/tests/utils/test_check_package.py b/support/testing/tests/utils/test_check_package.py index 17c2fcf3bc..c70ba02324 100644 --- a/support/testing/tests/utils/test_check_package.py +++ b/support/testing/tests/utils/test_check_package.py @@ -16,7 +16,8 @@ import infra def call_script(args, env, cwd): """Call a script and return stdout and stderr as lists.""" out, err = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, env=env).communicate() + stderr=subprocess.PIPE, env=env, + universal_newlines=True).communicate() return out.splitlines(), err.splitlines()