From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 1/6] tests/functional: Fix problems in asset.py reported by pylint
Date: Wed, 15 Oct 2025 11:54:49 +0200 [thread overview]
Message-ID: <20251015095454.1575318-2-thuth@redhat.com> (raw)
In-Reply-To: <20251015095454.1575318-1-thuth@redhat.com>
From: Thomas Huth <thuth@redhat.com>
The "raise" without an Exception was a real problem, the other
spots are rather cosmetics.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/functional/qemu_test/asset.py | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py
index f666125bfaf..ba3771027b4 100644
--- a/tests/functional/qemu_test/asset.py
+++ b/tests/functional/qemu_test/asset.py
@@ -111,7 +111,7 @@ def _wait_for_other_download(self, tmp_cache_file):
return False
self.log.debug("Time out while waiting for %s!", tmp_cache_file)
- raise
+ raise TimeoutError(f"Time out while waiting for {tmp_cache_file}")
def fetch(self):
if not self.cache_dir.exists():
@@ -129,7 +129,7 @@ def fetch(self):
self.log.info("Downloading %s to %s...", self.url, self.cache_file)
tmp_cache_file = self.cache_file.with_suffix(".download")
- for retries in range(3):
+ for _ in range(3):
try:
with tmp_cache_file.open("xb") as dst:
with urllib.request.urlopen(self.url) as resp:
@@ -169,7 +169,7 @@ def fetch(self):
# server or networking problem
if e.code == 404:
raise AssetError(self, "Unable to download: "
- "HTTP error %d" % e.code)
+ "HTTP error %d" % e.code) from e
continue
except URLError as e:
# This is typically a network/service level error
@@ -178,7 +178,7 @@ def fetch(self):
self.log.error("Unable to download %s: URL error %s",
self.url, e.reason)
raise AssetError(self, "Unable to download: URL error %s" %
- e.reason, transient=True)
+ e.reason, transient=True) from e
except ConnectionError as e:
# A socket connection failure, such as dropped conn
# or refused conn
@@ -189,7 +189,7 @@ def fetch(self):
except Exception as e:
tmp_cache_file.unlink()
raise AssetError(self, "Unable to download: %s" % e,
- transient=True)
+ transient=True) from e
if not os.path.exists(tmp_cache_file):
raise AssetError(self, "Download retries exceeded", transient=True)
@@ -202,7 +202,6 @@ def fetch(self):
self.hash.encode('utf8'))
except Exception as e:
self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)
- pass
if not self._check(tmp_cache_file):
tmp_cache_file.unlink()
@@ -211,9 +210,10 @@ def fetch(self):
# Remove write perms to stop tests accidentally modifying them
os.chmod(self.cache_file, stat.S_IRUSR | stat.S_IRGRP)
- self.log.info("Cached %s at %s" % (self.url, self.cache_file))
+ self.log.info("Cached %s at %s", self.url, self.cache_file)
return str(self.cache_file)
+ @staticmethod
def precache_test(test):
log = logging.getLogger('qemu-test')
log.setLevel(logging.DEBUG)
@@ -224,16 +224,17 @@ def precache_test(test):
handler.setFormatter(formatter)
log.addHandler(handler)
for name, asset in vars(test.__class__).items():
- if name.startswith("ASSET_") and type(asset) == Asset:
+ if name.startswith("ASSET_") and isinstance(asset, Asset):
try:
asset.fetch()
except AssetError as e:
if not e.transient:
raise
- log.error("%s: skipping asset precache" % e)
+ log.error("%s: skipping asset precache", e)
log.removeHandler(handler)
+ @staticmethod
def precache_suite(suite):
for test in suite:
if isinstance(test, unittest.TestSuite):
@@ -241,9 +242,10 @@ def precache_suite(suite):
elif isinstance(test, unittest.TestCase):
Asset.precache_test(test)
- def precache_suites(path, cacheTstamp):
+ @staticmethod
+ def precache_suites(path, cache_tstamp):
loader = unittest.loader.defaultTestLoader
tests = loader.loadTestsFromNames([path], None)
- with open(cacheTstamp, "w") as fh:
+ with open(cache_tstamp, "w", encoding='utf-8'):
Asset.precache_suite(tests)
--
2.51.0
next prev parent reply other threads:[~2025-10-15 9:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 9:54 [PATCH 0/6] tests/functional: Fix various problems reported by pylint Thomas Huth
2025-10-15 9:54 ` Thomas Huth [this message]
2025-10-15 9:54 ` [PATCH 2/6] tests/functional: Fix problems in decorators.py " Thomas Huth
2025-10-22 19:15 ` Philippe Mathieu-Daudé
2025-10-15 9:54 ` [PATCH 3/6] tests/functional: Fix problems in linuxkerenl.py " Thomas Huth
2025-10-22 19:14 ` Philippe Mathieu-Daudé
2025-10-23 6:46 ` Thomas Huth
2025-10-23 15:13 ` John Snow
2025-10-15 9:54 ` [PATCH 4/6] tests/functional: Fix problems in testcase.py " Thomas Huth
2025-10-22 19:10 ` Philippe Mathieu-Daudé
2025-10-23 4:57 ` Thomas Huth
2025-10-15 9:54 ` [PATCH 5/6] tests/functional: Fix problems in uncompress.py " Thomas Huth
2025-10-22 19:07 ` Philippe Mathieu-Daudé
2025-10-15 9:54 ` [PATCH 6/6] tests/functional: Fix problems in utils.py " Thomas Huth
2025-10-22 19:07 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251015095454.1575318-2-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).